The stake()
function in the provided code overwrites the existing staked amount for a user in the usersToStakes
mapping. This can lead to loss of previously staked funds and incorrect tracking of the total amount staked.
When a user stakes additional funds, the function replaces the existing staked amount with the new amount, effectively erasing any previous stake. This can result in incorrect accounting of the total staked amount and loss of user's previously staked funds.
User A stakes 10 ETH.
User A stakes another 5 ETH.
The usersToStakes[User A]
will now be 5 ETH, not 15 ETH, and the totalAmountStaked
will be incorrect.
Update the stake()
function to add the new stake amount to the existing staked amount, rather than overwriting it. This can be done by modifying the line:
to :
This will preserve the existing staked amount and correctly update the total amount staked.
Manual review, vscode
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.