Reproduced Exploit

StakedCapAdapter prices a 10 ether vault at zero and the assets are taken for free

The vault has 1000 ether shares and 10 ether of assets, so one full share is worth 0.01 underlying. price passes decimals() (18) into convertToAssets and divides by 18. convertToAssets(18) rounds to 0, the adapter returns 0, and the buyer pays 0 for the shares and redeems all 10 ether. priceFixed u…

May 2025•Ethereum•arithmetic•3 min read

Loss

10 ether of underlying, bought at a reported price of 0

Chain

Ethereum

Category

arithmetic

Date

May 2025

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: 61540-wrong-captokendecimals-value-used-in-stakedcapadapterprice-c. Standalone Foundry PoC and full write-up: 61540-wrong-captokendecimals-value-used-in-stakedcapadapterprice-c_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/arithmetic/decimal-mismatch · vuln/logic/price-calculation

Key info#

FieldValue
Loss10 ether of underlying, bought at a reported price of 0
Vulnerable contractStakedCapAdapter.price
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2025-05
Compilersolc 0.8.27, cancun, via IR
Bug classDecimal count used as the share amount

TL;DR#

The vault has 1000 ether shares and 10 ether of assets, so one full share is worth 0.01 underlying. price passes decimals() (18) into convertToAssets and divides by 18. convertToAssets(18) rounds to 0, the adapter returns 0, and the buyer pays 0 for the shares and redeems all 10 ether. priceFixed uses 10 ** decimals and returns 1000000, which is the 8-decimal price of 0.01.

Background#

Trail of Bits' May 2025 review of CAP Labs' Covered Agent Protocol. The quoted StakedCapAdapter.price stores IERC20Metadata(capToken).decimals() and passes that integer to convertToAssets, then divides by it. Current cap-contracts uses 10 ** decimals in that slot. The two mistakes cancel on a perfectly linear sample and diverge when convertToAssets(18) rounds to 0, which is this vault.

The vulnerable code#

SOLIDITY
uint256 capTokenDecimals = ERC20Min(capToken).decimals(); // @> VULN: 18, not 10**18
// FIX: capTokenDecimals = 10 ** ERC20Min(capToken).decimals()
uint256 pricePerFullShare = StakedVault(asset_).convertToAssets(capTokenDecimals);
latestAnswer = latestAnswer * pricePerFullShare / capTokenDecimals;

The change that removes the harm:

DIFF
- uint256 capTokenDecimals = ERC20Min(capToken).decimals();
+ uint256 capTokenDecimals = 10 ** uint256(ERC20Min(capToken).decimals());

Root cause#

convertToAssets is shares * totalAssets / totalSupply. Eighteen wei of shares against 1000 ether of supply is zero assets. The following division by 18 cannot recover the ratio. Sampling 10 ** 18 shares returns 0.01 ether of assets per share.

Preconditions#

  • Underlying price from the oracle is 1e8.
  • The vault's own share balance is 1000 ether and it holds 10 ether of underlying.
  • The sale charges shares * price / 1e8.

Attack walkthrough#

  1. price loads decimals 18.
  2. convertToAssets(18) is 0 and the returned price is 0.
  3. priceFixed returns 1000000.
  4. buy at price 0 transfers 10 ether of underlying to the buyer and records a payment of 0.

Diagrams#

flowchart TD A["Vault has 1000 shares and 10 assets"] --> B["VULN convertToAssets is called with 18"] B --> C["Sample rounds to 0 and the price is 0"] C --> D["Buyer pays 0 and receives 10 ether of underlying"] B --> E["Control uses 10 to the 18 and the price is 1000000"]

Impact#

The buyer receives 10 ether of underlying without paying. A price of 1000000 would have charged for the 0.01 underlying per share.

Remediation#

Set capTokenDecimals to 10 ** decimals before both convertToAssets and the division, which is the formula in the current StakedCapAdapter.

How to reproduce#

BASH
cd 61540-wrong-captokendecimals-value-used-in-stakedcapadapterprice-c_exp
forge test -vv

test_exploit is the harm. The control test is the guarded path. 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.