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.

Feb 2024•Ethereum•logic•3 min read

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

evm-hack-analyzer

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.

Loading fork state…

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-registry mirror.


Vulnerability classes: vuln/logic/missing-allowance

Key info#

FieldValue
Loss1,000 USDC stays in the diamond. The new gToken allowance is 0 and pull reverts
Vulnerable contractTradingStorage.updateGToken
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-02
Compilersolc 0.8.27, cancun
Bug classgToken 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#

SOLIDITY
gTokens[index] = _gToken; // @> VULN: new gToken stored, collateral.approve is never called
DIFF
  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 1000e6 collateral.
  • addCollateral already approved the old gToken and the staking address.
  • Governance calls updateGToken with a non-zero new gToken.

Attack walkthrough#

  1. updateGToken passes the index and zero-address checks.
  2. gTokens[1] becomes the new gToken. No approve runs.
  3. The new gToken calls pull for 1000e6.
  4. transferFrom reverts on allowance.
  5. The diamond still holds 1000e6 and the new gToken holds 0.
  6. The control approves during updateGToken and the pull succeeds.

Diagrams#

flowchart TD A["addCollateral approves the original gToken"] --> B["updateGToken stores a new gToken"] B --> C["VULN no approve for the new address"] C --> D["pull calls transferFrom"] D --> E["Allowance is 0 and the call reverts"] E --> F["1000 USDC stays in the diamond"] B --> G["Control approves max for the new gToken"] G --> H["Control pull moves the 1000 USDC"]

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#

BASH
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#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

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.