Skip to content
Business logic Audit finding Intermediate

Adversary can abuse hanging approvals left by PSwapLib.swap to bypass reward fees

The AuraSpell and ConvexSpell contracts allow users to specify arbitrary expectedRewards and swap data, enabling them to leave large token approvals hanging. An attacker could then swap reward tokens in a different order to bypass reward fees.

0x52 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-07-blueberry-judging/issues/104

Found by

0x52

PSwapLib.swap can be manipulated to leave hanging allowances via the expectedRewards input. These can then be abused to swap reward tokens out of order allowing them to bypass fees.

Vulnerability Detail

AuraSpell.sol#L247-L257

        _doCutRewardsFee(sellToken);
        if (
            expectedRewards[i] != 0 &&
            !PSwapLib.swap(
                augustusSwapper,
                tokenTransferProxy,
                sellToken,
                expectedRewards[i],
                swapDatas[i]
            )
        ) revert Errors.SWAP_FAILED(sellToken);

AuraSpell#closePositionFarm allows the user to specify any expectedRewards they wish. This allows the user to approve any amount, even if the amount is much larger than they would otherwise use. The can abuse these hanging approvals to swap tokens out of order and avoid paying reward fees.

Example: Assume there are two rewards, token A and token B. Over time a user's position accumulates 100 rewards for each token. Normally the user would have to pay fees on those rewards. However they can bypass it by first creating hanging approvals. The user would start by redeeming a very small amount of LP and setting expectedRewards to uint256.max. They wouldn't sell the small amount leaving a very large approval left for both tokens. Now the user withdraws the rest of their position. This time they specify the swap data to swap token B first. The user still has to pay fees on token A but now they have traded token B before any fees can be taken on it.

Impact

User can bypass reward fees

Code Snippet

AuraSpell.sol#L184-L286

ConvexSpell.sol#L179-L229

Tool used

Manual Review

Recommendation

After the swap reset allowances to 0

Discussion

sherlock-admin2

2 comment(s) were left on this issue during the judging contest.

0xyPhilic commented:

invalid because fees are cut before the supplied check in _doCutFees function

Kral01 commented:

Not how approval works

IAm0x52

Escalate

This was wrongly excluded. The judging comments above are incorrect. The code allows the user to make any swap in whatever order they want. This is what allows the user to bypass the fees. The user is meant to swap in the order that the tokens are listed but by swapping in a different order they can bypass the cut. Assume we have two tokens to claim. Normally the flow would be:

RewardCut A > Swap A > RewardCut B > Swap B

Using the methodology I've shown above the user can instead:

RewardCut A > Swap B > RewardCutB > Swap A

Here we see that B can be swapped before the reward cut allowing the fee to be bypassed.

sherlock-admin2

Escalate

This was wrongly excluded. The judging comments above are incorrect. The code allows the user to make any swap in whatever order they want. This is what allows the user to bypass the fees. The user is meant to swap in the order that the tokens are listed but by swapping in a different order they can bypass the cut. Assume we have two tokens to claim. Normally the flow would be:

RewardCut A > Swap A > RewardCut B > Swap B

Using the methodology I've shown above the user can instead:

RewardCut A > Swap B > RewardCutB > Swap A

Here we see that B can be swapped before the reward cut allowing the fee to be bypassed.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

Shogoki

Escalate

This was wrongly excluded. The judging comments above are incorrect. The code allows the user to make any swap in whatever order they want. This is what allows the user to bypass the fees. The user is meant to swap in the order that the tokens are listed but by swapping in a different order they can bypass the cut. Assume we have two tokens to claim. Normally the flow would be:

RewardCut A > Swap A > RewardCut B > Swap B

Using the methodology I've shown above the user can instead:

RewardCut A > Swap B > RewardCutB > Swap A

Here we see that B can be swapped before the reward cut allowing the fee to be bypassed.

Agree with escalation. As the user can specify any expectedRewards and any callData in any order, this is a valid attack vector.

hrishibhat

@Gornutz

Gornutz

The paraswap lib is already resetting the token approval to zero prior to allocating the allowance for each swap - https://github.com/sherlock-audit/2023-07-blueberry/blob/7c7e1c4a8f3012d1afd2e598b656010bb9127836/blueberry-core/contracts/libraries/Paraswap/PSwapLib.sol#L15

Shogoki

The paraswap lib is already resetting the token approval to zero prior to allocating the allowance for each swap - https://github.com/sherlock-audit/2023-07-blueberry/blob/7c7e1c4a8f3012d1afd2e598b656010bb9127836/blueberry-core/contracts/libraries/Paraswap/PSwapLib.sol#L15

I do not think this helps preventing this issue. As the approval is resetted before the swap, there still can be a hanging approval. Issue is that the approval is set/reset for the specified sellToken, but the user can swap any other token by specifying different calldatas. Therefore, i think the stated attack path is still possible

Gornutz

Gotcha, then yes seems valid

hrishibhat

Result: Medium Unique This is a valid medium issue

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

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

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 does not reset token allowances after swaps and allows the user to control the order of swaps, so a large approval can be used to swap a token before its fee is deducted.

Impact

A user could bypass reward fees on some tokens.

What the attacker needed

A farming position with reward tokens; ability to call closePositionFarm with custom parameters

The fix

The contract should reset allowances to zero after each swap.

How it was found

  1. Redeem a very small amount of LP and set expectedRewards to uint256.max, but do not sell the small amount, leaving a large approval for both tokens.
  2. Withdraw the rest of the position and specify swap data to swap token B first.
  3. Token B is swapped before any fee is taken on it, bypassing the reward fee for token B.

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.

When you close a farming position, the contract takes a fee from your reward tokens before swapping them. The contract lets you choose how much of each token to swap and in what order. By first setting a huge approval and not swapping, you leave a large allowance. Later, you can swap a token before the fee is taken on it, avoiding the fee.

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 0x52

View all

211 more disclosed reports, best first.

More from Blueberry Update #3

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.