Skip to content

Commit

Permalink
Add charges for selfdestruct ETH recipient address reads
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Sep 28, 2020
1 parent 283869e commit 4f1a28d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vm/lib/evm/opFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ export const handlers: Map<number, OpHandler> = new Map([
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
}

accessAddressEIP2929(runState, selfdestructToAddress, 0)
return runState.eei.selfDestruct(selfdestructToAddressBuf)
},
],
Expand Down Expand Up @@ -1278,13 +1279,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))
}
}
Expand Down

0 comments on commit 4f1a28d

Please sign in to comment.