Skip to content
Audit finding Advanced

Important state updates are made after the callback in the mint() function

The mint() function in TimeswapPair.sol performs a callback before updating critical state variables (reserve asset, collateral, totalDebtCreated), violating the checks-effects-interactions pattern. An attacker could exploit cross-function reentrancy to manipulate the contract's state during the callback, potentially leading to unintended behaviour or loss of funds.

jayjonah8 Follow

Originally disclosed on Code4rena

Submitted by jayjonah8

In TimeswapPair.sol, the mint() function has a callback in the middle of the function while there are still updates to state that take place after the callback. The lock modifier guards against reentrancy but not against cross function reentrancy. Since the protocol implements Uniswap like functionality, this can be extremely dangerous especially with regard to composability/interacting with other protocols and contracts. The callback before important state changes (updates to reserve asset, collateral, and totalDebtCreated) also violates the Checks Effects Interactions best practices further widening the attack surface.

Proof of Concept

Recommended Mitigation Steps

The callback Callback.mint(asset, collateral, xIncrease, dueOut.collateral, data) should be placed at the end of the mint() function after all state updates have taken place.

Mathepreneur (Timeswap) confirmed and resolved:

https://github.com/Timeswap-Labs/Timeswap-V1-Core/pull/107

The original report as published on Code4rena, by jayjonah8. 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 mint() function performs an external callback before completing its state updates, violating the checks-effects-interactions pattern and enabling cross-function reentrancy.

Impact

An attacker could exploit cross-function reentrancy to manipulate the contract's state during the callback, potentially causing unintended behaviour or loss of funds, though the report does not demonstrate a concrete exploit.

What the attacker needed

None

The fix

The callback should be moved to the end of the mint() function after all state updates have taken place.

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 smart contracts, a callback is when the contract calls out to another contract, which can then call back into the original contract before the first call finishes. If the original contract hasn't finished updating its records, the re-entrant call can see or change inconsistent data. This report says the mint function makes such a callback too early, which could let an attacker interfere with the contract's internal accounting.

More by jayjonah8

View all

18 more disclosed reports, best first.

More from Timeswap contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.