Reproduced Exploit
Polynomial Protocol — division-by-zero in getTokenPrice bricks KangarooVault with funds locked
1. getTokenPrice returns totalFunds.divWadDown(totalSupply) when totalFunds != 0 and positionId == 0, with no guard for totalSupply == 0. 2. That state is reachable: after all positions close and every holder withdraws, a residual can remain (a delayed settlement / rounding leftover).
Chain
Other
Category
dos
Date
Mar 2023
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, Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. No backend, no live RPC.
Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w. Standalone Foundry PoC and full write-up: 20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w_exp in the
evm-hack-registrymirror.
Vulnerability classes: vuln/dos/frozen-funds · vuln/logic/division-by-zero · vuln/loss-of-funds/locked-funds
Reproduction: a self-contained Foundry PoC that compiles & runs in an isolated project with only
forge-std— no fork, no RPC, noanvil_state. Full trace: output.txt. PoC: test/20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w_exp.sol.
Key info#
| Impact | HIGH — getTokenPrice divides by a zero share supply, so once all holders exit while any residual remains, every deposit reverts forever and the residual is permanently locked (vault bricked) |
| Protocol | Polynomial Protocol — KangarooVault (Power-Perp vault) |
| Vulnerable code | KangarooVault.getTokenPrice — return totalFunds.divWadDown(totalSupply) with no totalSupply == 0 guard |
| Bug class | Unhandled division by zero → denial of service |
| Finding | Code4rena — Polynomial Protocol, 2023-03 · #20229 · reporter peakbolt |
| Report | code4rena.com/reports/2023-03-polynomial |
| Source | AuditVault |
| Status | Audit finding — confirmed by the sponsor, judged HIGH (direct impact on assets). Reproduced here as a standalone local PoC. |
| Compiler | ^0.8.24 (PoC) |
This is an audit finding, not a historical on-chain incident. The upstream
Code4rena source repo has been taken down, so the reduced PoC preserves the
vulnerable getTokenPrice verbatim and drives the vault into the exact
"funds present, zero supply" state the finding describes.
TL;DR#
getTokenPricereturnstotalFunds.divWadDown(totalSupply)whentotalFunds != 0andpositionId == 0, with no guard fortotalSupply == 0.- That state is reachable: after all positions close and every holder withdraws, a residual can remain (a delayed settlement / rounding leftover).
getTokenPricethen divides by zero and reverts.initiateDepositprices new shares viagetTokenPrice, so it reverts too — deposits are impossible forever. The residual cannot be withdrawn either (no shares to burn). The vault is permanently DoS'd with funds locked.
The vulnerable code#
KangarooVault.getTokenPrice (verbatim):
if (totalFunds == 0) {
return 1e18;
}
uint256 totalSupply = getTotalSupply();
if (positionData.positionId == 0) {
return totalFunds.divWadDown(totalSupply); // @> reverts when totalSupply == 0
}
Root cause#
The totalFunds == 0 special case exists, but the symmetric totalSupply == 0
case does not. Funds and supply can desync — funds can be non-zero while supply
is zero — after everyone withdraws and a residual settles in. In that state the
price is funds / 0, which reverts, and every code path that needs a price
(deposits) is bricked.
Preconditions#
- All share holders have withdrawn (
totalSupply == 0). - A residual remains in the vault (
totalFunds != 0) with no open position (positionId == 0) — a delayed settlement return or rounding leftover.
Attack walkthrough#
From output.txt:
- A healthy deposit works:
totalFunds == 0⇒ price1e18;1e18deposited,1e18shares minted. - The sole holder withdraws everything:
totalSupplyandtotalFunds→ 0. - A closed position settles a residual back into the vault:
totalFunds > 0whiletotalSupply == 0. - HARM:
getTokenPricedividestotalFundsby0and reverts. BecauseinitiateDepositcallsgetTokenPrice, every future deposit reverts — the vault can never mint shares again. The residual is locked: there are no shares to burn, so it can never be withdrawn.
Diagrams#
Impact#
Once the vault reaches the "residual + zero supply" state it is permanently unusable: deposits revert forever, so supply can never be re-created, and the trapped residual can never be withdrawn. The judge kept it HIGH for the direct impact on assets.
Remediation#
Guard getTokenPrice against a zero supply, e.g.:
uint256 totalSupply = getTotalSupply();
+ if (totalSupply == 0) {
+ return 1e18;
+ }
if (positionData.positionId == 0) {
return totalFunds.divWadDown(totalSupply);
}
How to reproduce#
cd ~/RustroverProjects/audits/evm-hack-registry/20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w_exp
forge test -vvv
# Fully local — no fork, no RPC, no anvil_state required.
# Expected: test_divByZeroBricksVault PASSES (getTokenPrice reverts, deposits
# revert forever, residual locked with no shares to redeem it).
PoC source: test/20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w_exp.sol
— drives the verbatim vulnerable getTokenPrice into the DoS state and
re-asserts the permanent brick.
Note: modelling the residual as a post-withdrawal settlement is a reduced stand-in for the finding's rounding/position-close leftover; the vulnerable
getTokenPriceand the "funds present + zero supply ⇒ deposits revert forever" mechanism are faithful.
Sources#
- AuditVault finding: 20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w.md
- Contest report: Code4rena — Polynomial Protocol (2023-03)
- Reduced-source provenance: vulnerable
KangarooVault.getTokenPricereconstructed verbatim from the AuditVault finding (which quotes thegetTokenPricebody) and the merged contest reportcode-423n4/2023-03-polynomial-findings@main. The original contest source repocode-423n4/2023-03-polynomialhas been taken down.
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w_exp (evm-hack-registry mirror).
- AuditVault finding: 20229-h-06-division-by-zero-error-causes-kangaroovault-to-be-dos-w.
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.