Reproduced Exploit
Stargate — LPStaking.emergencyWithdraw pays user.amount before clearing it
Chain
Other
Category
reentrancy
Date
Dec 2021
Source
AuditVault
EVM Playground
Source-level debugger — step opcodes and Solidity in sync
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. No backend, no live RPC.
Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 56308-reentrancy-attack-in-emergencywithdraw-function-zokyo-none-s. Standalone Foundry PoC and full write-up: 56308-reentrancy-attack-in-emergencywithdraw-function-zokyo-none-s_exp in the
evm-hack-registrymirror.
Vulnerability classes: vuln/reentrancy/single-function · vuln/logic/incorrect-order-of-operations · vuln/logic/missing-check
Reproduction: Local Foundry reproduction of the pre-fix order. The LP token notifies the recipient. No fork. Trace: output.txt.
Root cause#
The December 2021 emergencyWithdraw transferred user.amount and only then wrote user.amount = 0 and user.rewardDebt = 0. The LP token notifies the recipient, so the attacker re-enters while user.amount is still the full stake and is paid again. The function also has no emergency-status check, so it is callable in the normal state.
uint256 userAmount = user.amount;
// @> VULN:
pool.lpToken.transfer(address(msg.sender), userAmount);
user.amount = 0;
user.rewardDebt = 0;
A victim has 1000 LP staked. The attacker stakes 100 LP, calls emergencyWithdraw, and the callback calls it again. The attacker receives 200 LP. The extra 100 LP comes out of the victim's stake. The staking contract is left holding 900 LP against the victim's recorded 1000.
Attack path#
PoC#
The fixed staking writes user.amount = 0 before the transfer. The same callback then transfers 0. The attacker is left with their own 100 LP and the victim's 1000 LP stays in the contract.
cd 56308-reentrancy-attack-in-emergencywithdraw-function-zokyo-none-s_exp
forge test -vv
Remediation#
Copy user.amount to a local, set user.amount and rewardDebt to 0, then transfer the local amount. Gate the function on an emergency flag if it should not be a normal exit.
References#
- AuditVault finding 56308
- Report: https://github.com/solodit/solodit_content/blob/main/reports/Zokyo/2021-12-31-Stargate.md
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 56308-reentrancy-attack-in-emergencywithdraw-function-zokyo-none-s_exp (evm-hack-registry mirror).
- AuditVault finding: 56308-reentrancy-attack-in-emergencywithdraw-function-zokyo-none-s.
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.