Merkle-tree-related contracts vulnerable to cross-chain-replay attacks
Merkle-tree distribution contracts encode leaves without any chain identifier, so after a blockchain fork the same withdrawal proof is valid on both chains. An attacker could watch a withdrawal on one chain and replay the identical call on the other, sending tokens to an address that may be unusable there.
Submitted by IllIllI
Bank is a token vesting, airdrop and payroll tool. It uses merkle trees to massively scale token distributions with integrated vesting (time locks). The idea of this tool is that it allows DAOs to vest pre-sale participants, and future allocations of tokens (such as DAO treasury allocations) far into the future. These are important contracts since they need longevity and will secure large allocations of tokens.
Since these trees are long-lived, they need to be able to handle forks correctly. If someone generates an exchange address for their drops, that address may only be valid for that chain (e.g. exchange supports BTC but not BSV), and any funds sent to the unsupported chain are lost.
Impact
If there’s a fork, since anyone can call withdraw(), an attacker can monitor the blockchain for calls to withdraw(), and then make the same call with the same arguments on the other chain, which will send funds to the unsupported address.
Proof of Concept
There are no EIP-712 protections in the encoding:
File: contracts/MerkleDropFactory.sol #1
94 bytes32 leaf = keccak256(abi.encode(destination, value));
File: contracts/MerkleVesting.sol #2
109 bytes32 leaf = keccak256(abi.encode(destination, totalCoins, startTime, endTime, lockPeriodEndTime));
and anyone can trigger a withdrawal:
File: contracts/MerkleDropFactory.sol #3
82 /// @dev Anyone may call this function for anyone else, funds go to destination regardless, it's just a question of
83 /// @dev who provides the proof and pays the gas, msg.sender is not used in this function
Recommended Mitigation Steps
Add EIP-712 protections and add a mechanism to allow tokens to be transferred to a different address using EIP-2612 permit()
illuzen (FactoryDAO) acknowledged, disagreed with severity and commented:
Sending funds to an unusable address on a chain that we didn’t intend to be on doesn’t seem in scope, but good thinking. In any case, the exchange will have the key for the address on the other chain since private keys are chain agnostic.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the leaf hash omits any chain identifier or signed authorisation, so a proof valid on one chain is equally valid on a forked chain.
Impact
Tokens could be sent to an address that is unsupported on the forked chain, and the project argued the recipient would still hold the key there, so the practical loss is limited.
What the attacker needed
A blockchain fork occurs; attacker can watch both chains; withdrawal call is public
The fix
The report recommends adding EIP-712 protections to the encoding and a way to move tokens to a different address via EIP-2612 permit; the project acknowledged the finding but disputed its severity.
How it was found
- Wait for a blockchain fork so the same contract exists on two chains.
- Watch the chain for a call to the withdrawal function.
- Repeat the same call with the same arguments on the other chain.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A merkle tree is a way to prove, with a short proof, that an address is entitled to some tokens. Here the proof is built only from the destination and amount, with nothing tying it to one particular blockchain. If a chain splits into two copies, the same proof works on both, so someone can repeat a withdrawal on the copy where the recipient cannot use the funds.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.