Closed code423n4 closed 2 years ago
We do not support tokens that offer reentrancy opportunities
For a discussion similar to #19 , while impact is minimal, I believe the finding to have validity in that the code doesn't respect CEI and doesn't have a nonReentrant
guard.
For those reasons I believe QA to be more appropriate
Lines of code
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/StakerVault.sol#L381-L383
Vulnerability details
Impact
When calling
StakerVault.unstakeFor()
, the user's balance is decremented by the value ofunstaked
. The withdrawal transfer occurs prior to calculating the amount ofunstaked
. Given thattoken
is an ERC20Upgradeable, it is within reason that this token will be upgraded in the future and will make a call to the receiver as is the standard for ERC777 or ERC1155 tokens.The vulnerability lies in the fact that
unstaked
is calculated based on the contract's token balances before and after the transfer. If the token were to transfer control flow to the receiver, the receiver could simply stake the withdrawn value, effectively printing money.Proof of Concept
Steps for exploit
100 ether
of token100 ether
safeTransfer()
and will immediately callstake()
with the same100 ether
.unstaked
will calculate to 0 since the contract's token balance will remain unchanged.200 ether
.Tools Used
Manual review
Recommended Mitigation Steps
Do not check the contract's token balance in order to calculate the value of
unstaked
. Simply subtract the amount that was sent viasafeTransfer()
.