Reproduced Exploit

Ithaca Ledger: an int64 downcast stores −2^63 instead of +2^63

processPositionUpdates adds the new size in int256, then stores the sum with an int64(...) cast. The report's input is 4611686018427387904 (2^62). The first call fits. The second call sums to 2^63, and the cast keeps the low 64 bits, which is int64.min. The published simplified updatePositions is e…

Oct 2023•Ethereum•arithmetic•3 min read

Loss

The client's position is stored as −9,223,372,036,854,775,808 (int64.min) instead of +9,223,372,036,854,775,8…

Chain

Ethereum

Category

arithmetic

Date

Oct 2023

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

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.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 59726-false-accounting-in-position-due-to-downcasting-int256-to-in. Standalone Foundry PoC and full write-up: 59726-false-accounting-in-position-due-to-downcasting-int256-to-in_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/arithmetic/int-downcast · vuln/logic/position-accounting

Key info#

FieldValue
LossThe client's position is stored as −9,223,372,036,854,775,808 (int64.min) instead of +9,223,372,036,854,775,808 (2^63)
Vulnerable contractLedger.processPositionUpdates
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2023-10
Compilersolc 0.8.27, cancun, via IR
Bug classExplicit int256 → int64 cast truncates

TL;DR#

processPositionUpdates adds the new size in int256, then stores the sum with an int64(...) cast. The report's input is 4611686018427387904 (2^62). The first call fits. The second call sums to 2^63, and the cast keeps the low 64 bits, which is int64.min. The published simplified updatePositions is external and has no caller check, so any address can write the client's position.

An int256 ledger given the same two calls stores +2^63, which is not int64.min.

The vulnerable code#

SOLIDITY
clientPositions[position.contractId][position.client] = int64(
    int256(clientPositions[position.contractId][position.client]) + int256(position.size)
); // @> VULN: downcast truncates 2^63 to int64.min

Solidity 0.8 checks arithmetic overflow. An explicit narrowing cast does not. It cuts off the high bits.

Root cause#

The position map is int64. The addition is widened to int256 and then narrowed again. 2^63 is 0x8000000000000000. As int64 that bit pattern is −2^63, not +2^63.

Preconditions#

  • The caller can reach updatePositions. In the published snippet that function is external and has no modifier.
  • The same client and contract id are updated twice by 2^62, or by any pair of sizes whose int256 sum is outside int64.

Attack walkthrough#

  1. Call updatePositions with size 2^62. The stored position is 2^62.
  2. Call it again with size 2^62.
  3. The int256 sum is 2^63. The int64 cast stores −9223372036854775808.
  4. The sink is minted 2^63 of FALSE-POS, the magnitude of that false balance.

Diagrams#

flowchart TD A["updatePositions size = 2^62"] --> B["position is 2^62"] B --> C["second updatePositions size = 2^62"] C --> D["int256 sum is 2^63"] D --> E["int64 cast keeps the low 64 bits"] E --> F["stored position is int64.min"]

Impact#

The client's position balance is the sign-flipped minimum int64 instead of a long of 2^63. Anything that settles, margins, or pays from that stored position uses a balance that is off by 2^64.

How to reproduce#

BASH
cd 59726-false-accounting-in-position-due-to-downcasting-int256-to-in_exp
forge test -vv

test_run_positionBecomesInt64Min calls run() and checks the stored position is int64.min. test_control_int256KeepsPositiveSum stores +2^63 and asserts it is not int64.min.

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.