LeverageMacroBase::_doOperation
will revert if willSweep
is set to true
#146
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
🤖_11_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/ebtc-protocol/ebtc/blob/2da05f2d1354190eacf64ec256d2c5c5358e5fa2/packages/contracts/contracts/LeverageMacroBase.sol#L241-L243
https://github.com/ebtc-protocol/ebtc/blob/2da05f2d1354190eacf64ec256d2c5c5358e5fa2/packages/contracts/contracts/LeverageMacroBase.sol#L248
https://github.com/ebtc-protocol/ebtc/blob/2da05f2d1354190eacf64ec256d2c5c5358e5fa2/packages/contracts/contracts/LeverageMacroBase.sol#L43-L46
Vulnerability details
LeverageMacroBase.sol
has an internal function_doOperation
that handles the execution of the CDP operation requested by an user, which can be opening a CDP, adjusting a CDP or closing a CDP.LeverageMacroBase::_doOperation
After handling the operation, the
_doOperation
function performs post-operation checks to ensure that the CDP position values, such as debt and collateral, are as expected post-operation execution.After performing the post-operation checks, there is a selection statement that checks if
willSweep
has been set to true and if it evaluates to true, the_doOperation
function callssweepToCaller
to ensure that any dust that has been left over from the performed operation is transferred back to the user.The
sweepToCaller
function calls another internal function_assertOwner
, which checks who is the caller of thesweepToCaller
function and compares it against the owner of theLeverageZapRouterBase
contract that has been initialized during the contract construction.LeverageMacroBase::sweepToCaller
LeverageMacroBase::_assertOwner
LeverageZapRouterBase::constructor
However, given that any user can perform operations such as opening a CDP, adjusting a CDP and closing a CDP, it is unsafe to assume that the caller of the
sweepToCaller
function will be equal to the owner address initialized during theLeverageZapRouterBase
construction.Impact
If
willSweep
is set to true, all main functions -openCdp
,adjustCdp
,closeCdp
- will revert becausemsg.sender
can be any arbitrary EOA address and would not necessarily be equal to the owner address of the contract.Although in the specific case of
LeverageZapRouterBase
, thewillSweep
variable is initialized to false, the overall implementation is flawed. ThesweepToCaller
function can only be called by the owner of theLeverageZapRouterBase
and no one else, effectively making it asweepToOwner
instead of asweepToCaller
.Proof of Concept
https://github.com/ebtc-protocol/ebtc/blob/2da05f2d1354190eacf64ec256d2c5c5358e5fa2/packages/contracts/contracts/LeverageMacroBase.sol#L241-L243
https://github.com/ebtc-protocol/ebtc/blob/2da05f2d1354190eacf64ec256d2c5c5358e5fa2/packages/contracts/contracts/LeverageMacroBase.sol#L248
https://github.com/ebtc-protocol/ebtc/blob/2da05f2d1354190eacf64ec256d2c5c5358e5fa2/packages/contracts/contracts/LeverageMacroBase.sol#L43-L46
Tools Used
Manual Review
Recommended Mitigation Steps
Change the
sweepToCaller
function's visibility toprivate
to ensure it cannot be called by anyone other than the contract itself and remove the_assertOwner
call, so that it can properly transfer the remaining dust to any arbitrary EOA address and not just the owner address.Assessed type
DoS
The text was updated successfully, but these errors were encountered: