Skip to content
Business logic Audit finding Intermediate

Potential unfair distribution of Rewards due to MEV in updateBucketExchangeRatesAndClaim

The public reward-claiming function pays the first caller who updates bucket exchange rates, so a bot can front-run honest users and take the reward. This discourages non-technical users from maintaining the system.

bytes032 Follow with patitonar and troublor

Originally disclosed on Code4rena

Submitted by bytes032, also found by patitonar and troublor

This vulnerability allows malicious actors to exploit the reward system by frontrunning transactions and unfairly claiming rewards, thereby disincentivizing honest users from updating the bucket exchange rates and contributing to the system.

Proof of Concept

The updateBucketExchangeRatesAndClaim function is publicly callable and serves two main purposes:

  1. Updates the exchange rate of a list of buckets.
  2. If eligible, the caller can claim 5% of the rewards accumulated to each bucket since the last burn event, if it hasn’t already been updated.

https://github.com/code-423n4/2023-05-ajna/blob/fc70fb9d05b13aee2b44be2cb652478535a90edd/ajna-core/src/RewardsManager.sol#L310-L318

function updateBucketExchangeRatesAndClaim(
        address pool_,
        uint256[] calldata indexes_
    ) external override returns (uint256 updateReward) {
        updateReward = _updateBucketExchangeRates(pool_, indexes_);

        // transfer rewards to sender
        _transferAjnaRewards(updateReward);
    }

So, to summarize it’s primary purpose is to incentivize people who keep the state updated. However, given the nature of the function (first come, first serve) it becomes very prone to MEV.

Consider the following scenario:

  1. Alice is hard-working, non-technical and constantly keeps track of when to update the buckets so she can claim a small reward. Unfortunately, she becomes notorious for getting most of the rewards from updating the bucket exchange rate.
  2. A malicious actor spots Alice’s recent gains and creates a bot to front run any transactions to RewardsManager’s _updateBucketExchangeRateAndCalculateRewardssubmitted by Alice.
  3. The day after that, Alice again see’s theres a small reward to claim, attempts to claim it, but she gets front runned by whoever set the bot.
  4. Since Alice is non-technical, she cannot ever beat the bot so she is left with a broken heart and no longer able to claim rewards.

I believe the system should be made fair to everybody that wants to contribute, hence this is a vulnerability that should be taken care of to ensure the fair distribution of awards to people who care about the protocol instead of .

Recommended Mitigation Steps

I see potentially two solutions here:

  1. Introduce a randomized reward mechanism, such as a lottery system or a probabilistic reward distribution for people who contribute to updating buckets. This could reduce the predictability of rewards and hence the potential for MEV exploitation.
  2. Consider limiting the reward claim process to users who have staked in the rewards manager because they are the individuals that are directly affected if the bucket is not updated, because if its not updated for 14 days they won’t be getting rewards. Additionally, you can couple it with a rate-limitting mechanism by implementing a maximum claim per address per time period

MikeHathaway (Ajna) acknowledged


The original report as published on Code4rena, by bytes032. 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 reward is given to whoever calls first, with no randomness or restriction, making the payout predictable and easy to front-run.

Impact

Honest users could be consistently beaten to the reward, reducing their incentive to keep the system updated.

What the attacker needed

Public mempool visibility; attacker can pay higher gas; reward available to claim

The fix

The reward mechanism should be changed, for example by randomising payouts or limiting claims to staked users with rate limits.

How it was found

  1. Alice watches for a moment when a bucket reward is available.
  2. A malicious actor builds a bot that watches for Alice's update transactions.
  3. Alice sends her update transaction.
  4. The bot front-runs it and claims the reward instead.

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 smart contract pays a small reward to whoever first updates some stored numbers. Because anyone can see a pending update in the public queue, a faster bot can copy it and grab the reward before the original person. The honest user then stops bothering.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by bytes032

View all

7 more disclosed reports, best first.

More from Ajna Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.