Skip to content
Business logic Audit finding Intermediate

block.timestamp or deadline

Some functions use block.timestamp as the deadline for token swaps instead of the deadline field provided in the input struct. An attacker could exploit this by delaying transactions to get unfavourable swap rates, as the deadline check is ineffective.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon, also found by kenzo and robee

Impact

Some functions, like rebalance() in RebalanceManagerV3 use _deadline as a time limit for swapExactTokensForTokens() Other functions, like _joinTokenSingle() of SingleTokenJoinV2.sol and _exit() of SingleNativeTokenExitV2() use block.timestamp, although a deadline field is present in the struct.

Possibly the deadline fields should have been used.

Proof of Concept

RebalanceManagerV3.sol L158-L203

function rebalance(UnderlyingTrade[] calldata _swapsV2, uint256 _deadline)  external override onlyRebalanceManager {
...
        for (uint256 i; i < _swapsV2.length; i++) {
  ...
            for (uint256 j; j < trade.swaps.length; j++) {
                ..
                _swapUniswapV2(swap.exchange,input,0, swap.path,address(basket), _deadline );

RebalanceManagerV3.sol L63-L104

function _swapUniswapV2(...) {
        basket.singleCall(
            exchange,
            abi.encodeWithSelector(  IUniswapV2Router02(exchange).swapExactTokensForTokens.selector,  quantity,   minReturn,  path, recipient, deadline  ),
            0
        );

SingleTokenJoinV2.sol L80-L112

struct JoinTokenStructV2 {
     ...
        uint256 deadline;
     ...
    }
function _joinTokenSingle(JoinTokenStructV2 calldata _joinTokenStruct)  internal {
     ...
           for (uint256 j; j < trade.swaps.length; j++) {
                IPangolinRouter(swap.exchange).swapExactTokensForTokens( amountIn,  0, swap.path, address(this),  block.timestamp );
            }
        }

SingleNativeTokenExitV2.sol L59-L88

 struct ExitTokenStructV2 {
        ...
        uint256 deadline;
       ...
    }
function _exit(ExitTokenStructV2 calldata _exitTokenStruct) internal {
     ...
        for (uint256 i; i < _exitTokenStruct.trades.length; i++) {
           ...
            for (uint256 j; j < trade.swaps.length; j++) {
                ...
                IPangolinRouter(swap.exchange).swapExactTokensForTokens( IERC20(swap.path[0]).balanceOf(address(this)), 0, swap.path, address(this), block.timestamp );
            }
        }

Recommended Mitigation Steps

Check whether the deadline fields should have been used. If so replace block.timestamp with the appropriate deadline

loki-sama (Amun) confirmed

The original report as published on Code4rena, by gpersoon. 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 code mistakenly uses block.timestamp instead of the deadline value from the input struct when calling the swap function.

Impact

An attacker could potentially delay the transaction to execute swaps at unfavourable rates, causing financial loss to users.

What the attacker needed

None

The fix

The code should be fixed by replacing block.timestamp with the appropriate deadline from the input struct.

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 blockchain transactions, a deadline is a timestamp that tells the system the latest time a trade can be executed. If the deadline is set to the current time (block.timestamp), it always passes immediately, so the trade can happen at any time, even if prices have changed. This report says some functions ignore the user-provided deadline and use the current time instead, which could let someone else delay the trade and cause a loss.

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 gpersoon

View all

47 more disclosed reports, best first.

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