SNARKeling Treasure Hunt

First Flight #59
Beginner FriendlyGameFiFoundry
100 EXP
Submission Details
Impact: medium
Likelihood: medium

ALLOWED_TREASURE_HASHES contains a duplicate entry, so the hunt exposes only 9 unique treasures while MAX_TREASURES == 10

Author Revealed upon completion

Description

  • The Noir circuit's ALLOWED_TREASURE_HASHES is declared as a 10-element array and paired with MAX_TREASURES = 10 in the Solidity contract. The deployment flow funds the contract with 100 ETH so that each of the ten expected treasures can be redeemed for 10 ETH.

  • Entries at index 8 and index 9 of ALLOWED_TREASURE_HASHES are byte-for-byte identical. The circuit therefore admits only 9 distinct treasure_hash public inputs, while the on-chain claimed mapping keys on that hash and enforces uniqueness. Once the nine unique hashes are consumed, no tenth hash exists for claim() to succeed on, so claimsCount stops at 9. Since withdraw() requires claimsCount >= MAX_TREASURES == 10, it becomes permanently unreachable, stranding the tenth 10 ETH reward in the contract.

// circuits/src/main.nr
global ALLOWED_TREASURE_HASHES: [Field; 10] = [
1505662313093145631275418581390771847921541863527840230091007112166041775502,
-7876059170207639417138377068663245559360606207000570753582208706879316183353,
-5602859741022561807370900516277986970516538128871954257532197637239594541050,
2256689276847399345359792277406644462014723416398290212952821205940959307205,
10311210168613568792124008431580767227982446451742366771285792060556636004770,
-5697637861416433807484703347699404695743570043365849280798663758395067508,
-2009295789879562882359281321158573810642695913475210803991480097462832104806,
8931814952839857299896840311953754931787080333405300398787637512717059406908,
@> -961435057317293580094826482786572873533235701183329831124091847635547871092, // index 8
@> -961435057317293580094826482786572873533235701183329831124091847635547871092 // index 9 (duplicate)
];

Risk

Likelihood:

  • Occurs on every deployment using the shipped circuit artifacts — the set membership check is_allowed(treasure_hash) and the Solidity MAX_TREASURES constant never align because the circuit only exposes nine distinct hashes.

  • No user action is required to trigger the inconsistency; once any nine distinct hashes are claimed, the final reward slot is locked.

Impact:

  • 10 ETH (one tenth of the funded reward pool) is permanently stranded inside the contract. withdraw() reverts with HUNT_NOT_OVER because claimsCount caps at 9.

  • Only emergencyWithdraw() (owner-only, requires the contract be paused) can recover the stuck funds, breaking the advertised "organizer withdraws after hunt" UX.

  • Participants advertised a hunt with ten treasures receive only nine reward opportunities; if both physical "9th" and "10th" treasures share the duplicated secret, the second finder receives nothing.

Proof of Concept

Source-level inspection of circuits/src/main.nr lines 64–65 shows the two literals are textually identical. No runtime PoC is needed — the equality is textual and deterministic at circuit-compilation time.

// circuits/src/main.nr, lines 64-65 (from ALLOWED_TREASURE_HASHES initializer)
-961435057317293580094826482786572873533235701183329831124091847635547871092,
-961435057317293580094826482786572873533235701183329831124091847635547871092

Economic consequence: after 9 successful claims claim() reverts AllTreasuresClaimed only if claimsCount >= 10; actually it reverts because no further distinct hash can pass is_allowed. Any attempt at the tenth slot fails proof verification. withdraw() checks claimsCount >= MAX_TREASURES and reverts with HUNT_NOT_OVER, leaving 10 ETH permanently stuck pending emergencyWithdraw().

Recommended Mitigation

Replace the duplicated value at index 9 with the intended tenth distinct treasure hash, regenerate the verifier contract and proving key, and regenerate the Foundry fixtures. Alternatively, if only nine treasures were ever intended, align the contract constant and the deployment funding to match so the lifecycle terminates cleanly.

// circuits/src/main.nr
global ALLOWED_TREASURE_HASHES: [Field; 10] = [
...
-961435057317293580094826482786572873533235701183329831124091847635547871092,
- -961435057317293580094826482786572873533235701183329831124091847635547871092
+ <new_distinct_tenth_treasure_hash>
];

If keeping nine treasures:

// contracts/src/TreasureHunt.sol
- uint256 public constant MAX_TREASURES = 10;
+ uint256 public constant MAX_TREASURES = 9;

And update the deployment script's fixed funding from 100 ether to 90 ether. In both cases, regenerate the circuit artifacts and the Foundry fixtures so the on-chain verifier matches the compiled Noir code.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!