Skip to content
DoS Audit finding Intermediate

DOS pay function

The pay() function subtracts the amount paid from the user's recorded debt, and the contract uses Solidity 0.8 or later, so any subtraction that goes below zero reverts. An attacker can front-run a user who is repaying their full debt by paying a tiny amount toward that user's debt first, which makes the user's payment exceed the remaining debt and causes the transaction to revert.

egjlmn1 Follow

Originally disclosed on Code4rena

Submitted by egjlmn1

in the pay() function users repay their debt and in line 364: https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L364 it decreases their debt.

lets say a user wants to repay all his debt, he calls the pay() function with his full debt. an attacker can see it and frontrun to repay a single token for his debt (since it’s likely the token uses 18 decimals, a single token is worth almost nothing) and since your solidity version is above 0.8.0 the line: due.debt -= assetsIn[i]; will revert due to underflow

The attacker can keep doing it everytime the user is going to pay and since 1 token is baisicly 0$ (18 decimals) the attacker doesn’t lose real money

Impact

A DoS on every user that repay his full debt (or enough that the difference between his total debt to what he pays his negligible)

Proof of Concept

From solidity docs

Since Solidity 0.8.0, all arithmetic operations revert on over- and underflow by default, thus making the use of these libraries unnecessary.

Recommended Mitigation Steps

if assetsIn[i] is bigger than due.debt set assetsIn[i]=due.debt and due.debt=0

Mathepreneur (Timeswap) acknowledged:

The convenience contract will implement how much asset to pay in.

The original report as published on Code4rena, by egjlmn1. 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 pay() function subtracts the paid amount from the debt without capping it at the outstanding debt, so an overpayment underflows and reverts under Solidity 0.8 checked arithmetic.

Impact

Every user repaying their full debt, or an amount close enough that the difference is negligible, can be blocked from completing the payment, and the attacker loses almost nothing because one token with 18 decimals is worth very little.

What the attacker needed

Attacker can front-run transactions; victim repays full or near-full debt; attacker pays a tiny amount first

The fix

The contract should cap the amount applied at the outstanding debt, setting the debt to zero when the payment is larger, as the report recommends.

How it was found

  1. A user calls pay() with an amount equal to their full debt.
  2. An attacker sees the pending transaction and front-runs it by repaying a single token toward that user's debt.
  3. The user's transaction then subtracts more than the remaining debt and reverts due to underflow.

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 keeps a record of how much each person owes. When someone pays, the contract subtracts the payment from that record. If the payment is larger than the recorded debt, the subtraction goes negative and the contract refuses to run the transaction at all. An attacker can make a tiny payment on the victim's behalf just before the victim's payment, so the victim's own payment is now too large and always fails.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by egjlmn1

View all

2 more disclosed reports, best first.

More from Timeswap contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.