Skip to content
Business logic Audit finding Intermediate

borrowRateMaxMantissa should be specific to the chain protocol is being deployed to

The maximum borrow rate constant is fixed for all chains, so on chains with shorter block times the effective annual maximum borrow rate becomes extremely high. An attacker could exploit this to borrow at an absurd rate if utilisation spikes, potentially causing protocol failure.

kankodu Follow with cryptonue

Originally disclosed on Code4rena

Submitted by kankodu, also found by cryptonue

https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/MTokenInterfaces.sol#L23

https://github.com/code-423n4/2023-07-moonwell/blob/fced18035107a345c31c9a9497d0da09105df4df/src/core/MToken.sol#L403

  • The purpose of borrowRateMaxMantissa is to put the protocol in failure mode when absurd utilisation makes borrowRate absurd. It is defined as a constant for all the chains. It should really be changed according to average blocktime of the chain the protocol is being deployed to.
  • borrowRateMaxMantissa = 0.0005e16 translates to maximum borrow rate of .0005% / block.
  • For Ethereum chain that has 12 seconds of average block time, this translates to maximum borrow rate of 0.0005% * (365 * 24 * 3600)/12 = 1314. For BNB with 3 seconds of average block time it is 0.0005% * (365 * 24 * 3600)/3 = 5256%. For fantom with 1 second of average block time it is 0.0005% * (365 * 24 * 3600)/1 = 15768%.

Proof of Concept

https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/MTokenInterfaces.sol#L23

https://github.com/code-423n4/2023-07-moonwell/blob/fced18035107a345c31c9a9497d0da09105df4df/src/core/MToken.sol#L403

Recommended Mitigation Steps

  • Decide on a maximum borrow rate protocol is ok with (my suggestion is ~1000%) and change borrowRateMaxMantissa according to what chain it is being deployed to.

ElliotFriedman (Moonwell) acknowledged and commented:

Agreed this could be configured on a per chain basis, however this is legacy code that we don’t want to change. This instance is only being deployed on base, so maybe instead of making it configurable, this value could be adjusted downwards.


The original report as published on Code4rena, by kankodu. 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 maximum borrow rate constant was not adjusted for the average block time of the deployment chain, so the per-block cap translates to an excessive annual rate on faster chains.

Impact

On chains with short block times, the maximum annual borrow rate could reach thousands of percent, potentially putting the protocol in failure mode if utilisation becomes absurd.

What the attacker needed

Protocol deployed on a fast-block chain; utilisation becomes absurd

The fix

The value should be adjusted downwards or made configurable per chain to target a reasonable maximum annual borrow rate.

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 sets a cap on how fast interest can grow per block. Because different blockchains produce blocks at different speeds, the same per-block cap means a much higher yearly interest rate on faster chains. This could let someone borrow at a rate so high it breaks the protocol's economics.

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 kankodu

View all

5 more disclosed reports, best first.

More from Moonwell

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.