Reproduced Exploit
Gains Network: updateGToken never approves the new gToken
addCollateral approves the gToken for type(uint256).max. updateGToken writes the new address into gTokens[index] and does not approve it. The new gToken's transferFrom of the 1,000 USDC sitting in the diamond reverts. The collateral cannot move.
Loss
1,000 USDC stays in the diamond. The new gToken allowance is 0 and pull reverts
Chain
Ethereum
Category
logic
Date
Feb 2024
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: 37793-h-04-collateral-not-approved-after-updating-of-gtoken-addres. Standalone Foundry PoC and full write-up: 37793-h-04-collateral-not-approved-after-updating-of-gtoken-addres_exp in the
evm-hack-registrymirror.
Vulnerability classes:
vuln/logic/missing-allowance
Key info#
| Field | Value |
|---|---|
| Loss | 1,000 USDC stays in the diamond. The new gToken allowance is 0 and pull reverts |
| Vulnerable contract | TradingStorage.updateGToken |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2024-02 |
| Compiler | solc 0.8.27, cancun |
| Bug class | gToken pointer is replaced without collateral.approve |
TL;DR#
addCollateral approves the gToken for type(uint256).max. updateGToken writes the new address into gTokens[index] and does not approve it. The new gToken's transferFrom of the 1,000 USDC sitting in the diamond reverts. The collateral cannot move.
The vulnerable code#
gTokens[index] = _gToken; // @> VULN: new gToken stored, collateral.approve is never called
gTokens[index] = _gToken;
+ collateral.approve(_gToken, type(uint256).max);
Root cause#
The allowance is granted only in addCollateral, to the address passed at that moment. Replacing the stored gToken does not move or extend that allowance. The old gToken remains approved. The new one has allowance 0.
Preconditions#
- The diamond holds
1000e6collateral. addCollateralalready approved the old gToken and the staking address.- Governance calls
updateGTokenwith a non-zero new gToken.
Attack walkthrough#
updateGTokenpasses the index and zero-address checks.gTokens[1]becomes the new gToken. Noapproveruns.- The new gToken calls
pullfor1000e6. transferFromreverts on allowance.- The diamond still holds
1000e6and the new gToken holds 0. - The control approves during
updateGTokenand the pull succeeds.
Diagrams#
Impact#
After a gToken rotation, the new vault cannot pull collateral out of the diamond. The 1,000 USDC in this run stays put. Users who depend on the new gToken to move that collateral cannot withdraw or settle through it.
How to reproduce#
cd 37793-h-04-collateral-not-approved-after-updating-of-gtoken-addres_exp
forge test -vv
output.txt is the captured passing run. The control test checks the recommended fix.
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/37793-h-04-collateral-not-approved-after-updating-of-gtoken-addres.md
- Report: https://github.com/pashov/audits/blob/master/team/md/GainsNetwork-security-review-February.md
- Provenance: Pashov Gains Network February review, TradingStorageUtils.updateGToken. The blamed function is quoted in the finding.
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 37793-h-04-collateral-not-approved-after-updating-of-gtoken-addres_exp (evm-hack-registry mirror).
- AuditVault finding: 37793-h-04-collateral-not-approved-after-updating-of-gtoken-addres.
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.