Skip to content
Race condition Audit finding Intermediate

Users Can Frontrun Calls to updateRewardsMetadata() And Claim Tokens Twice

The reward distributor contract allows users to claim rewards based on a merkle root that the admin can update. If a user frontruns the admin's call to update the merkle root, they can claim their reward twice or cause a loss of rewards.

leastwood Follow

Originally disclosed on Code4rena

Submitted by leastwood

The updateRewardsMetadata() function is called by the BribeVault contract by the admin role. The function will take a list of distributions which are used to update the associated reward metadata. It is expected that the merkle root will be updated to correctly identify which claimers have already claimed tokens.

reward.updateCount is incremented to reset the claimed tracker, allowing users that may have previously claimed, to claim their updated reward. However, there is potential for mis-use if users frontrun calls to updateRewardsMetadata() and claim their reward after the new merkle root has been calculated and updated by the admin role. This may allow the claimer to double claim their rewards or lead to a loss in rewards if the reward metadata completely replaces the previous list of claimers.

Proof of Concept

RewardDistributor.sol#L97-L119 RewardDistributor.sol#L127-L209

Recommended Mitigation Steps

Consider implementing a delay where users cannot claim rewards before a call to updateRewardsMetadata() is made. This should ensure the admin role can construct a merkle tree based on the most up-to-date and correct data.

kphed (Redacted Cartel) confirmed and commented:

After speaking with leastwood via Discord, I now believe this issue to be meaningfully different from issue M-09 and is a valid attack vector. His recommended solution above inspired a fix which we both agreed would solve the problem (i.e. set a “blank” merkle root, evaluate the users who claimed with the previous merkle root, and construct a new one accordingly).

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

I appreciate the nuance from the sponsor over this finding.

Ultimately when using a merkle proof system, the new proof is calculated at a certain time. (ProofX)

If UserA didn’t claim when the proof was generated, they technically have time between when the proof is generated and the proof is published to claim for the first time.

Because the new Merkle Proof (ProofX) was built to allow UserA to claim, they will be able to claim again.

The only way I can think of to avoid this is to always only have one proof per set of claims, as to avoid getting front-run.

There is merit to make this finding separate, although ultimately the reason why this is possible is because of the Admin ability to change the proofs at any time.

So I’m going to suggest that this finding is similar to M-09, it’s mitigation should be basically the same, however I’ll mark as separate to give credit where it’s due.

Because the finding is contingent on external conditions (owner getting frontrun or owner being malicious), I believe medium severity to be appropriate.

A mitigation could be to push new proofs via Flashbots, and use a snapshot like system to check that no claims where made in the time between the proof generation and the proof being set.


The original report as published on Code4rena, by leastwood. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 contract allows claims to be processed against a merkle root that is about to be replaced, without a delay or snapshot mechanism to prevent double claiming.

Impact

A user could double claim their rewards or cause a loss of rewards if the new merkle root completely replaces the previous list of claimers.

What the attacker needed

Admin updates merkle root; user frontruns the update

The fix

The fix should implement a delay where users cannot claim rewards before a call to `updateRewardsMetadata()` is made, or set a blank merkle root and evaluate previous claims before constructing a new one.

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 root is like a fingerprint of a list of who can claim rewards. The admin updates this list, but if a user claims just before the update, they might be able to claim again with the new list, getting double rewards.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by leastwood

View all

70 more disclosed reports, best first.

More from Redacted Cartel contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.