Skip to content
Business logic Audit finding Intermediate

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.

auditor0517 Follow

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%).

  1. At the first time, vestingProfit = 100, vestingPeriod = 10 days and estimatedAPR() returns the correct value.
  2. 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.
  3. In estimatedAPR(), vestingProfit will be 100 and it will return the same APR as 10 days before.
  4. 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 accrue would give. estimatedAPR should return an approximation of the current APR but is an approximation on the long run

hansfriese (Judge) commented:

@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.

Angle mitigated:

PR: https://github.com/AngleProtocol/angle-transmuter/commit/337c65d005bbd8ed6dfa76929d2cae475066756a Applies the suggested fix.

Status: Mitigation confirmed. Full details in reports from auditor0517 and Jeiwan.


The original report as published on Code4rena, by auditor0517. 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 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

  1. Set vestingProfit to 100 and vestingPeriod to 10 days; estimatedAPR() returns the correct value.
  2. 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.
  3. estimatedAPR() still uses vestingProfit = 100 and returns the same APR as before.
  4. 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.

More by auditor0517

View all

11 more disclosed reports, best first.

More from Angle Protocol - Invitational

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.