Skip to content
Smart contracts Audit finding Advanced

In the lend() function state updates are made after the callback

The lend() function in TimeswapPair.sol makes an external callback to the caller before updating key state variables such as totalClaims, bonds, insurance and reserves. This violates the checks-effects-interactions pattern and could allow cross-function reentrancy, potentially enabling an attacker to exploit the protocol's composability with other contracts.

jayjonah8 Follow

Originally disclosed on Code4rena

Submitted by jayjonah8

In TimeswapPair.sol, the lend() function has a callback to the msg.sender 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 totalClaims bonds, insurance and reserves assets) also violates the Checks Effects Interactions best practices further widening the attack surface.

Proof of Concept

Recommended Mitigation Steps

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

Mathepreneur (Timeswap) confirmed and resolved:

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

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

Impact

The report claims this could be extremely dangerous for composability and interaction with other protocols, but it does not demonstrate a concrete exploit or loss.

What the attacker needed

Protocol interacts with external contracts

The fix

The callback should be moved to the end of the lend() function after all state updates have taken place; the project confirmed and resolved the issue.

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 can call another contract in the middle of its own work. If it does that before finishing its own record-keeping, the other contract can call back in and see or use outdated information. This report says the lend function does exactly that, which could let someone interfere with the protocol's accounting.

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 jayjonah8

View all

18 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.

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.