`getCollateral` and `getAsset` functions of the AssetTotsDaiLeverageExecutor contract decode data incorrectly
The AssetTotsDaiLeverageExecutor contract decodes swap data twice, causing the data to be misaligned and the functions to revert. An attacker could not exploit this; it is a functional bug that breaks the contract's intended operation.
Source: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/84
Found by
duc
Summary
See vulnerability detail
Vulnerability Detail
In AssetTotsDaiLeverageExecutor contract, getCollateral function decodes the data before passing it to _swapAndTransferToSender function.
SLeverageSwapData memory swapData = abi.decode(data, (SLeverageSwapData));
uint256 daiAmount =
_swapAndTransferToSender(false, assetAddress, daiAddress, assetAmountIn, swapData.swapperData);
However, _swapAndTransferToSender will decode this data again to obtain the swapperData:
function _swapAndTransferToSender(
bool sendBack,
address tokenIn,
address tokenOut,
uint256 amountIn,
bytes memory data
) internal returns (uint256 amountOut) {
SLeverageSwapData memory swapData = abi.decode(data, (SLeverageSwapData));
...
The redundant decoding will cause the data to not align as expected, which is different from SimpleLeverageExecutor.getCollateral() function (code snippet)
Impact
getCollateral and getAsset of AssetTotsDaiLeverageExecutor will not work as intended due to incorrectly decoding data.
Code Snippet
https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/leverage/AssetTotsDaiLeverageExecutor.sol#L53-L55 https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/leverage/AssetTotsDaiLeverageExecutor.sol#L88-L91
Tool used
Manual Review
Recommendation
The AssetTotsDaiLeverageExecutor contract should pass data directly to _swapAndTransferToSender, similar to the SimpleLeverageExecutor contract
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
takarez commented:
it seem to have been encoded twice, cuz it will not work if its encoded once in the first place
nevillehuang
@cryptotechmaker This seems to lack an impact description, but would this cause an revert within _swapAndTransferToSender?
cryptotechmaker
Yes, it causes a revert.
sherlock-admin4
The protocol team fixed this issue in PR/commit https://github.com/Tapioca-DAO/Tapioca-bar/commit/2432f1e85cb241d46b8da220226a744b7fc36f88.
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 getCollateral and getAsset functions will revert and not work as intended.
What the attacker needed
None
The fix
The contract should pass the original data directly to _swapAndTransferToSender without decoding it first, similar to SimpleLeverageExecutor.
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.
This contract is supposed to take some encoded data, decode it once, and use it. But it decodes the data twice, which corrupts the information and makes the function fail. As a result, the contract cannot perform its job.
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.