Reproduced Exploit

Abacus: remove clears the wrong tokenMapping key and closes the pool

includeNft and getHeldTokenExistence use id << 160 | nft. remove writes nft << 160 | id. The real slot stays true, so the owner can sign the same NFT again. Each remove increments nftRemoved. With nftsInPool equal to 2, two sign-and-remove cycles on one NFT close the pool. liquidate then reverts an…

Jul 2022•Ethereum•logic•4 min read

Loss

Liquidation reverts. The borrower keeps 100 USD and the NFT still shows as held

Chain

Ethereum

Category

logic

Date

Jul 2022

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

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.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 48698-inconsistency-in-usage-of-tokenmapping-ottersec-none-abacus. Standalone Foundry PoC and full write-up: 48698-inconsistency-in-usage-of-tokenmapping-ottersec-none-abacus_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/incorrect-state-transition · vuln/dos/frozen-funds

Key info#

FieldValue
LossLiquidation reverts. The borrower keeps 100 USD and the NFT still shows as held
Vulnerable contractVault.remove
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2022-07
Compilersolc 0.8.27, cancun, via IR

TL;DR#

includeNft and getHeldTokenExistence use id << 160 | nft. remove writes nft << 160 | id. The real slot stays true, so the owner can sign the same NFT again. Each remove increments nftRemoved. With nftsInPool equal to 2, two sign-and-remove cycles on one NFT close the pool. liquidate then reverts and the 100 USD loan is not repaid. The consistent-key control clears the include slot, leaves the pool open, and lets liquidation zero the debt.

The vulnerable code#

SOLIDITY
function remove(address nft, uint256 id) external {
    uint256 tempStorage = removeKey(nft, id);
    tokenMapping[tempStorage] = false;
    Factory(factory).updateNftInUse(nft, id); // @> VULN: the slot cleared above is nft<<160|id, not the includeNft key
}

removeKey is uint256(uint160(nft)) << 160 | id. includeKey is id << 160 | uint256(uint160(nft)). OtterSec's patch used one encoding everywhere and updated the mapping after updateNftInUse. The control does that: it checks existence, increments nftRemoved, then clears the include key.

Root cause#

Two functions pack the same pair in opposite orders. A write through the remove key does not delete the include key, so every later existence check still succeeds and every remove still counts.

Preconditions#

  • The pool tracks two NFTs. The attacker owns one of them and can sign and remove it. That is the report's PoC, not an admin action.
  • Lend has 100 USD and accepts the NFT while the include key is set and the pool is open.

Attack walkthrough#

  1. Both NFT ids are included. The attacker borrows 100 USD against id 1.
  2. The attacker signs id 1 and removes it. The wrong slot is cleared. Existence stays true. nftRemoved becomes 1.
  3. The attacker signs and removes id 1 again. nftRemoved becomes 2 and the pool closes.
  4. liquidate reverts with pool closed.
  5. The debt is still 100 USD. That balance is the attacker's.

Diagrams#

flowchart TD A["Borrow 100 USD against an included NFT"] --> B["Sign and remove the NFT"] B --> C["VULN remove clears nft shifted 160 or id"] C --> D["Include key stays true so a second sign works"] D --> E["nftRemoved reaches nftsInPool and the pool closes"] E --> F["Liquidation reverts and the 100 USD is not repaid"]

Impact#

One NFT owner forces closePool while the collateral still shows as held. The lender cannot liquidate, so the 100 USD loan stays with the borrower. The report's second note, that a correct key written before updateNftInUse would make remove revert, is why the control clears the include key only after the existence check.

Remediation#

Use one key in includeNft, remove, closeNft, and getHeldTokenExistence, and clear it after the factory has finished its existence check. The control then removes the NFT once, refuses a second signature, and lets liquidate clear the debt.

How to reproduce#

BASH
cd 48698-inconsistency-in-usage-of-tokenmapping-ottersec-none-abacus_exp
forge test -vv

test_exploit_wrong_key_closes_pool_and_bricks_liquidation asserts a closed pool, a reverted liquidation, a 100 USD debt, and unequal keys. test_control_consistent_key_removes_once_and_liquidation_works asserts the pool stays open and the debt is cleared.

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

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.