mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-05 16:54:00 +00:00
Merge pull request #134 from status-im/createOpContractAddr
Add to Create Op, generateAddress
This commit is contained in:
commit
8c425dc173
@ -135,6 +135,10 @@ proc getCode*(db: AccountStateDB, address: EthAddress): ByteRange =
|
|||||||
let codeHash = db.getCodeHash(address)
|
let codeHash = db.getCodeHash(address)
|
||||||
result = db.trie.get(codeHash.toByteRange_Unnecessary)
|
result = db.trie.get(codeHash.toByteRange_Unnecessary)
|
||||||
|
|
||||||
|
proc hasCodeOrNonce*(account: AccountStateDB, address: EthAddress): bool {.inline.} =
|
||||||
|
account.getNonce(address) != 0 or account.getCodeHash(address) != EMPTY_SHA3
|
||||||
|
|
||||||
proc dumpAccount*(db: AccountStateDB, addressS: string): string =
|
proc dumpAccount*(db: AccountStateDB, addressS: string): string =
|
||||||
let address = addressS.parseAddress
|
let address = addressS.parseAddress
|
||||||
return fmt"{addressS}: Storage: {db.getStorage(address, 0.u256)}; getAccount: {db.getAccount address}"
|
return fmt"{addressS}: Storage: {db.getStorage(address, 0.u256)}; getAccount: {db.getAccount address}"
|
||||||
|
|
||||||
|
4
nimbus/utils/addresses.nim
Normal file
4
nimbus/utils/addresses.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import nimcrypto, eth_common, rlp
|
||||||
|
|
||||||
|
func generateAddress*(address: EthAddress, nonce: AccountNonce): EthAddress =
|
||||||
|
result[0..19] = keccak256.digest(rlp.encodeList(address, nonce).toOpenArray).data.toOpenArray(12, 31)
|
@ -12,7 +12,7 @@ import
|
|||||||
./gas_meter, ./gas_costs, ./opcode_values, ./vm_forks,
|
./gas_meter, ./gas_costs, ./opcode_values, ./vm_forks,
|
||||||
../memory, ../message, ../stack, ../code_stream, ../computation,
|
../memory, ../message, ../stack, ../code_stream, ../computation,
|
||||||
../../vm_state, ../../errors, ../../constants, ../../vm_types,
|
../../vm_state, ../../errors, ../../constants, ../../vm_types,
|
||||||
../../db/[db_chain, state_db]
|
../../db/[db_chain, state_db], ../../utils/addresses
|
||||||
|
|
||||||
# ##################################
|
# ##################################
|
||||||
# Syntactic sugar
|
# Syntactic sugar
|
||||||
@ -545,19 +545,23 @@ op create, inline = false, value, startPosition, size:
|
|||||||
let callData = computation.memory.read(memPos, len)
|
let callData = computation.memory.read(memPos, len)
|
||||||
|
|
||||||
## TODO dynamic gas that depends on remaining gas
|
## TODO dynamic gas that depends on remaining gas
|
||||||
|
var
|
||||||
|
contractAddress: EthAddress
|
||||||
|
isCollision: bool
|
||||||
|
|
||||||
##### getNonce type error: expression 'db' is of type: proc (vmState: untyped, readOnly: untyped, handler: untyped): untyped{.noSideEffect, gcsafe, locks: <unknown>.}
|
computation.vmState.mutateStateDB:
|
||||||
# computation.vmState.db(readOnly=true):
|
# Regarding collisions, see: https://github.com/status-im/nimbus/issues/133
|
||||||
# let creationNonce = db.getNonce(computation.msg.storageAddress)
|
# See: https://github.com/ethereum/EIPs/issues/684
|
||||||
# db.incrementNonce(computation.msg.storageAddress)
|
let creationNonce = db.getNonce(computation.msg.storageAddress)
|
||||||
let contractAddress = ZERO_ADDRESS # generateContractAddress(computation.msg.storageAddress, creationNonce)
|
db.setNonce(computation.msg.storageAddress, creationNonce + 1)
|
||||||
|
|
||||||
let isCollision = false # TODO: db.accountHasCodeOrNonce ...
|
contractAddress = generateAddress(computation.msg.storageAddress, creationNonce)
|
||||||
|
isCollision = db.hasCodeOrNonce(contractAddress)
|
||||||
|
|
||||||
if isCollision:
|
if isCollision:
|
||||||
debug("Address collision while creating contract", address = contractAddress.toHex)
|
debug("Address collision while creating contract", address = contractAddress.toHex)
|
||||||
push: 0
|
push: 0
|
||||||
return
|
raise newException(ValidationError, "Contract creation failed, address already in use")
|
||||||
|
|
||||||
let childMsg = prepareChildMessage(
|
let childMsg = prepareChildMessage(
|
||||||
computation,
|
computation,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user