Reproduced Exploit

Nexus: DepositETH share price underflows and 30 WETH of rewards stay locked

_updateSharePrice computes the ETH balance as ethDeposited - ethWithdrawn + rewardsClaimed. Solidity evaluates that left to right. With 100 deposited, 150 withdrawn, and 80 of rewards just claimed, the true balance is 30, but 100 - 150 underflows and the call reverts. The 30 WETH that was delivered…

Nov 2024•Ethereum•arithmetic•4 min read

Loss

30 WETH stuck in DepositETH; share price never updates and withdraw reverts

Chain

Ethereum

Category

arithmetic

Date

Nov 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: 44985-h-05-arithmetic-underflow-in-total-balance-calculation-pasho. Standalone Foundry PoC and full write-up: 44985-h-05-arithmetic-underflow-in-total-balance-calculation-pasho_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/arithmetic/underflow · vuln/logic/price-calculation

Key info#

FieldValue
Loss30 WETH stuck in DepositETH; share price never updates and withdraw reverts
Vulnerable contractDepositETH._updateSharePrice
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-11
Compilersolc 0.8.27, cancun, via IR
Bug classethDeposited - ethWithdrawn + rewardsClaimed subtracts before it adds

TL;DR#

_updateSharePrice computes the ETH balance as ethDeposited - ethWithdrawn + rewardsClaimed. Solidity evaluates that left to right. With 100 deposited, 150 withdrawn, and 80 of rewards just claimed, the true balance is 30, but 100 - 150 underflows and the call reverts. The 30 WETH that was delivered as rewards stays in the contract. Withdraw calls the same update and reverts too. Reordering to ethDeposited + rewardsClaimed - ethWithdrawn yields 30 and writes the share price.

Background#

Pashov Audit Group, Nexus review dated 2024-11-29, finding H-05. Withdrawals tracked by the protocol include principal and earned rewards, so ethWithdrawn grows past ethDeposited in ordinary operation. DepositUSD._updateSharePrice has the same expression. The report's fix adds the rewards before subtracting the withdrawals, and divides by that total once.

The vulnerable code#

SOLIDITY
rewardsClaimed += _rewardsEarned;
uint256 totalEthBalance = (ethDeposited - ethWithdrawn + rewardsClaimed); // @> VULN
sharePrice = (nETHMinted) * BASE_POINT / (ethDeposited - ethWithdrawn + rewardsClaimed);
DIFF
- uint256 totalEthBalance = (ethDeposited - ethWithdrawn + rewardsClaimed);
+ uint256 totalEthBalance = ethDeposited + rewardsClaimed - ethWithdrawn;
- sharePrice = (nETHMinted) * BASE_POINT / (ethDeposited - ethWithdrawn + rewardsClaimed);
+ sharePrice = (nETHMinted * BASE_POINT) / totalEthBalance;

Root cause#

+ and - have the same precedence and associate left to right. The subtraction is not saved by the rewards that are added afterwards. On 0.8 the underflow reverts instead of wrapping, so every caller of the update, including withdraw, reverts. The contract can be solvent and still be unable to account or to pay out.

Preconditions#

  • ethDeposited is 100 ether, ethWithdrawn is 150 ether, and nETHMinted is 100 ether.
  • This update adds 80 ether of rewards. 100 + 80 - 150 is 30.
  • 30 WETH has been transferred in, which is the solvent balance the reverted update refuses to recognize.

Attack walkthrough#

  1. 30 WETH is transferred to DepositETH.
  2. poke(80 ether) calls _updateSharePrice.
  3. 100 - 150 reverts. sharePrice stays 0.
  4. The holder calls withdraw.
  5. Withdraw passes the shares check and calls the same update.
  6. The update reverts again. The holder receives 0. DepositETH still holds 30 WETH.

Diagrams#

flowchart TD A["30 WETH of rewards arrives"] --> B["Update adds 80 to rewardsClaimed"] B --> C["VULN 100 minus 150 underflows"] C --> D["Share price stays 0"] D --> E["Holder withdraw hits the same expression"] E --> F["30 WETH stays in DepositETH"] B --> G["Reordered sum is 30 and the share price is written"]

Impact#

Holders cannot withdraw. The 30 WETH that represents the solvent balance after rewards stays in DepositETH, and sharePrice is never stored. The reordered update records 80 ether of rewards and sets sharePrice to 100 ether * 1e18 / 30 ether.

Remediation#

Add rewardsClaimed to ethDeposited before subtracting ethWithdrawn, and use that total for the share-price division. Apply the same reorder in DepositUSD.

How to reproduce#

BASH
cd 44985-h-05-arithmetic-underflow-in-total-balance-calculation-pasho_exp
forge test -vv

test_exploit_share_price_underflow_locks_30 asserts the 30 WETH balance and a zero share price. test_control_reordered_sum_sets_share_price asserts the reordered total of 30 and the resulting price. Captured output is output.txt.

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.