From c234a7b990954c0fd187678202a0547e83fa87e8 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 28 Sep 2020 09:21:19 -0700 Subject: [PATCH] Add charges for selfdestruct ETH recipient address reads --- packages/vm/lib/evm/opcodes/functions.ts | 1 + packages/vm/lib/evm/opcodes/util.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vm/lib/evm/opcodes/functions.ts b/packages/vm/lib/evm/opcodes/functions.ts index a6946b4ce4..bdde871d7d 100644 --- a/packages/vm/lib/evm/opcodes/functions.ts +++ b/packages/vm/lib/evm/opcodes/functions.ts @@ -1193,6 +1193,7 @@ export const handlers: Map = new Map([ runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount'))) } + accessAddressEIP2929(runState, selfdestructToAddress, 0) return runState.eei.selfDestruct(selfdestructToAddressBuf) }, ], diff --git a/packages/vm/lib/evm/opcodes/util.ts b/packages/vm/lib/evm/opcodes/util.ts index f7b50095c7..08437361d3 100644 --- a/packages/vm/lib/evm/opcodes/util.ts +++ b/packages/vm/lib/evm/opcodes/util.ts @@ -33,13 +33,14 @@ function accessAddressEIP2929(runState: RunState, address: BN | Buffer, baseFee? runState.accessedAddresses.add(addressStr) // CREATE, CREATE2 opcodes have the address warmed for free. - if (baseFee) { + // selfdestruct beneficiary address reads are charged an *additional* cold access + if (baseFee !== undefined) { runState.eei.useGas( new BN(runState._common.param('gasPrices', 'coldaccountaccess') - baseFee), ) } - // Warm - } else if (baseFee) { + // Warm: (selfdestruct beneficiary address reads are not charged when warm) + } else if (baseFee !== undefined && baseFee > 0) { runState.eei.useGas(new BN(runState._common.param('gasPrices', 'warmstorageread') - baseFee)) } }