From 76031ccbe4d50ea57f13cb2478b94c53db6fb6c4 Mon Sep 17 00:00:00 2001 From: Jamie Lokier Date: Thu, 27 May 2021 08:45:55 +0100 Subject: [PATCH] Transaction: EIP-2929 (Berlin): Initial access list Signed-off-by: Jamie Lokier --- nimbus/transaction/call_common.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nimbus/transaction/call_common.nim b/nimbus/transaction/call_common.nim index 333cfaeca..0f0ad53e7 100644 --- a/nimbus/transaction/call_common.nim +++ b/nimbus/transaction/call_common.nim @@ -54,6 +54,22 @@ proc hostToComputationMessage(msg: EvmcMessage): Message = 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 = let vmState = call.vmState vmState.setupTxContext( @@ -100,6 +116,9 @@ proc runComputation*(call: CallParams): CallResult = let host = setupCall(call, true) let c = host.computation + # Must come after `setupCall` for correct fork. + initialAccessListEIP2929(call) + # Charge for gas. host.vmState.mutateStateDB: db.subBalance(call.sender, call.gasLimit.u256 * call.gasPrice.u256)