Zealynx AcademyZealynx Academy
ZLX-Check

Spot the Bug: the Merkle proof that proves the wrong thing

Question 1 of 3Score 0/3

An airdrop builds a leaf as keccak256(abi.encode(amount)), verifies the Merkle proof, then pays msg.sender. What is still wrong?

Review and apply

Worked answers

Try the quiz above first, then open an answer to compare your reasoning. These notes are also available to read without completing an attempt.

  1. 1. An airdrop builds a leaf as keccak256(abi.encode(amount)), verifies the Merkle proof, then pays msg.sender. What is still wrong?

    • A.Nothing, verifying the proof covers it
    • B.The leaf commits only to the amount, not the claimer, so any valid proof claims someone else's allocation
    • C.abi.encode should be abi.encodePacked
    • D.keccak256 is too expensive to use for leaves
    Answer and explanation

    B. The leaf commits only to the amount, not the claimer, so any valid proof claims someone else's allocation

    A verified proof only proves that an amount-leaf sits in the tree. It says nothing about who is allowed to claim it. Because msg.sender is never hashed into the leaf, any caller with any valid proof passes the check and takes an allocation assigned to someone else.

  2. 2. The leaf is keccak256(amount) and the contract never marks it claimed. How does an attacker profit?

    • A.They cannot; the Merkle root is immutable
    • B.They submit a valid proof, get paid, then submit the same proof again and again until the pool is empty
    • C.They front-run the deployer to swap the root
    • D.They overflow the amount to mint new tokens
    Answer and explanation

    B. They submit a valid proof, get paid, then submit the same proof again and again until the pool is empty

    Two failures compound. The leaf does not bind a claimer, so a proof works for any caller, and nothing records that the leaf was spent, so the same proof is accepted repeatedly. One valid proof becomes an unlimited withdrawal.

  3. 3. What actually closes this?

    • A.Add onlyOwner to the claim function
    • B.Hash msg.sender into the leaf, and record each leaf as claimed on first use so reuse reverts
    • C.Wrap the token transfer in a try/catch
    • D.Emit a Claimed event after paying out
    Answer and explanation

    B. Hash msg.sender into the leaf, and record each leaf as claimed on first use so reuse reverts

    The leaf must bind the claimer, keccak256(msg.sender, amount), so a proof only works for its owner. Then track claimed leaves and reject a second use. Access control, events, and try/catch do nothing to stop a valid proof from being replayed.

Read alongside: See it in real audits