REENTRANCY ATTACK POSSIBLE IF THE _feeTo
IS A MALICIOUS CONTRACT IN FeeWrapper._chargeFeePayable()
FUNCTION
#1166
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
M-08
primary issue
Highest quality submission among a set of duplicates
selected for report
This submission will be included/highlighted in the audit report
Lines of code
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/FeeWrapper.sol#L76-L89
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/FeeWrapper.sol#L108-L121
Vulnerability details
Impact
Reentrancy attack could happen if
_feeTo
is amalicious
contract and hasrecieve()
function implemented in_feeTo
contract.FeeWrapper._chargeFeePayable()
function is used to send the_feeAmount
of Eth to the_feeTo
address.Consider that
FeeWrapper._chargeFeePayable()
is called by theFeeWrapper._rubicallPayable()
function with the necessary_feeParams
input parameter, and the following scenario can occur:1 . The call to (bool OK, ) =
payable(_feeTo)
.call{value: _feeAmount}("") is made. Lets assume the _totalAmount = 1Eth and _feeAmount = 0.1Eth initially.2 .
_feeTo
contract hasrecieve()
function implemented in it.3 . It reenters the
FeeWrapper
contract by calling therubicallPayable()
function by sending0.01Eth
as msg.value.4 . Sets the
_feeParams.totalAmount = 0.01Eth
and_feeParams.feeAmount = 0.1Eth
in the call torubicallPayable()
5 .
FeeWrapper.chargeFeePayable()
will be called again by therubicallPayable()
function.6 . (bool OK, ) = payable(_feeTo).call{value: _feeAmount}(""); will be called and
Tx will pass
since there isenouth Eth
in the contract from the previous deposit.7 . Again
_feeParams.feeAmount = 0.1Eth
will be transferred to the_feeTo
address.8 . This can be continued till there is
enough Eth in the contract
.9 . This happens due to there is
no check
to make suremsg.value > _feeAmount
before the low levelcall
to the_feeTo
address.Proof of Concept
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/FeeWrapper.sol#L108-L121
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/FeeWrapper.sol#L76-L89
Tools Used
Manual Review and VSCode
Recommended Mitigation Steps
Two options can be recommended to mitigate this issue:
Add a reentrancy guard.
Openzeppelin
ReentrancyGuard.sol
can be used, andnonReentrant
modifier can be added to bothFeeWrapper._chargeFeePayable()
andFeeWrapper._rubicallPayable()
functions.Check that the ``msg.value > _feeAmount
before the low level
call` to the `_feeTo` address is made. In that case there is no gain to the `_feeTo` malicious contract, since the value it sending via `msg.value` is any way greater than the `_feeAmount` which he can steal via `reentrancy attack`.The text was updated successfully, but these errors were encountered: