Skip to content
Business logic Audit finding Advanced

PirexGmx#migrateReward() may cause users to lose Reward.

During a contract migration, the reward producer in PirexRewards still pointed at the old PirexGmx contract, so a bot calling compound could route a claim through the old contract, which returned zero rewards. This meant pending rewards for AutoPxGmx could be lost.

bin2chen Follow

Originally disclosed on Code4rena

Submitted by bin2chen

PirexGmx#migrateReward() may cause users to lose Reward before PirexRewards.sol set new PirexGmx.

Proof of Concept

The current migration process is: call # completemigration ()-> # migrateward ()

After this method, the producer of PirexRewards.sol contract is still the old PirexGmx.

At this time, if AutoPxGmx#compound () is called by bot:

AutoPxGmx#compound() -> PirexRewards#.claim() -> old_PirexGmx#claimRewards()

Old_PirexGmx#claimRewards () will return zero rewards and the reward of AutopXGMX will be lost.

Old PirexGmx still can execute https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/PirexGmx.sol#L824-L828

https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/PirexGmx.sol#L940-L949

Recommended Mitigation Steps

There are two ways to solve the problem.

  1. Set the producer of PirexRewards to the new PirexGmx in completeMigration ().
  2. In #migrateReward (), set the old PirexGmx’s “pirexRewards” to address(0), so that you can’t use the old PirexGmx to get rewards

Simply use the second, such as:

    function migrateReward() external whenPaused {
        if (msg.sender != migratedTo) revert NotMigratedTo();
        if (gmxRewardRouterV2.pendingReceivers(address(this)) != address(0))
            revert PendingMigration();

        // Transfer out any remaining base reward (ie. WETH) to the new contract
        gmxBaseReward.safeTransfer(
            migratedTo,
            gmxBaseReward.balanceOf(address(this))
        );
+       pirexRewards ==address(0);   //*** set pirexRewards=0,Avoid claimRewards () being called by mistake.***//
    }

drahrealm (Redacted Cartel) confirmed


The original report as published on Code4rena, by bin2chen. 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 migration left PirexRewards pointing at the old PirexGmx as its reward producer, and the old contract could still be called to claim rewards after migration.

Impact

Pending AutoPxGmx rewards could be lost if a bot calls compound during the window after migration.

What the attacker needed

Migration has been run; a bot calls compound before the producer is updated

The fix

The reporter suggested setting PirexRewards' producer to the new PirexGmx during completeMigration, or clearing the old PirexGmx's pirexRewards reference in migrateReward so it cannot be used to claim.

How it was found

  1. Run the migration, which calls completeMigration and then migrateReward.
  2. Note that PirexRewards still lists the old PirexGmx as its producer.
  3. Have a bot call AutoPxGmx compound, which claims through PirexRewards and the old PirexGmx.
  4. Observe that the old PirexGmx returns zero rewards and the rewards are lost.

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 is being replaced with a newer version. The rewards contract was still told to ask the old version for rewards, and the old version no longer had any to give, so a routine automated claim could wipe out rewards that should have gone to users.

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 bin2chen

View all

139 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.

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.