Platform: Code4rena
Start Date: 05/07/2023
Pot Size: $390,000 USDC
Total HM: 136
Participants: 132
Period: about 1 month
Judge: LSDan
Total Solo HM: 56
Id: 261
League: ETH
Rank: 24/132
Findings: 4
Award: $2,962.84
π Selected for report: 1
π Solo Findings: 0
π Selected for report: Sathish9098
Also found by: 0xSmartContract, 0xnev, Udsen, jasonxiale, rvierdiiev, tsvetanovv
76.5537 USDC - $76.55
https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/markets/bigBang/BigBang.sol#L365-L370 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/markets/bigBang/BigBang.sol#L384-L424 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/markets/singularity/SGLLeverage.sol#L117-L122 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/Penrose.sol#L529-L534
The BigBang
contract does not allow users to submit a deadline for their actions which execute swaps on Uniswap V3. This missing feature enables pending transactions to be maliciously executed at a later point.
Introducing a deadline parameter would help mitigate the risks associated with delayed transactions, changing token prices, and potential MEV exploitation.
FILE: tapioca-bar-audit/contracts/markets/bigBang/BigBang.sol function buyCollateral( address from, uint256 borrowAmount, uint256 supplyAmount, uint256 minAmountOut, ISwapper swapper, bytes calldata dexData ) external notPaused solvent(from) returns (uint256 amountOut) { require(penrose.swappers(swapper), "SGL: Invalid swapper"); // Let this fail first to save gas: uint256 supplyShare = yieldBox.toShare(assetId, supplyAmount, true); if (supplyShare > 0) { yieldBox.transfer(from, address(swapper), assetId, supplyShare); } uint256 borrowShare; (, borrowShare) = _borrow(from, address(swapper), borrowAmount); ISwapper.SwapData memory swapData = swapper.buildSwapData( assetId, collateralId, 0, supplyShare + borrowShare, true, true ); uint256 collateralShare; (amountOut, collateralShare) = swapper.swap( swapData, minAmountOut, from, dexData ); require(amountOut >= minAmountOut, "SGL: not enough"); _allowedBorrow(from, collateralShare); _addCollateral(from, from, false, 0, collateralShare); }
Imagine Alice
is using this function to swap some tokens for collateral. She initiates the swap with the intention of receiving a certain minimum amount of collateral, specified as minAmountOut
. However, due to network congestion or other issues, her transaction
remains pending for a prolonged period
.
During this delay, the value of the collateral might change significantly. If the value increases, Alice
might end up with more collateral than expected, which could be beneficial for her. However, if the value decreases, the amountOut
she receives might be lower than her originally specified minAmountOut
.
Without a deadline parameter, Introducing a deadline
parameter would allow Alice to specify a time window within which the swap
must be executed. If the swap is not executed within the specified timeframe
, the transaction could automatically fail or be reverted
, giving Alice more control over the outcome and preventing situations where she receives an unexpectedly low amount of collateral due to delays
Manual Audit
Introduce a deadline
parameter to all functions which potentially perform a swap on the userβs behalf.
MEV
#0 - c4-pre-sort
2023-08-05T12:43:15Z
minhquanym marked the issue as duplicate of #1513
#1 - c4-judge
2023-09-29T21:48:43Z
dmvt marked the issue as selected for report