Transaction: EIP-2929 (Berlin): Initial access list

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-05-27 08:45:55 +01:00
parent c6d50a0ef7
commit 76031ccbe4
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2
1 changed files with 19 additions and 0 deletions

View File

@ -54,6 +54,22 @@ proc hostToComputationMessage(msg: EvmcMessage): Message =
flags: if msg.isStatic: emvcStatic else: emvcNoFlags flags: if msg.isStatic: emvcStatic else: emvcNoFlags
) )
proc initialAccessListEIP2929(call: CallParams) =
# EIP2929 initial access list.
let vmState = call.vmState
if vmState.fork < FkBerlin:
return
vmState.mutateStateDB:
db.accessList(call.sender)
# For contract creations the EVM will add the contract address to the
# access list itself, after calculating the new contract address.
if not call.isCreate:
db.accessList(call.to)
# TODO: Check this only adds the correct subset of precompiles.
for c in activePrecompiles():
db.accessList(c)
proc setupCall(call: CallParams, useIntrinsic: bool): TransactionHost = proc setupCall(call: CallParams, useIntrinsic: bool): TransactionHost =
let vmState = call.vmState let vmState = call.vmState
vmState.setupTxContext( vmState.setupTxContext(
@ -100,6 +116,9 @@ proc runComputation*(call: CallParams): CallResult =
let host = setupCall(call, true) let host = setupCall(call, true)
let c = host.computation let c = host.computation
# Must come after `setupCall` for correct fork.
initialAccessListEIP2929(call)
# Charge for gas. # Charge for gas.
host.vmState.mutateStateDB: host.vmState.mutateStateDB:
db.subBalance(call.sender, call.gasLimit.u256 * call.gasPrice.u256) db.subBalance(call.sender, call.gasLimit.u256 * call.gasPrice.u256)