Beginner FriendlyFoundryDeFi
100 EXP
View results
Submission Details
Severity: high
Invalid

Reentrancy Attack

Summary: The unstake function is susceptible to a reentrancy attack due to the order of operations, specifically the transfer of Ether before updating the state variables related to staking balances.

Vulnerability Details: In the unstake function, Ether is transferred out of the contract using the send method before the state variables usersToStakes and totalAmountStaked are updated. This allows a malicious contract at the _to address to recursively call the unstake function, draining funds from the contract.

Impact: A successful reentrancy attack could lead to significant loss of funds from the contract, undermining trust and potentially causing financial harm to stakeholders.

Tools Used: Manual code review based on Solidity best practices and understanding of Ethereum smart contract vulnerabilities.

Recommendations:

1.Implementing the Checks-Effects-Interactions pattern by moving the send operation to the end of the function, after all state variables have been updated.

2.Using the transfer function instead of send for transferring Ether, as it forwards only a limited gas stipend, mitigating reentrancy risks.

3.Alternatively, adopting a pull-over-push pattern for withdrawals, where users withdraw funds themselves upon request, further reducing reentrancy risks.

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.