Skip to content
Business logic Audit finding Intermediate

Scores.sol: Incorrect computation of user’s score when alpha is 1

The score calculation for a staked user returns zero whenever either the staked XVS balance or the supplied capital is zero, even when the alpha weighting parameter is set to 1. This means a user who only stakes XVS and supplies no capital would incorrectly receive a score of zero instead of the full staking-based score.

Testerbot Follow

Originally disclosed on Code4rena

Submitted by Testerbot

The formula for a user’s score depends on the xvs staked and the capital. One core variable in the calculation of a user’s score is alpha which represents the weight for xvs and capital. It has been stated in the documentation that alpha can range from 0 to 1 depending on what kind of incentive the protocol wants to drive (XVS Staking or supply/borrow). Please review Significance of α subsection.

When alpha is 1, xvs has all the weight when calculating a user’s score, and capital has no weight. If we see the Cobb-Douglas function, the value of capital doesn’t matter, it will always return 1 since capital^0 is always 1. So, a user does not need to borrow or lend in a given market since capital does not have any weight in the score calculation.

The issue is an inconsistency in the implementation of the Cobb-Douglas function.

Developers have added an exception: if (xvs == 0 || capital == 0) return 0; Because of this the code will always return 0 if either the xvs or the capital is zero, but we know this should not be the case when the alpha value is 1.

PoC

To check how it works:

In describe('boosted yield') add the following code:

it.only("calculate score only staking", async () => {
      const xvsBalance = bigNumber18.mul(5000);
      const capital = bigNumber18.mul(0);

      await prime.updateAlpha(1, 1); // 1

      //  5000^1 * 0^0 = 5000
      // BUT IS RETURNING 0!!!
      expect((await prime.calculateScore(xvsBalance, capital)).toString()).to.be.equal("0");
});

Recommended Mitigation Steps

Only return 0 when (xvs = 0 or capital = 0) * and alpha is not 1.

chechu (Venus) confirmed and commented:

Fixed here. (Alpha cannot be 0 or 1 anymore)

0xDjango (Judge) commented:

I agree with Medium severity. In the case where Venus decides to make XVS staking the sole factor in user score, this function should calculate correctly. Also given that the documentation specifically states “The value of α is between 0-1”.


The original report as published on Code4rena, by Testerbot. 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 an early-return guard that treats a zero capital or zero XVS balance as always producing a zero score, without accounting for the alpha exponent making the other term irrelevant.

Impact

A user who only stakes XVS could receive a zero score and therefore no rewards when the protocol intends staking alone to count.

What the attacker needed

Alpha set to 1; user stakes XVS but supplies no capital

The fix

The guard should only return zero when either value is zero and alpha is not 1; the project fixed it by disallowing alpha values of 0 or 1.

How it was found

  1. Set alpha to 1 in the contract.
  2. Call the score calculation with a non-zero XVS balance and a zero capital value.
  3. Observe that the returned score is zero instead of the expected staking-only value.

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 protocol gives users a score based on how much they stake and how much they lend or borrow. A setting called alpha decides how much each part counts. When alpha is 1, only staking should matter, but the code still returns zero if the user has not lent or borrowed anything, so their score is wrongly wiped out.

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 Testerbot

View all

2 more disclosed reports, best first.

More from Venus Prime

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.