Reproduced Exploit
Entangle: withdrawLP(uint256.max) casts to -1 and pays the whole pool
withdrawLP casts the amount with int128(int256(amount)). uint256.max, the value in the published PoC, becomes -1. A negative amount pays totalLp to the caller, so the chef balance goes to 0. The caller deposited 1 ether and a second depositor deposited 1,000 ether. The caller receives both. SafeCas…
Loss
1,000 ether of another depositor's LP
Chain
Ethereum
Category
untagged
Date
Undated
Source
AuditVault
EVM Playground
Source-level debugger — step opcodes and Solidity in sync
The attack replays in your browser. Step through it by Solidity line or by opcode.
The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.
Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 51368-unsafe-casting-leads-to-overflowunderflow-halborn-entangle-l. Standalone Foundry PoC and full write-up: 51368-unsafe-casting-leads-to-overflowunderflow-halborn-entangle-l_exp in the
evm-hack-registrymirror.
Vulnerability classes: vuln/arithmetic
Reproduction: a self-contained Foundry PoC that compiles and runs offline with only
forge-std- no fork and no RPC. PoC: test/51368-unsafe-casting-leads-to-overflowunderflow-halborn-entangle-l_exp.sol.
Key info#
| Field | Value |
|---|---|
| Loss | 1,000 ether of another depositor's LP |
| Protocol | Entangle Trillion MasterChef |
| Bug class | Unsafe uint256 to int128 cast |
| Source | AuditVault finding |
| Report | Halborn, Entangle Trillion |
| Chain / block / date | Ethereum model · block 0 · 1970-01 |
| Compiler | solc 0.8.27, cancun, via IR |
TL;DR#
withdrawLP casts the amount with int128(int256(amount)). uint256.max, the value in the published PoC, becomes -1. A negative amount pays totalLp to the caller, so the chef balance goes to 0. The caller deposited 1 ether and a second depositor deposited 1,000 ether. The caller receives both. SafeCast reverts on the same input and the 1,000 ether stays.
The vulnerable code#
// @> VULN: uint256.max truncates through int256 to int128(-1)
int256 casted = int256(int128(int256(amount)));
uint256 pay = casted < 0 ? poolBefore : uint256(casted);
Root cause#
reinvest and withdraw convert uint256 amounts to int128 with no range check. uint256.max does not fit in int128. The conversion wraps to -1. The withdraw path treats that negative value as 'pay the pool', which is why the published test sees the chef LP balance fall to 0.
Preconditions#
withdrawLPis callable by a depositor. No admin role is required.- Attacker has deposited 1 ether of LP. Another account has deposited 1,000 ether.
- The amount argument is
type(uint256).max, the literal in the Halborn PoC.
Attack walkthrough#
- Snapshot totalLp at 1,001 ether.
- Cast uint256.max to int128. The result is -1.
- Because the cast is negative, set the payout to the full pool.
- Set totalLp to 0.
- Transfer 1,001 ether to the caller. 1,000 ether of it is not their deposit.
Diagrams#
Impact#
The other depositor's 1,000 ether of LP is transferred to the caller. Their deposit record is still 1,000 ether and the chef balance is 0, so the tokens are gone. The SafeCast control reverts and that 1,000 ether remains in the chef.
Remediation#
Use OpenZeppelin SafeCast (the note's fix) so a value above int128 max reverts before the payout is computed. Cap the payout at deposits[msg.sender].
How to reproduce#
cd 51368-unsafe-casting-leads-to-overflowunderflow-halborn-entangle-l_exp
forge test -vv
run() is the harm path. The control test uses the corrected comparison or guard and does not produce the loss number.
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 51368-unsafe-casting-leads-to-overflowunderflow-halborn-entangle-l_exp (evm-hack-registry mirror).
- AuditVault finding: 51368-unsafe-casting-leads-to-overflowunderflow-halborn-entangle-l.
Alerts & third-party analyses
These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.