-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Don't assume contracts are created with zero balance #61
Comments
Excellent edge case @SergioDemianLerner. Thanks for the find. We will add this. |
@SergioDemianLerner ...Does it mean if the authentic user tries creating the contract, the already existing one is used or how does the pre-creation affect the new creation? If indeed the attacker's pre-created contract is used and has control over the "contract created" by the real user, does that mean only the attacker would then have access over the contract and it's funds, which would have been updated by the authentic user? |
@lherbeur an account (no code) is what's pre-created. This advice is even in the case where someone sends ether to an accidental address, which happens to be the address that your new contract would be deployed to. |
Can we create a contract with pre existing balance and it will not refer to the addresse which created it. Annonimize the creator |
and also, will this balance be used by the owner of the contract or it will stay blocked if it came from someone else? |
`require(this.balance == 0);` is addressing any possibility of this happening: Consensys/smart-contract-best-practices#61
Contract developers may assume a newly created contract has zero balance. For example,developers may write asserts on different parts of the code that check that the contract balance equals an internal field such as expectedBalance, which is updated on every incoming/outgoing payment.
In Ethereum contract addresses can be guessed: they are built using the source address and source nonce hashed. Therefore an attacker can predict the a contract address that is to be created and send before a tiny amount of ether the that address, pre-creating an account (without any code) with the same address. The attacker has no control over it, so the account nonce will be always zero. When the contract is actually created by the authentic source, the pre-existing balance will not be destroyed: the contract will be created with a pre-existent non-zero balance. Therefore a contract cannot assume the balance is zero upon creation.
The text was updated successfully, but these errors were encountered: