OnRecvPacket does not roll back failures in Convert coins or Swap coins #3
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-19
grade-b
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_primary
AI based primary recommendation
🤖_08_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-05-canto/blob/d1d51b2293d4689f467b8b1c82bba84f8f7ea008/canto-main/x/onboarding/keeper/ibc_callbacks.go#L137
Vulnerability details
Impact
onboarding#OnRecvPacket will be call
coinswapKeeper.TradeInputForExactOutput and
erc20Keeper.ConvertCoin
However, if the execution of these two functions fails in the middle, for example, the user's token has been deducted, but the execution fails when mint is executed, the transaction will not be rolled back, which will cause the loss of user funds.
Proof of Concept
The x/keeper function will return an error. If the function is executed through RPC, if it fails, the SDK will handle the error and roll back the transaction.
However,OnRecvPacket calls the keeper function directly, and the error returned by the keeper function is not passed.
The OnRecvPacket function returns the same ack regardless of success or failure.
Therefore, if the erc20Keeper.ConvertCoin function fails halfway through execution, the error will not be handled.
The ConvertCoin function usually first deducts the user's token and then calls the mint or transfer function (k.CallEVM) in the contract.
Since there are many cases where K.CallEVM may fail to execute, if after deducting the user token, K.CallEVM does not execute successfully, the user's token will be permanently lost.
The
convertCoinNativeERC20
function checks whether the user's balance is consistent after the conversion, and checks theApproval
event in logs,In this case, these checks are invalid because the returned error will not be handled.
The same problem occurs when executing
coinswapKeeper.TradeInputForExactOutput
.Tools Used
vscode, manual
Recommended Mitigation Steps
Assessed type
Error
The text was updated successfully, but these errors were encountered: