Reproduced Exploit
ConvexTradeExecutor.totalFunds ignores the WETH balance
totalFunds returns positionInWantToken, whose sum is staked LP value in ETH, idle LP value in ETH, and address(this).balance. The executor is also paid and stored in WETH. That balance is not in the sum. With 20e18 staked, 5e18 idle LP, 3 ETH, and 10 WETH, totalFunds returns 28e18. The position is…
Loss
totalFunds returns 28e18. The executor holds 38e18. The missing 10e18 is WETH
Chain
Ethereum
Category
logic
Date
May 2022
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: 13256-the-weth-tokens-are-not-taken-into-account-in-the-convextrad. Standalone Foundry PoC and full write-up: 13256-the-weth-tokens-are-not-taken-into-account-in-the-convextrad_exp in the
evm-hack-registrymirror.
Vulnerability classes: vuln/logic/omitted-balance · vuln/defi/valuation
Reproduction: self-contained synthetic Foundry reduction; see output.txt.
Key info#
| Field | Value |
|---|---|
| Loss | totalFunds returns 28e18. The executor holds 38e18. The missing 10e18 is WETH |
| Vulnerable contract | ConvexTradeExecutor.totalFunds |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() with 3 ETH |
| Chain / block / date | Ethereum model · block 0 · 2022-05 |
| Compiler | solc 0.8.27, cancun, via IR |
| Bug class | Position value adds native ETH and leaves out WETH.balanceOf |
TL;DR#
totalFunds returns positionInWantToken, whose sum is staked LP value in ETH, idle LP value in ETH, and address(this).balance. The executor is also paid and stored in WETH. That balance is not in the sum. With 20e18 staked, 5e18 idle LP, 3 ETH, and 10 WETH, totalFunds returns 28e18. The position is worth 38e18. The fixed function adds WETH.balanceOf(this) and returns 38e18.
Background#
ConsenSys Diligence reviewed Brahma Fi in May 2022. Every trade executor's totalFunds is supposed to report every asset the contract holds, because later accounting uses that figure. ConvexTradeExecutor.totalFunds delegates to ConvexPositionHandler.positionInWantToken. _getTotalBalancesInETH values staked and idle Curve LP in ETH and then sets ethBalance = address(this).balance. WETH is a token balance, so it is invisible. The contract receives WETH up front and holds WETH again before a withdrawal.
The vulnerable code#
ethOut = address(this).balance;
uint256 amount = stakedOut + lpOut + ethOut; // @> VULN: ETH is included. WETH is not.
The audited return is stakedLpBalanceInETH + lpTokenBalanceInETH + ethBalance in ConvexPositionHandler.positionInWantToken, and ethBalance = address(this).balance in _getTotalBalancesInETH.
Root cause#
Native ETH and WETH are the same asset in the position and different balances in the contract. The sum reads only the native balance. Ten WETH on the contract does not change totalFunds.
Preconditions#
- Staked LP has already been valued at 20e18 ETH.
- Idle LP has already been valued at 5e18 ETH.
- The executor holds 3 ETH and 10 WETH.
- Buggy total is 28e18. Fair total is 38e18.
Attack walkthrough#
runforwards 3 ETH into the executor. The 10 WETH is already there.totalFundsstores the staked leg, the idle LP leg, and the 3 ETH, then adds those three.- The return value is 28e18.
WETH.balanceOfis still 10e18. - The 10e18 gap is minted to the sink. The control adds the WETH balance and returns 38e18.
Diagrams#
Impact#
Any accounting that trusts totalFunds understates the Convex leg by the full WETH balance. Here that is 10e18 out of a 38e18 position. Share price, withdrawal value, and the split between the no-loss leg and the rest of the vault are short by that WETH. The tokens are still in the contract. They are just not in the number.
Remediation#
Add the WETH balance to the ETH-denominated sum:
- uint256 amount = stakedLpBalanceInETH + lpTokenBalanceInETH + address(this).balance;
+ uint256 amount = stakedLpBalanceInETH + lpTokenBalanceInETH
+ + address(this).balance + WETH.balanceOf(address(this));
How to reproduce#
cd 13256-the-weth-tokens-are-not-taken-into-account-in-the-convextrad_exp
forge test -vv
Sources#
- AuditVault finding: 13256-the-weth-tokens-are-not-taken-into-account-in-the-convextrad
- ConsenSys Diligence, Brahma Fi, May 2022: https://consensys.net/diligence/audits/2022/05/brahma-fi/
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 13256-the-weth-tokens-are-not-taken-into-account-in-the-convextrad_exp (evm-hack-registry mirror).
- AuditVault finding: 13256-the-weth-tokens-are-not-taken-into-account-in-the-convextrad.
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.