Functions in AggregateRouter dont allow reverts #30
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
🤖_54_group
AI based duplicate group recommendation
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/ronin-chain/katana-operation-contracts/blob/27f9d28e00958bf3494fa405a8a5acdcd5ecdc5d/src/aggregate-router/base/Dispatcher.sol#L31-L51
Vulnerability details
Proof of Concept
The
AggregateRouter
contract allows functions to fail and still have the other functions succeed. This is implemented via a failure check implemented in the code.So a user can decide to allow a function call to fail, by setting a particular bit in the command.
The
command
is passed in as a byte array, where each byte represents a single command.Of that 1 byte, 2 masks are used to define the operation.
A
COMMAND_TYPE_MASK
of 0x3f (00111111) is used to define the operation. This is the last 6 bits of the byte. AFLAG_ALLOW_REVERT
of 0x80 (10000000) is used to define the allow revert. This is the first bit of the byte.So a user can presumable set an operation with the last 6 bits, and then set an allowrevert in the first bit, to allow execution of other functions. These two things are independent, and can be chosen by the user.
The issue is that the allowRevert functionality mostly doesn't work.
This is because in the
Dispatcher.sol
contract, thesuccess
value is updated in only one function out of the 14 implemented, and none of the function calls usetry-catch
pattern to check for success.The
success
value is set in the contract totrue
, and then never updated.As seen in the snippet above, the swap function is called directly, so any reverts in the swap function reverts the main
execute
function, without giving any opportunity for a graceful failure.Thus the whole mechanism of using the first bit to define
FLAG_ALLOW_REVERT
has been ignored.Only the implementation of the
BALANCE_CHECK_ERC20
command updates success correctly.Thus the dispatcher contract does not allow for any soft failures. Since the devs intend to allow for soft failures as shown by the usage of the
FLAG_ALLOW_REVERT
mask, this is an issue.Recommended Mitigation Steps
The function calls in the dispatcher should be done with
try-catch
statements. If failed, thesuccess
value should be updated accordingly and returned.Assessed type
Other
The text was updated successfully, but these errors were encountered: