Skip to content
Business logic Audit finding Intermediate

Loans of tokens with >18 decimals can result in incorrect collateral calculation

The collateral calculation in a lending protocol incorrectly assumes collateral tokens have at most 18 decimals, so a token with more decimals causes the required collateral to be computed as zero. An attacker could then take a loan with no collateral and default, leaving the pool with a loss.

Maple Finance contest

Originally disclosed on Code4rena

It is possible for a user to mislead a Pool Delegate to a seemingly innocuous loan by utilizing a token with more than 18 decimals as collateral and lucrative loan terms.

The final calculation within the collateralRequiredForDrawdown of LoanLib incorrectly assumes the collateral token of a loan to be less than 18 decimals, which can not be the case as there is no sanitization conducted on the creation of a Loan via the factory. This can cause an underflow to the power of 10 which will cause the division to yield 0 and thus cause the Loan to calculate 0 as collateral required for the loan. We advise the same paradigm as _toWad to be applied, which is secure.

lucas-manuel (Maple) acknowledged:

We are aware that we cannot onboard liquidityAssets or collateralAssets with more that 18 decimals of precision, and will make that part of our onboarding criteria.

Nick Johnson (Judge):

This is 100% a legitimate issue that could be exploited against the contract, and using social mitigations (making this part of the onboarding strategy) when there’s a technical mitigation (require()ing that the token have <= 18 decimals, or using the recommended mitigation) is insufficient and could easily lead to an exploit due to human error.

Based on the OWASP methodogology, I’m judging this as Likelihood=Low (because of the requirement to get it past human review) and Impact=High (because of the impact of the bug if it were exploited to create a 0-collateral loan and default on it), resulting in a Severity of Medium.

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

The collateral calculation divides by a power of ten based on the token's decimals without checking that the token has at most 18 decimals, causing an underflow when it has more.

Impact

An attacker could create a loan with zero required collateral and default on it, causing a loss to the pool; the judge rated likelihood low because the token must pass human review, but impact high.

What the attacker needed

A collateral token with more than 18 decimals; the token passes the pool's onboarding review

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 lending pool lets people borrow tokens if they put up other tokens as collateral. The code that works out how much collateral is needed assumes the collateral token has at most 18 decimal places. If a token has more, the maths breaks and the required collateral becomes zero, so someone could borrow without putting anything up and never pay it back.

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 from Maple Finance contest

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.