hats-finance / Metrom-0xfdfc6d4ac5807d7460da20a3a1c0c84ef2b9c5a2

Smart contracts for the Metrom project.
GNU General Public License v3.0
0 stars 0 forks source link

Merkle implementation does not prevent replication of transactions across chains #42

Open hats-bug-reporter[bot] opened 5 months ago

hats-bug-reporter[bot] commented 5 months ago

Github username: -- Twitter username: -- Submission hash (on-chain): 0xe37fb55a31f8d87b0655e71114e2825ce9b102b2694c790becc5002ec8784262 Severity: high

Description: Description\ - SUMMARY -

As stated in the Discord Q&A: "The Metrom contract will be deployed on multiple chains according to demand (if a dex strictly requires the Metrom campaigns to live on chain A, we'll deploy an instance there too)."

However, the existing implementation of merkle tree proofs fails to consider this aspect, thus enabling the replication of transactions across chains.

- DETAILS -

Within the claimRewards() function, the _processRewardClaim() function is called invoking MerkleProof.verifyCalldata() as shown in the code below.

Attack Scenario\

  1. The attacker executes a transaction successfully on the Ethereum Mainnet by calling claimRewards() and satisfying all the arguments required in the _bundles parameter.
  2. At this point, the core components of the exploit, namely the proof and root, have already been revealed.
  3. On a different EVM chain where the contract is deployed, the attacker replicates the transaction by calling the claimRewards() function with identical arguments used in the successful transaction during Step 1.
  4. Now, the attacker can acquire additional rewards on every chain where the contract is deployed.

- IMPACT -

Given that rewards can be replicated for each attacker across multiple chains, the protocol faces the risk of losing funds.

Attachments

  1. Proof of Concept (PoC) File n/a

  2. Revised Code File (Optional) n/a

mcgrathcoutinho commented 5 months ago

@luzzif This issue assumes there are two similar campaigns by the owner running on two different chains. In this case, if the user is able to claim rewards on both chain A and chain B, that means it is intentional for the user to earn rewards on both chains since the root is set by the updater. If the root on chain B is different, the user cannot claim the rewards. I do not think this is an issue since at the end it is the updater setting the roots across chains after seeing who is eligible to earn rewards and who is not.

luzzif commented 5 months ago

You're right on this one too actually. If the same root is on multiple chains, assuming the updater does its job correctly, it's only right that the same claim can be processed on both chains without any apparent issue.

0xgreywolf commented 5 months ago

Hi @luzzif and @mcgrathcoutinho.

The possibility of the transaction replay still exists and lingers. If a malicious campaign owner uses it to his/her advantage by creating two identical campaigns, then uses his/her own wallet (another wallet) and does the replay transaction himself/herself which is very feasible because he/she will basically replicate his/her rewards.

luzzif commented 5 months ago

But this wouldn't make much sense. The attacker would need to create a second campaign, putting rewards on the line, to only get a portion of them back by replaying a transaction/claim?

0xgreywolf commented 5 months ago

@luzzif Got it. You're right. I misinterpreted the purpose of the campaign itself. Thanks for explaining.