Reproduced Exploit
DeGate: a fee-on-transfer deposit is credited in full
Anyone can register a token, and needCheckBalance stays false until the owner calls setCheckBalance. A 10 percent fee-on-transfer deposit is then credited for the full amount. Alice withdraws that credit. The exchange is left holding 800 against Bob's credit of 1000, so Bob's withdrawal reverts.
Loss
Bob is credited 1000 and can withdraw only 800. His full withdrawal reverts
Chain
Ethereum
Category
logic
Date
Nov 2022
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. 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: 17856-token-management-diculties-caused-by-the-addition-of-arbitra. Standalone Foundry PoC and full write-up: 17856-token-management-diculties-caused-by-the-addition-of-arbitra_exp in the
evm-hack-registrymirror.
Vulnerability classes:
vuln/logic/fee-calculation·vuln/access-control/missing-auth
Key info#
| Field | Value |
|---|---|
| Loss | Bob is credited 1000 and can withdraw only 800. His full withdrawal reverts |
| Vulnerable contract | DefaultDepositContract.deposit |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · local · 2022-11 |
| Compiler | solc 0.8.27, cancun |
| Bug class | needCheckBalance left false for a permissionlessly registered token |
TL;DR#
Anyone can register a token, and needCheckBalance stays false until the owner calls setCheckBalance. A 10 percent fee-on-transfer deposit is then credited for the full amount. Alice withdraws that credit. The exchange is left holding 800 against Bob's credit of 1000, so Bob's withdrawal reverts.
Background#
Trail of Bits' DeGate review, November 2022, by Shaun Mirani. The report covers ExchangeV3.registerToken, ExchangeDeposits.deposit, and DefaultDepositContract.deposit. The owner cannot reliably front-run every new token to enable the balance check.
The vulnerable code#
bool checkBalance = needCheckBalance[token];
uint256 balanceBefore = checkBalance ? FeeToken(token).balanceOf(address(this)) : 0;
FeeToken(token).transferFrom(from, address(this), uint256(amount));
uint256 balanceAfter = checkBalance ? FeeToken(token).balanceOf(address(this)) : amount; // @> VULN: credits `amount` when the fee token delivered less
- uint256 balanceAfter = checkBalance ? FeeToken(token).balanceOf(address(this)) : amount;
+ uint256 balanceAfter = FeeToken(token).balanceOf(address(this));
Root cause#
When the flag is false, balanceAfter is the requested amount and balanceBefore is 0, so the credit equals amount no matter what the token actually delivered.
Preconditions#
- The token takes a 10 percent fee on
transferFromand is not onneedCheckBalance. - Bob has already deposited 1000 and was credited 1000 while only 900 arrived.
- Alice deposits 1000 and then withdraws her credit.
Attack walkthrough#
- Bob's earlier deposit left the exchange with 900 tokens and a 1000 credit.
- Alice deposits 1000. The token burns 100 and delivers 900. She is credited 1000.
- Alice withdraws 1000. The exchange pays it and has 800 left.
- Bob's withdrawal of his 1000 credit reverts. Alice is back to the 1000 she started with.
Diagrams#
Impact#
Bob's 1000 credit cannot be paid. The exchange holds 800 of the fee token after Alice's withdrawal. With setCheckBalance enabled, the same deposit credits only the 900 that arrived.
Remediation#
Credit the measured balance delta for every token, or refuse tokens that have not been explicitly reviewed and flagged.
How to reproduce#
cd 17856-token-management-diculties-caused-by-the-addition-of-arbitra_exp
forge test -vv
test_exploit_overcredit_lets_alice_strand_bob asserts an 800 balance, Bob's 1000 credit, and a reverted withdrawal. test_control_check_balance_credits_only_what_arrived asserts a 900 credit. Captured output is output.txt.
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/17856-token-management-diculties-caused-by-the-addition-of-arbitra.md
- Trail of Bits report: https://github.com/trailofbits/publications/blob/master/reviews/DeGate.pdf
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 17856-token-management-diculties-caused-by-the-addition-of-arbitra_exp (evm-hack-registry mirror).
- AuditVault finding: 17856-token-management-diculties-caused-by-the-addition-of-arbitra.
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.