Skip to content
Business logic Audit finding Intermediate

StaticATokenLM transfer missing _updateRewards

The StaticATokenLM contract's transfer and transferFrom functions do not call _updateRewards() before changing balances, so the sender's accrued rewards are not updated and may be transferred to the recipient. An attacker could exploit this to cause a loss of rewards for the sender.

bin2chen Follow

Originally disclosed on Code4rena

Submitted by bin2chen

Transfer missing _updateRewards(), resulting in the loss of from’s reward.

Proof of Concept

StaticATokenLM contains the rewards mechanism, when the balance changes, the global _accRewardsPerToken needs to be updated first to calculate the user’s rewardsAccrued more accurately.

Example: mint()/burn() both call _updateRewards() to update _accRewardsPerToken.

    function _deposit(
        address depositor,
        address recipient,
        uint256 amount,
        uint16 referralCode,
        bool fromUnderlying
    ) internal returns (uint256) {
        require(recipient != address(0), StaticATokenErrors.INVALID_RECIPIENT);
@>      _updateRewards();

...

        _mint(recipient, amountToMint);

        return amountToMint;
    }

    function _withdraw(
        address owner,
        address recipient,
        uint256 staticAmount,
        uint256 dynamicAmount,
        bool toUnderlying
    ) internal returns (uint256, uint256) {
...
@>      _updateRewards();

...
@>      _burn(owner, amountToBurn);

...
    }

When transfer()/transerFrom(), the balance is also modified, but without calling _updateRewards() first. The result is that if the user transfers the balance, the difference in rewards accrued by from is transferred to to along with it. This doesn’t make sense for from.

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256
    ) internal override {
        if (address(INCENTIVES_CONTROLLER) == address(0)) {
            return;
        }
        if (from != address(0)) {
            _updateUser(from);
        }
        if (to != address(0)) {
            _updateUser(to);
        }
    }

Recommended Mitigation Steps

_beforeTokenTransfer first trigger _updateRewards().

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256
    ) internal override {
        if (address(INCENTIVES_CONTROLLER) == address(0)) {
            return;
        }
+       _updateRewards();
        if (from != address(0)) {
            _updateUser(from);
        }
        if (to != address(0)) {
            _updateUser(to);
        }
    }

Assessed type

Context

tbrent (Reserve) commented:

We will be reaching out to the Aave team to understand more about this. It seems there are multiple places in StaticATokenLM where reward steps are missing, and there may be reasons why.

julianmrodri (Reserve) commented:

We will mark this issue as Sponsor Acknowledged. It is true the situation described by the warden and that’s the behavior we observe. However we will not be implementing any change in the code (besides adding some comments) for the following reasons:

  • We do not expect rewards in Aave V2 to come back.
  • We checked with Aave and we believe the original reason for building it this way still holds, and that is for gas purposes. Even if for some reason rewards on AAve V2 come back the cost of updating the user rewards on every transfer outweighs the rewards that may be left “uncollected” after a transfer operation. It is important to remark that any deposit or withdraw done to the contract plus any call to collectRewards.., and any claim of rewards from the Reserve protocol, would setup the correct balances. So while it is true that transfers may in some cases not transfer rewards we expect this to only be slightly off.

To clarify this issue for users we will add a comment to the wrapper contract StaticATokenLM to clarify the situation with how rewards are handled on transfer.

tbrent (Reserve) acknowledged


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 _beforeTokenTransfer hook updates user rewards but does not update the global reward accumulator before balances change.

Impact

The sender may lose accrued rewards when transferring tokens, though the sponsor considers the impact slight and notes that deposits, withdrawals, and reward collections correct the balances.

What the attacker needed

User holds StaticATokenLM tokens; rewards are active

The fix

The recommended mitigation is to call _updateRewards() at the start of _beforeTokenTransfer, but the sponsor chose not to implement it and only added comments.

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.

This is a smart contract that tracks rewards for users. When you transfer tokens, the contract should first update how many rewards you have earned so far. Because it does not, the sender may lose some rewards that get passed to the receiver.

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 Reserve Core

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.