-
Notifications
You must be signed in to change notification settings - Fork 5
Update EtherStore.sol #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-entrancy vulnerability and incorrect balance reset in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect balance reset after withdrawal locks 1 wei per user
Description:
TL;DR:
The
EtherStorecontract’swithdrawfunction resets the sender's balance to 1 wei instead of 0, resulting in permanently locked funds.The vulnerability in the
EtherStorecontract occurs when after a successful withdrawal, the user's balance is incorrectly set to 1 wei instead of zero. This error leads to a persistent lock of 1 wei per user and deviates from expected full withdrawal behavior.Details
The issue is present in the
withdrawfunction of theEtherStorecontract. The function first retrieves the user’s balance, ensures it is greater than zero, and proceeds to send the entire balance using a low-level call. The intended behavior is to reset the user's balance to zero after a successful withdrawal; however, the code sets it to 1. This minor error means that after each withdrawal, users retain a balance of 1 wei that cannot be effectively withdrawn due to gas costs and minimum transfer constraints. The relevant snippet is shown below:This logic flaw breaks the invariant that a full withdrawal should leave the user's balance at zero.
Impact
The impact of this bug is minimal in terms of monetary loss as it only locks 1 wei per user. However, it can lead to user confusion and does not align with the expected behavior of the contract. The issue does not create an avenue for fund theft or unauthorized control, but it implies a design oversight that may affect user trust.
Mitigation Steps:
Set
balances[msg.sender]to 0 after a successful withdrawal to correctly reflect the withdrawal of funds.-Implement unit tests to verify that the balance is reset to zero after withdrawal, ensuring the correct behavior of the function.