Skip to content
Business logic Audit finding Intermediate

Debt accrual is path-dependant and inaccurate

The total debt in the vault is updated by subtracting only the calling user's discounted debt, making the total debt path-dependent on which user triggers the accrual. An attacker could exploit this to cause the total debt to be lower or higher than it should be, potentially leading to incorrect interest calculations and financial discrepancies.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The total debt in MochiVault.accrueDebt increases by the current debt times the debt index growth. This is correct but the total debt is then reduced again by the calling user’s discounted debt, meaning, the total debt depends on which specific user performs the debt accrual.

This should not be the case.

POC

Assume we have a total debt of 2000, two users A and B, where A has a debt of 1000, and B has a debt of 100. The (previous) debtIndex = 1.0 and accruing it now would increase it to 1.1.

There’s a difference if user A or B first does the accrual.

User A accrues first

User A calls accrueDebt: increased = 2000 * 1.1/1.0 - 2000 = 200. Thus debts is first set to 2200. The user’s increasedDebt = 1000 * 1.1 / 1.0 - 1000 = 100 and assume a discount of 10%, thus discountedDebt = 100 * 10% = 10. Then debts = 2200 - 10 = 2190.

The next accrual will work with a total debt of 2190.

User B accruess first

User B calls accrueDebt: increased = 2000 * 1.1/1.0 - 2000 = 200. Thus debts is first set to 2200. The user’s increasedDebt = 100 * 1.1 / 1.0 - 100 = 10 and assume a discount of 10%, thus discountedDebt = 10 * 10% = 1. Then debts = 2200 - 1 = 2199.

The next accrual will work with a total debt of 2199, leading to more debt overall.

Impact

The total debt of a system depends on who performs the accruals which should ideally not be the case. The discrepancy compounds and can grow quite large if a whale always does the accrual compared to someone with almost no debt or no discount.

Recommended Mitigation Steps

Don’t use the discounts or track the weighted average discount across all users that is subtracted from the increased total debt each time, i.e., reduce it by the discount of all users (instead of current caller only) when accruing to correctly track the debt.

ryuheimat (Mochi) confirmed

The original report as published on Code4rena, by cmichel. 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 accrueDebt function subtracts the caller's discounted debt from the total debt instead of accounting for all users' discounts, making the total debt dependent on the caller.

Impact

The total debt of the system depends on who performs the accruals, and the discrepancy compounds and can grow quite large if a whale always does the accrual compared to someone with almost no debt or no discount.

What the attacker needed

Users with debt and discounts; ability to call accrueDebt

The fix

The total debt should be reduced by the discount of all users (or the weighted average discount) instead of only the caller's discount.

How it was found

  1. User A calls accrueDebt, increasing total debt by 200 and then subtracting A's discounted debt of 10, resulting in total debt 2190.
  2. User B calls accrueDebt, increasing total debt by 200 and then subtracting B's discounted debt of 1, resulting in total debt 2199.

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.

In a lending system, the total amount owed by all users should increase by a fixed percentage over time. But here, when a user triggers an update, the system subtracts a discount that only applies to that user from the total. So the total ends up different depending on who triggers the update, which is unfair and can be abused.

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 cmichel

View all

196 more disclosed reports, best first.

More from Mochi 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.