vm2: Use `ContractSalt` type for `CREATE2` salt

As this branch of vm2 doesn't support EVMC, this EVMC-motivated change is only
required here for internal compatibility.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-06-11 12:46:26 +01:00
parent 11f03a1846
commit 20e1831e6f
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2
2 changed files with 7 additions and 5 deletions

View File

@ -35,7 +35,7 @@ when defined(chronicles_log_level):
# Helpers # Helpers
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
proc generateContractAddress(c: Computation, salt: Uint256): EthAddress = proc generateContractAddress(c: Computation, salt: ContractSalt): EthAddress =
if c.msg.kind == evmcCreate: if c.msg.kind == evmcCreate:
let creationNonce = c.vmState.readOnlyStateDb().getNonce(c.msg.sender) let creationNonce = c.vmState.readOnlyStateDb().getNonce(c.msg.sender)
result = generateAddress(c.msg.sender, creationNonce) result = generateAddress(c.msg.sender, creationNonce)
@ -105,8 +105,8 @@ template selfDestruct*(c: Computation, address: EthAddress) =
template getCode*(c: Computation, address: EthAddress): seq[byte] = template getCode*(c: Computation, address: EthAddress): seq[byte] =
c.vmState.readOnlyStateDB.getCode(address) c.vmState.readOnlyStateDB.getCode(address)
proc newComputation*(vmState: BaseVMState, proc newComputation*(vmState: BaseVMState, message: Message,
message: Message, salt= 0.u256): Computation = salt: ContractSalt = ZERO_CONTRACTSALT): Computation =
new result new result
result.vmState = vmState result.vmState = vmState
result.msg = message result.msg = message

View File

@ -16,6 +16,7 @@ import
../../../constants, ../../../constants,
../../../errors, ../../../errors,
../../../forks, ../../../forks,
../../../utils,
../../computation, ../../computation,
../../memory, ../../memory,
../../stack, ../../stack,
@ -37,7 +38,8 @@ import
# Private helpers # Private helpers
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
proc execSubCreate(k: var Vm2Ctx; childMsg: Message; salt = 0.u256) = proc execSubCreate(k: var Vm2Ctx; childMsg: Message;
salt: ContractSalt = ZERO_CONTRACTSALT) =
## Create new VM -- helper for `Create`-like operations ## Create new VM -- helper for `Create`-like operations
# need to provide explicit <c> and <child> for capturing in chainTo proc() # need to provide explicit <c> and <child> for capturing in chainTo proc()
@ -123,7 +125,7 @@ const
endowment = k.cpt.stack.popInt() endowment = k.cpt.stack.popInt()
memPos = k.cpt.stack.popInt().safeInt memPos = k.cpt.stack.popInt().safeInt
memLen = k.cpt.stack.popInt().safeInt memLen = k.cpt.stack.popInt().safeInt
salt = k.cpt.stack.peekInt() salt = ContractSalt(bytes: k.cpt.stack.peekInt().toBytesBE)
k.cpt.stack.top(0) k.cpt.stack.top(0)