Reproduced Exploit
BasisOS: clamping the close-all sentinel buys back 900 of a 1,000 redemption
A full redemption sets the hedge decrease to type(uint256).max. _adjustPosition clamps every non-zero size to decreaseSizeMax. With that cap at 10,000, the stored request is 10,000 instead of the sentinel. The agent closes the real 1,000 position. The deviation is -9,000, so 1,000 * 9,000 / 10,000…
Loss
Redeemer receives 100 of 1,000 ASSET. 900 is bought back onto the spot
Chain
Ethereum
Category
logic
Date
Nov 2024
Source
AuditVault
EVM Playground
Source-level debugger — step opcodes and Solidity in sync
The attack replays in your browser. Step through it by Solidity line or by opcode.
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: 62397-loglab-10-unable-to-redeem-all-user-shares-or-sell-all-produ. Standalone Foundry PoC and full write-up: 62397-loglab-10-unable-to-redeem-all-user-shares-or-sell-all-produ_exp in the
evm-hack-registrymirror.
Vulnerability classes: vuln/logic/sentinel-clamp · vuln/defi/redemption-buyback
Key info#
| Field | Value |
|---|---|
| Loss | Redeemer receives 100 of 1,000 ASSET. 900 is bought back onto the spot |
| Vulnerable contract | BasisStrategy._adjustPosition |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2024-11 |
| Compiler | solc 0.8.27, cancun, via IR |
| Bug class | type(uint256).max close-all size is clamped, so the fill looks short |
TL;DR#
A full redemption sets the hedge decrease to type(uint256).max. _adjustPosition clamps every non-zero size to decreaseSizeMax. With that cap at 10,000, the stored request is 10,000 instead of the sentinel. The agent closes the real 1,000 position. The deviation is -9,000, so 1,000 * 9,000 / 10,000 = 900 ASSET is transferred back to the spot and bought. The redeemer receives 100. If decreaseSizeMax is type(uint256).max, the sentinel survives and the redeemer receives 1,000.
Background#
Hexens, November 2024, BasisOS / Logarithm basis strategy, LOGLAB-10. spotSellCallback uses type(uint256).max as the close-all signal for both size and collateral. _afterDecreasePosition copies the agent's actual fill over that sentinel before the deviation check. The clamp in _adjustPosition destroys the signal whenever decreaseSizeMax is any smaller value. The fix is to skip the clamp when the size is type(uint256).max.
The vulnerable code#
recordedMax = max;
// @> VULN: the close-all sentinel is clamped to decreaseSizeMax, so it is no longer type(uint256).max
clampedSize = _clamp(min, sizeDeltaInTokens, max);
The buyback then uses the clamped request:
revertedAmt = pending * sizeDeviationAbs / requestSize;
Root cause#
type(uint256).max means "close whatever the position actually is". Treating it as a numeric size and capping it makes a full fill look like an under-fill against a much larger request.
Preconditions#
- Users are redeeming everything, so vault supply is 0 and the close-all branch runs.
decreaseSizeMaxis 10,000. The hedge position and the sale proceeds are 1,000.- The response deviation threshold is 100 bps. A 90 percent gap exceeds it.
- The agent reports the real decrease of 1,000, which is the whole position.
Attack walkthrough#
decreaseSizeMaxis stored as 10,000. The strategy holds 1,000 ASSET of sale proceeds.spotSellCallbacksets the size sentinel totype(uint256).max.- The clamp stores 10,000. The sentinel branch in
_afterDecreasePositiondoes not run. - Deviation is 1,000 - 10,000. The negative branch buys 900 back on the spot.
- The redeemer is transferred 100.
- The control uses
decreaseSizeMax = type(uint256).max. The clamp returns the sentinel, the request is replaced by the 1,000 fill, and the redeemer receives 1,000.
Diagrams#
Impact#
The redeemer is paid 100 ASSET of a 1,000 ASSET redemption. 900 ASSET is back on the spot, so the hedge is closed and the spot is open again. The same close with decreaseSizeMax equal to type(uint256).max pays the full 1,000 and buys nothing back.
Remediation#
Do not clamp sizeDeltaInTokens when it equals type(uint256).max. The close-all branch in _afterDecreasePosition can then replace the sentinel with the agent's actual fill before the deviation check.
How to reproduce#
cd 62397-loglab-10-unable-to-redeem-all-user-shares-or-sell-all-produ_exp
forge test -vv
test_exploit_close_all_buys_back_900 asserts a 900 spot balance, a 100 redeemer balance, and a 900 LOCKED marker. test_control_max_decrease_pays_the_full_1000 asserts a 1,000 redeemer balance and an empty spot.
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/62397-loglab-10-unable-to-redeem-all-user-shares-or-sell-all-produ.md
- Report: https://github.com/solodit/solodit_content/blob/main/reports/Hexens/2024-11-25-BasisOS.md
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 62397-loglab-10-unable-to-redeem-all-user-shares-or-sell-all-produ_exp (evm-hack-registry mirror).
- AuditVault finding: 62397-loglab-10-unable-to-redeem-all-user-shares-or-sell-all-produ.
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.