Reproduced Exploit
Cryptex: liquidationReward pays a 6-decimal collateral as if it had 18 decimals
liquidationReward computes burnAmount tcapPrice (1e18 + penalty) / collateralPrice / 1e18 and never scales by the collateral's decimals. Burning 1 TCAP priced at $1 against $1 USDC returns 1e18 raw units instead of 1e6. The vault, seeded with that buggy amount, pays all of it to the liquidator.
Loss
Liquidator receives 1e18 raw USDC units for 1 TCAP. The fair 6-decimal amount is 1e6. The vault is emptied
Chain
Ethereum
Category
arithmetic
Date
Sep 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: 40209-calculating-liquidationreward-without-considering-collateral. Standalone Foundry PoC and full write-up: 40209-calculating-liquidationreward-without-considering-collateral_exp in the
evm-hack-registrymirror.
Vulnerability classes:
vuln/arithmetic/decimal-mismatch
Key info#
| Field | Value |
|---|---|
| Loss | Liquidator receives 1e18 raw USDC units for 1 TCAP. The fair 6-decimal amount is 1e6. The vault is emptied |
| Vulnerable contract | LiquidationLib.liquidationReward |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2024-09 |
| Compiler | solc 0.8.27, cancun |
| Bug class | reward formula omits collateral decimals |
TL;DR#
liquidationReward computes burnAmount * tcapPrice * (1e18 + penalty) / collateralPrice / 1e18 and never scales by the collateral's decimals. Burning 1 TCAP priced at $1 against $1 USDC returns 1e18 raw units instead of 1e6. The vault, seeded with that buggy amount, pays all of it to the liquidator.
The vulnerable code#
function liquidationReward(uint256 burnAmount, uint256 tcapPrice, uint256 collateralPrice, uint64 liquidationPenalty) public pure returns (uint256) {
return burnAmount * tcapPrice * (1e18 + liquidationPenalty) / collateralPrice / 1e18; // @> VULN: ignores collateral decimals
}
The Cantina fix multiplies by 10 ** collateralDecimals and divides by 10 ** 18:
- return burnAmount * tcapPrice * (1e18 + liquidationPenalty) / collateralPrice / 1e18;
+ return burnAmount * tcapPrice * (1e18 + liquidationPenalty) * 10 ** collateralDecimals / collateralPrice / 1e18 / 10 ** 18;
Root cause#
TCAP amounts and both prices are 18-decimal wads. Dividing only by collateralPrice and 1e18 leaves an 18-decimal token amount. USDC has 6 decimals, so the same number is 1e12 times too many units. The control with collateralDecimals = 6 returns 1e6.
Preconditions#
- Collateral is USDC, 6 decimals, price
1e18per token. - The liquidator burns
1e18TCAP units attcapPrice = 1e18with a zero penalty. - The vault holds
1e18raw USDC units, which is exactly the buggy reward.
Attack walkthrough#
CollateralVault.liquidateasksLiquidationLibfor the reward.- The return expression yields
1e18. - The vault transfers that balance to the liquidator.
- The fair amount, scaled by
10 ** 6 / 10 ** 18, is1e6. - The vault balance is 0.
Diagrams#
Impact#
The liquidator is paid 1e18 raw USDC units, which is 1e12 whole tokens, for one dollar of TCAP. Every other depositor in that collateral vault funds the difference. With a 6-decimal collateral the overpayment is 10 ** (18 - decimals).
How to reproduce#
cd 40209-calculating-liquidationreward-without-considering-collateral_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/40209-calculating-liquidationreward-without-considering-collateral.md
- Report: https://cdn.cantina.xyz/reports/cantina_cryptex_sep2024.pdf
- Provenance: Cantina Cryptex review, September 2024. Function quoted in the finding as LiquidationLib.sol lines 17-19. Fixed in Cryptex PR 9.
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 40209-calculating-liquidationreward-without-considering-collateral_exp (evm-hack-registry mirror).
- AuditVault finding: 40209-calculating-liquidationreward-without-considering-collateral.
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.