estimatedAPR() might return the wrong APR
The estimatedAPR() function in SavingsVest returns a stale APR after the vesting period ends because it uses the stored vestingProfit without checking whether any profit remains locked. Users could see an incorrect, non-zero APR when the true APR should be zero.
Originally disclosed on Code4rena
Submitted by auditor0517
estimatedAPR() might return the wrong APR and it will make users confused.
Proof of Concept
SavingsVest.estimatedAPR() returns the APR using the current vestingProfit and vestingPeriod.
function estimatedAPR() external view returns (uint256 apr) {
uint256 currentlyVestingProfit = vestingProfit;
uint256 weightedAssets = vestingPeriod * totalAssets();
if (currentlyVestingProfit != 0 && weightedAssets != 0)
apr = (currentlyVestingProfit * 3600 * 24 * 365 * BASE_18) / weightedAssets;
}
First of all, it uses the current vestingRatio = vestingProfit / vestingPeriod for 1 year even if vestingPeriod < 1 year. I think it might be an intended behavior to estimate the APR with the current vesting ratio.
But it’s wrong to use the same vesting ratio after the vesting period is finished already.
In accrue(), it updates the vestingProfit and lastUpdate only when it’s overcollateralized/undercollateralized more than 0.1%.
So lastUpdate wouldn’t be changed for a certain time while collatRatio is in range (99.9%, 100.1%).
- At the first time,
vestingProfit = 100, vestingPeriod = 10 daysandestimatedAPR()returns the correct value. - After 10 days, all vestings are unlocked and there is no locked profit. But
accrue()has never been called due to the stable collateral ratio. - In
estimatedAPR(),vestingProfitwill be 100 and it will return the same APR as 10 days before. - But the APR should be 0 as there is no locked profit now.
Recommended Mitigation Steps
estimatedAPR() should return 0 when lockedProfit() == 0.
function estimatedAPR() external view returns (uint256 apr) {
if (lockedProfit() == 0) return 0; //check locked profit first
uint256 currentlyVestingProfit = vestingProfit;
uint256 weightedAssets = vestingPeriod * totalAssets();
if (currentlyVestingProfit != 0 && weightedAssets != 0)
apr = (currentlyVestingProfit * 3600 * 24 * 365 * BASE_18) / weightedAssets;
}
Picodes (Angle) confirmed and commented:
Valid, although this function isn’t really useful as what matters in the end is how much a call to
accruewould give.estimatedAPRshould return an approximation of the current APR but is an approximation on the long run
@Picodes - It looks like a middle of Medium and Low as it’s a view function. Will keep as Medium because it will be used to estimate the profit rate for users.
PR: https://github.com/AngleProtocol/angle-transmuter/commit/337c65d005bbd8ed6dfa76929d2cae475066756a Applies the suggested fix.
Status: Mitigation confirmed. Full details in reports from auditor0517 and Jeiwan.
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 estimatedAPR() function does not check whether lockedProfit() is zero before calculating the APR from the stored vestingProfit.
Impact
Users could be shown an incorrect, non-zero APR after the vesting period has ended, which may confuse them about the actual profit rate.
What the attacker needed
VestingPeriod has elapsed; collateral ratio stays within 99.9%–100.1%; accrue() not called
The fix
The function was fixed by returning zero when lockedProfit() is zero, as confirmed by the mitigation.
How it was found
- Set vestingProfit to 100 and vestingPeriod to 10 days; estimatedAPR() returns the correct value.
- After 10 days all vestings are unlocked and there is no locked profit, but accrue() has not been called because the collateral ratio stayed stable.
- estimatedAPR() still uses vestingProfit = 100 and returns the same APR as before.
- The APR should be 0 because there is no locked profit now.
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 reports an annual percentage rate (APR) to show how much interest users might earn. The contract only updates its internal profit figure when the collateral ratio moves outside a narrow band, so after the profit has fully vested the stored figure can remain out of date. The function then keeps showing the old APR instead of zero, which could mislead 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.