Skip to content

Commit

Permalink
Adjust EIP-2200 refunds
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Sep 28, 2020
1 parent 18f52e2 commit 283869e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/vm/lib/evm/opFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1338,15 +1338,20 @@ function adjustSstoreGasEIP2929(

const keyStr = key.toString('hex')
const address = runState.eei.getAddress().toString('hex')
const warmRead = runState._common.param('gasPrices', 'warmstorageread')
const coldSload = runState._common.param('gasPrices', 'coldsload')

// @ts-ignore Set Object is possibly 'undefined'
if (runState.accessedStorage.has(address) && runState.accessedStorage.get(address).has(keyStr)) {
if (costName === 'reset') {
return defaultCost - runState._common.param('gasPrices', 'coldsload')
}

if (costName === 'noop') {
return runState._common.param('gasPrices', 'warmstorageread')
switch (costName) {
case 'reset':
return defaultCost - coldSload
case 'noop':
return warmRead
case 'initRefund':
return runState._common.param('gasPrices', 'sstoreInitGasEIP2200') - warmRead
case 'cleanRefund':
return runState._common.param('gasPrices', 'sstoreReset') - coldSload - warmRead
}
}

Expand Down Expand Up @@ -1523,13 +1528,15 @@ function updateSstoreGas(runState: RunState, found: any, value: Buffer, key: Buf
if (original.equals(value)) {
if (original.length === 0) {
// Reset to original non-existent slot
const sstoreInitRefund = runState._common.param('gasPrices', 'sstoreInitRefundEIP2200')
runState.eei.refundGas(
new BN(runState._common.param('gasPrices', 'sstoreInitRefundEIP2200')),
new BN(adjustSstoreGasEIP2929(runState, key, sstoreInitRefund, 'initRefund')),
)
} else {
// Reset to original existing slot
const sstoreCleanRefund = runState._common.param('gasPrices', 'sstoreCleanRefundEIP2200')
runState.eei.refundGas(
new BN(runState._common.param('gasPrices', 'sstoreCleanRefundEIP2200')),
new BN(adjustSstoreGasEIP2929(runState, key, sstoreCleanRefund, 'cleanRefund')),
)
}
}
Expand Down

1 comment on commit 283869e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 283869e Previous: ca3ef33 Ratio
Block 9422905 1736 ops/sec (±5.35%) 1850 ops/sec (±5.29%) 1.07
Block 9422906 1702 ops/sec (±5.95%) 1843 ops/sec (±5.64%) 1.08
Block 9422907 1768 ops/sec (±0.86%) 1911 ops/sec (±1.11%) 1.08
Block 9422908 1746 ops/sec (±0.58%) 1871 ops/sec (±1.14%) 1.07
Block 9422909 1717 ops/sec (±1.22%) 1543 ops/sec (±11.98%) 0.90
Block 9422910 1680 ops/sec (±1.45%) 1807 ops/sec (±1.13%) 1.08
Block 9422911 1330 ops/sec (±13.26%) 1785 ops/sec (±1.05%) 1.34
Block 9422912 1654 ops/sec (±1.37%) 1778 ops/sec (±1.25%) 1.07
Block 9422913 1626 ops/sec (±0.58%) 1613 ops/sec (±6.26%) 0.99
Block 9422914 1603 ops/sec (±0.55%) 1190 ops/sec (±16.11%) 0.74

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.