Reproduced Exploit
Royco: VaultOrderbook rate check is seeded with the requested rate
The first loop in allocateOrder sets tokenToRate[token] = tokenRatesRequested[i]. The vault rate is only added after that. The comparison tokenRatesRequested > tokenToRate can never fail. An order that asks for REAL at 100 is filled when previewRateAfterDeposit returns 0, and the LP loses 1,000 BAS…
Loss
The LP's 1,000 BASE is taken while the vault will pay a REAL rate of 0
Chain
Ethereum
Category
logic
Date
Aug 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: 46678-rate-checks-unenforceable-due-to-faulty-cache-value-initiali. Standalone Foundry PoC and full write-up: 46678-rate-checks-unenforceable-due-to-faulty-cache-value-initiali_exp in the
evm-hack-registrymirror.
Vulnerability classes:
vuln/logic/state-update·vuln/logic/missing-check
Key info#
| Field | Value |
|---|---|
| Loss | The LP's 1,000 BASE is taken while the vault will pay a REAL rate of 0 |
| Vulnerable contract | VaultOrderbook.allocateOrder |
| Attacker EOA | 0x1111111111111111111111111111111111111111 (the allocator) |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2024-08 |
| Compiler | solc 0.8.27, cancun |
| Bug class | First loop copies tokenRatesRequested into the cache the check reads |
TL;DR#
The first loop in allocateOrder sets tokenToRate[token] = tokenRatesRequested[i]. The vault rate is only added after that. The comparison tokenRatesRequested > tokenToRate can never fail. An order that asks for REAL at 100 is filled when previewRateAfterDeposit returns 0, and the LP loses 1,000 BASE. Deleting that loop makes the same fill revert.
The vulnerable code#
for (uint256 i; i < order.tokenRatesRequested.length; ++i) {
tokenToRate[order.tokensRequested[i]] = order.tokenRatesRequested[i]; // @> VULN: cache starts at the requested rate, so the check below cannot fail
}
- for (uint256 i; i < order.tokenRatesRequested.length; ++i) {
- tokenToRate[order.tokensRequested[i]] = order.tokenRatesRequested[i];
- }
Root cause#
The cache is initialized to the value the later loop is supposed to test. Adding a non-negative vault rate cannot make the cached value smaller than the request, so OrderConditionsNotMet is dead.
Preconditions#
- The LP requests REAL at rate 100 and has approved 1,000 BASE.
- The matching campaign's
previewRateAfterDepositis 0.
Attack walkthrough#
- The LP approves 1,000 BASE.
allocateOrderis called with the REAL campaign.- The cache for REAL is set to 100 before the vault is read.
- The vault adds 0. The check is
100 > 100, which does not revert. - The book pulls 1,000 BASE.
- The LP receives no REAL. The allocator holds the 1,000 BASE.
Diagrams#
Impact#
The LP loses 1,000 BASE on an order the vault cannot pay. The control, which starts the cache at 0, reverts and the deposit stays with the LP.
How to reproduce#
cd 46678-rate-checks-unenforceable-due-to-faulty-cache-value-initiali_exp
forge test -vv
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/46678-rate-checks-unenforceable-due-to-faulty-cache-value-initiali.md
- Cantina Royco report, August 2024: https://cdn.cantina.xyz/reports/cantina_royco_august2024.pdf
- Royco fix commit cited by the finding:
2129be28(the seeding loop was removed)
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 46678-rate-checks-unenforceable-due-to-faulty-cache-value-initiali_exp (evm-hack-registry mirror).
- AuditVault finding: 46678-rate-checks-unenforceable-due-to-faulty-cache-value-initiali.
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.