Flash swap call back prior to transferring tokens in indexPool
The flashSwap function in the IndexPool contract calls the callback before transferring tokens, so the sender does not receive tokens during the callback. This breaks the expected flash swap behaviour and could require redeploying all index pools if found after mainnet launch.
Submitted by broccoli, also found by 0xsanson and cmichel
Impact
In the IndexPool contract, flashSwap does not work. The callback function is called prior to token transfer. The sender won’t receive tokens in the callBack function. ITridentCallee(msg.sender).tridentSwapCallback(context);
Flashswap is not implemented correctly. It may need a migration to redeploy all indexPools if the issue is found after main-net launch. I consider this a high-risk issue.
Proof of Concept
ITridentCallee(msg.sender).tridentSwapCallback(context);
// @dev Check Trident router has sent `amountIn` for skim into pool.
unchecked { // @dev This is safe from under/overflow - only logged amounts handled.
require(_balance(tokenIn) >= amountIn + inRecord.reserve, "NOT_RECEIVED");
inRecord.reserve += uint120(amountIn);
outRecord.reserve -= uint120(amountOut);
}
_transfer(tokenOut, amountOut, recipient, unwrapBento);
Recommended Mitigation Steps
_transfer(tokenOut, amountOut, recipient, unwrapBento);
ITridentCallee(msg.sender).tridentSwapCallback(context);
// @dev Check Trident router has sent `amountIn` for skim into pool.
unchecked { // @dev This is safe from under/overflow - only logged amounts handled.
require(_balance(tokenIn) >= amountIn + inRecord.reserve, "NOT_RECEIVED");
inRecord.reserve += uint120(amountIn);
outRecord.reserve -= uint120(amountOut);
}
Duplicate of https://github.com/code-423n4/2021-09-sushitrident-findings/issues/157 and https://github.com/code-423n4/2021-09-sushitrident-findings/issues/80
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 callback is invoked before the outbound token transfer, so the recipient cannot use the tokens during the callback.
Impact
Flash swaps do not work as intended, and fixing after mainnet launch may require migrating all index pools.
What the attacker needed
None
The fix
The outbound token transfer should be moved before the callback invocation.
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 flash swap lets someone borrow tokens and repay them within one transaction. The contract should send the borrowed tokens to the borrower before asking them to repay. Here, the contract asks for repayment first, so the borrower never gets the tokens to use.
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.