Reproduced Exploit

A shadowed day count skips the share decay

_deposit sets daysSinceLastDeposit to 0 and then declares a second variable with the same name inside the if. The loop later reads the outer variable, which is still 0, so r = (r * 9965) / 10000 never runs.

Undated•Ethereum•logic•2 min read

Loss

A stake of 10000 mints 10000 shares. Two days of the 9965/10000 decay mint 9930. The extra is 70

Chain

Ethereum

Category

logic

Date

Undated

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: 51786-incorrect-shares-calculation-due-to-shadowed-variable-halbor. Standalone Foundry PoC and full write-up: 51786-incorrect-shares-calculation-due-to-shadowed-variable-halbor_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/variable-shadow · vuln/defi/share-calculation

Key info#

FieldValue
LossA stake of 10000 mints 10000 shares. Two days of the 9965/10000 decay mint 9930. The extra is 70
Vulnerable contractVault.preview
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit at 0x15452ec016c4dc8c549e7fe6ff4b26324ea8b7a4
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 1970-01
Compilersolc 0.8.27, cancun, via IR
Bug classdaysSinceLastDeposit is declared again inside the if, so the decay loop reads the outer 0
flowchart TD A["Two days have elapsed and the stake is 10000"] --> B["The inner declaration computes 2"] B --> C["VULN the outer variable stays 0 and the decay loop does not run"] C --> D["The mint is 10000"] B --> E["Control runs the loop twice"] E --> F["The mint is 9930"]

TL;DR#

_deposit sets daysSinceLastDeposit to 0 and then declares a second variable with the same name inside the if. The loop later reads the outer variable, which is still 0, so r = (r * 9965) / 10000 never runs.

Two elapsed days and a stake of 10000 mint 10000 shares. The same loop run twice leaves a rate of 9930 and a mint of 9930. The extra shares are 70.

The finding has no month, so the date marker is 1970-01.

The vulnerable code#

SOLIDITY
uint256 daysSinceLastDeposit = 0;
if (elapsedDays > 0) {
    uint256 daysSinceLastDeposit = elapsedDays > 599 ? 599 : elapsedDays;
}
outerDays = daysSinceLastDeposit;
for (uint256 i = 0; i < daysSinceLastDeposit; i++) {
    r = (r * 9965) / 10000;
}
rate = r; // @> VULN: the loop saw the outer 0, so the rate is still 10000

Impact#

A second deposit does not decay the share rate. A 10000 stake receives 70 shares more than two days of the quoted multiplier allow.

How to reproduce#

BASH
cd 51786-incorrect-shares-calculation-due-to-shadowed-variable-halbor_exp
forge test -vv

test_exploit_decay_loop_does_not_run asserts a mint of 10000 and an outer day count of 0. test_control_two_days_mint_9930 asserts 9930.

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.