code-423n4 / 2022-06-yieldy-findings

0 stars 0 forks source link

Reentrancy vulnerability Staking.sol #8

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-06-yieldy/blob/524f3b83522125fb7d4677fa7a7e5ba5a2c0fe67/src/contracts/Staking.sol#L674-L719

Vulnerability details

Impact

Possible Reentrancy attack function does not follow check effect interact pattern leaving it open to a possible reentrnacy attack re-entrancy attack can lead to a function being called again leading to the removal of more funds than are alloted/allowed by the external caller, Contracts should not make any changes to state variables, after interacting with external entities, as we cannot rely on the execution of any code coming after the interaction.

Proof of Concept

(direct link to code in question) https://github.com/code-423n4/2022-06-yieldy/blob/524f3b83522125fb7d4677fa7a7e5ba5a2c0fe67/src/contracts/Staking.sol#L674-L719

personal automated test outcome

Reentrancy in Staking.unstake(uint256,bool) (src/contracts/Staking.sol#674-696): External calls:

RequestWithdraw can be called multiple times possible ability to withdraw more funds than alloted/allowed

Tools Used

Sither

Recommended Mitigation Steps

ensure functions follow the correct check, effect, interact pattern and add additional checks in place where needed to stop potential reentrancy attacks however small the threat of maybe

toshiSat commented 2 years ago

73