-
Notifications
You must be signed in to change notification settings - Fork 197
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
TRC: Create2 #26
Comments
@ithinker1991 , I notice etheream version has an extra 0xff to generate new contract address. Why we don't add that in our version? |
@taihaofu the formula in ETH is different and Excerpt from EIP-1014:
|
@ithinker1991 IMHO it's not obvious why there is no conflict in generated address between |
address is always 21 bytes
|
refer : https://github.com/miguelmota/solidity-create2-example |
Interesting reading: https://medium.com/coinmonks/why-create2-e99b6afcc28c |
By having arbitrarily dropped the 0xff from the prefix, you sadly broke Nick's method of being able to create singleton contracts across chains, including EIP-2470 singletons :(. https://eips.ethereum.org/EIPS/eip-2470 |
Simple Summary
A new contract creation function called CREATE2
Abstract
A new method of creating a contract is proposed where the resulting address can be determined by parties ahead of time.
Motivation
Allows interactions to (actually or counterfactually in channels) be made with addresses that do not exist yet on-chain but can be relied on to only possibly eventually contain code that has been created by a particular piece of init code. Important for state-channel use cases that involve counterfactual interactions with contracts.
Specification
Adds a new opcode at 0xf5, which takes 4 stack arguments: endowment, memory_start, memory_length, salt. Behaves identically to CREATE, except using
addressPrefix ++ keccak256(address ++ salt ++ keccak256(init_code))[12:]
to create a new contract address.addressPrefix
is0x41
for
TThe
CREATE2
has the sameengery
schema asCREATE
, but also an extrahashcost
ofGSHA3WORD * ceil(len(init_code) / 32)
, to account for the hashing that must be performed. Thehashcost
is deducted at the same time as memory-expansion engery andCreate
is deducted: before evaluation of the resulting address and the execution ofinit_code
.address
is always21
bytes,salt
is always32
bytes (a stack item).keccak256(init_code)
32 bytesThe preimage for the final hashing round is thus always exactly
85
bytes long.Rationale
Address formula
CREATE
mainly depends ontrxHash
, the CREATE2 addresses will not collide with CREATE addresses.addressPrefix ++ keccak256(trxHash ++ txOwnerAddress)[12:]
addressPrefix ++ keccak256(trxHash ++ nonce)[12:]
Engery cost
Since address calculation depends on hashing the
init_code
, it would leave clients open to DoS attacks if executions could repeatedly cause hashing of large pieces ofinit_code
, since expansion of memory is paid for only once. This TIP uses the same cost-per-word as theSHA3
opcode.The text was updated successfully, but these errors were encountered: