Skip to content
Business logic Audit finding Intermediate

`_protocolFees` can be applied multiple times in `AutoCompoundingPodLp` contract

The protocol fee is charged twice on the same reward tokens when a swap from the paired LP token to the pod and staking pool token fails, leaving the tokens in the contract. An attacker could trigger this failure to cause users to lose rewards to excessive fees.

X77 Follow with ZoA, pashap9990 and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/157

Found by

X77, ZoA, pashap9990, pkqs90

Summary

In the _processRewardsToPodLp function, the reward token is swapped to PAIRED_LP_TOKEN, and then some of it is paid as _protocolFees. The remaining PAIRED_LP_TOKEN is swapped to pod and StakingPoolToken. However, if this swap fails, PAIRED_LP_TOKEN remains in the contract as it is. PAIRED_LP_TOKEN can also be reward token, and in case of PAIRED_LP_TOKEN, the same operation is done for balanceOf(PAIRED_LP_TOKEN) - _protocolFees. If the previous reward token is swapped to PAIRED_LP_TOKEN and then the swap to pod and StakingPoolToken fails, the remaining token amount is included in balanceOf(PAIRED_LP_TOKEN), and _protocolFees is paid again for this amount..

Root Cause

If the swap from PAIRED_LP_TOKEN to pod and StakingPoolToken fails, PAIRED_LP_TOKEN remains in the contract as it is. (let's call this swapFaildAmount)

In case of PAIRED_LP_TOKEN, the swapFaildAmount is included to IERC20(_token).balanceOf(address(this)) and IERC20(_token).balanceOf(address(this)) - _protocolFees is swapped to PodLp while paying protocol fee for swapFaildAmount again. This means that the protocol fee is paid twice for the previous reward token.

For PAIRED_LP_TOKEN, if the swap to pod and StakingPoolToken also fails, the protocol fee will be applied again next time.

Internal Pre-conditions

swap from PAIRED_LP_TOKEN to pod fails

External Pre-conditions

No response

Attack Path

No response

Impact

The protocol fee can be paid multiple times, reducing the reward for users.

PoC

RewardsTokens = [PAIRED_LP_TOKEN, dai, lpRewardsToken]

  1. In prev call of _processRewardsToPodLp function:

lpRewardsToken is swapped to 50 of PAIRED_LP_TOKEN, and 5 is paid for protocol fee. Total protocol fee increases from 0 to 5. And then the rest 45 of PAIRED_LP_TOKEN is used for swap to Pod but this swap failed. swapFaildAmount = 45, balance of PAIRED_LP_TOKEN = 45, _protocolFee = 5 2. 40 of PAIRED_LP_TOKEN is distributed to AutoCompoundingPodLp contract and the balance of PAIRED_LP_TOKEN is increased to 85 from 45. 3. In next call of _processRewardsToPodLp function:

80(=85-_protocolFee) of PAIRED_LP_TOKEN is used for swap and protocol fee is also paid for the swapFaildAmount.

This means for previous lpRewardsToken with same worth of 50 PAIRED_LP_TOKEN, total paid fee is 50 / 10 + 45 / 10 = 9.5. To be correct, the fee should be paid only for the newly distributed PAIRED_LP_TOKEN of 40.

Mitigation

The protocol fee must be paid only if the swap to PodLp is successful. Or keep track of the amount of PAIRED_LP_TOKEN remaining in the contract if the swap fails.

The original report as published on Sherlock, by X77. 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 track which tokens have already had the protocol fee deducted, so leftover paired LP tokens from a failed swap are counted again in the balance and charged the fee a second time.

Impact

The protocol fee can be paid multiple times, reducing the reward for users.

What the attacker needed

Swap from PAIRED_LP_TOKEN to pod fails

The fix

The protocol fee should be paid only if the swap to PodLp is successful, or the contract should track the amount of PAIRED_LP_TOKEN remaining after a failed swap.

How it was found

  1. In a previous call, a reward token is swapped to the paired LP token and a protocol fee is taken.
  2. The remaining paired LP token is meant to be swapped to the pod and staking pool token, but that swap fails, leaving the tokens in the contract.
  3. More paired LP tokens are later distributed to the contract, increasing its balance.
  4. In the next call, the contract uses the entire balance minus the fee for swapping, effectively charging the protocol fee again on the leftover amount.

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 the contract processes rewards, it takes a small cut as a fee before swapping the rest. If a later swap fails, the leftover tokens stay in the contract. On the next run, the contract mistakenly charges the fee again on those leftovers, so users get less reward than they should.

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 X77

View all

6 more disclosed reports, best first.

More from Peapods

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.