Reproduced Exploit
QuantAMM: a negative weight multiplier underflows and the swap reverts
calculateBlockNormalisedWeight adds a positive multiplier and subtracts a negative one. The negative branch casts the multiplier to uint256 first. The report's value, -0.001e18, becomes a word near 2^256. Subtracting mulUp of that word from the 0.15e18 weight underflows, so onSwap reverts whenever…
Loss
The swap reverts. No trader can exit through the negative-multiplier weight
Chain
Ethereum
Category
arithmetic
Date
Dec 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: 44296-incorrect-handling-of-negative-multipliers-in-quantammweight. Standalone Foundry PoC and full write-up: 44296-incorrect-handling-of-negative-multipliers-in-quantammweight_exp in the
evm-hack-registrymirror.
Vulnerability classes:
vuln/arithmetic/underflow·vuln/logic/price-calculation
Key info#
| Field | Value |
|---|---|
| Loss | The swap reverts. No trader can exit through the negative-multiplier weight |
| Vulnerable contract | QuantAMMWeightedPool.calculateBlockNormalisedWeight |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2024-12 |
| Compiler | solc 0.8.27, cancun |
| Bug class | Negative int256 cast to uint256 before subtraction |
TL;DR#
calculateBlockNormalisedWeight adds a positive multiplier and subtracts a negative one. The negative branch casts the multiplier to uint256 first. The report's value, -0.001e18, becomes a word near 2^256. Subtracting mulUp of that word from the 0.15e18 weight underflows, so onSwap reverts whenever timeSinceLastUpdate is not zero. Negating before mulUp returns a smaller positive weight and the swap can proceed.
Background#
Cyfrin's 17 December 2024 QuantAMM V1.2 review. The function is QuantAMMWeightedPool.calculateBlockNormalisedWeight at commit 7213401, lines 505-521. QuantAMM fixed it in commit 31636cf by multiplying uint256(-multiplierScaled18). The playground timestamp is 1784893842, so the elapsed time is not zero. lastUpdate stays 0.
The vulnerable code#
if (_multiplier > 0) {
return uint256(_weight) + FixedPoint.mulDown(uint256(multiplierScaled18), timeSinceLastUpdate);
} else {
return uint256(_weight) - FixedPoint.mulUp(uint256(multiplierScaled18), timeSinceLastUpdate); // @> VULN: uint256(negative) is ~2^256, so this subtraction underflows
// FIX: return uint256(_weight) - FixedPoint.mulUp(uint256(-multiplierScaled18), timeSinceLastUpdate);
}
FixedPoint.mulUp is the Balancer round-up. The product is taken in assembly so the huge cast still returns a huge quotient instead of aborting inside the multiply, which is the underflow the report describes on the subtraction.
Root cause#
uint256(negativeInt) is not the absolute value. It is the two's-complement bit pattern. The following subtraction is then weight - enormous and reverts under checked arithmetic. Every swap that needs this weight reverts with it.
Preconditions#
- The second weight from the report:
0.15e18with multiplier-0.001e18. timeSinceLastUpdateis not zero. HerelastUpdateis 0 and the block timestamp is1784893842.
Attack walkthrough#
- Call
onSwapfor 1 token. - The pool loads
block.timestamp - lastUpdate. - The negative branch casts the multiplier and the subtraction reverts.
- The low-level call returns false. Reserves do not move.
calculateFixednegates the multiplier first. The resulting weight is below0.15e18and still positive.
Diagrams#
Impact#
A swap against the falling weight does not execute. The trader who needs to sell that token cannot. The fixed formula at the same timestamp produces a positive weight below the stored 0.15e18, which is the update the pool should have applied.
Remediation#
Subtract FixedPoint.mulUp(uint256(-multiplierScaled18), timeSinceLastUpdate), which is the change in commit 31636cf.
How to reproduce#
cd 44296-incorrect-handling-of-negative-multipliers-in-quantammweight_exp
forge test -vv
The test warps to 1784893842 before run. test_negative_multiplier_reverts_swap asserts the swap reverted and the fixed weight is strictly below 0.15e18. Captured output is output.txt.
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/44296-incorrect-handling-of-negative-multipliers-in-quantammweight.md
- Report: https://github.com/solodit/solodit_content/blob/main/reports/Cyfrin/2024-12-17-cyfrin-quantamm-v1.2.md
- Blamed lines: https://github.com/QuantAMMProtocol/QuantAMM-V1/blob/7213401491f6a8fd1fcc1cf4763b15b5da355f1c/pkg/pool-quantamm/contracts/QuantAMMWeightedPool.sol#L505-L521
- Fix: https://github.com/QuantAMMProtocol/QuantAMM-V1/commit/31636cf736e9f6eda09f569bceb4e8d9bd3137bb
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 44296-incorrect-handling-of-negative-multipliers-in-quantammweight_exp (evm-hack-registry mirror).
- AuditVault finding: 44296-incorrect-handling-of-negative-multipliers-in-quantammweight.
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.