Skip to content
Smart contracts Audit finding Intermediate

Public vault slope can overflow

The slope value in the public vault can overflow due to unchecked addition in the afterPayment function, leading to incorrect totalAssets. This can also cause underflows in slope updates elsewhere, resulting in large fluctuations in slope and totalAssets.

evan Follow

Originally disclosed on Code4rena

Submitted by evan

https://github.com/code-423n4/2023-01-astaria/blob/main/src/PublicVault.sol#L562-L568 https://github.com/code-423n4/2023-01-astaria/blob/57c2fe33c1d57bc2814bfd23592417fc4d5bf7de/src/LienToken.sol#L702-L704

The slope of public vault can overflow in the afterPayment function due to unchecked addition. When this happens, totalAssets will not be correct. This can also result in underflows in slope updates elsewhere, causing large fluctuations in slope and totalAssets.

Proof of Concept

Assume the token is a normal 18 decimal ERC20 token. After 5 loans of 1000 tokens, all with the maximum interest rate of 63419583966, the slope will overflow. 5 * 1000 * 63419583966 / 2^48 = 1.1265581173

Tools Used

VSCode

Recommended Mitigation Steps

Remove the unchecked block. Also, I think 48 bits might not be enough for slope.

SantiagoGregory (Astaria) confirmed


The original report as published on Code4rena, by evan. 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 use of an unchecked block around an addition that can overflow, combined with a 48-bit storage type that may be too small for the slope value.

Impact

The overflow causes totalAssets to be incorrect and can lead to underflows in slope updates, causing large fluctuations in slope and totalAssets.

What the attacker needed

Multiple loans with high interest rate

The fix

Remove the unchecked block and consider using a larger type than 48 bits for slope.

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 stores a number called 'slope' that tracks how fast interest accumulates. Because the code adds to this number without checking for overflow, it can wrap around to a very small value, making the contract's accounting wrong. This could let someone manipulate the vault's reported assets.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by evan

View all

11 more disclosed reports, best first.

More from Astaria contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.