EIP-3529: Replace SSTORE_CLEARS_SCHEDULE in evmc host_service

This commit is contained in:
jangko 2021-06-30 20:35:10 +07:00
parent db8988fe64
commit 697b38b844
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 12 additions and 1 deletions

View File

@ -94,13 +94,15 @@ const
# EIP-2200
SSTORE_SET_GAS = 20000
SSTORE_RESET_GAS = 5000
SSTORE_CLEARS_SCHEDULE = 15000
SLOAD_GAS_ISTANBUL = 800
# EIP-2929
WARM_STORAGE_READ_COST = 100
COLD_SLOAD_COST = 2100
COLD_ACCOUNT_ACCESS_COST = 2600
SSTORE_CLEARS_SCHEDULE_EIP2200 = 15000
SSTORE_CLEARS_SCHEDULE_EIP3529 = 4800
func storageModifiedAgainRefund(originalValue, oldValue, value: HostValue,
fork: Fork): int {.inline.} =
# Calculate `SSTORE` refund according to EIP-2929 (Berlin),
@ -114,6 +116,11 @@ func storageModifiedAgainRefund(originalValue, oldValue, value: HostValue,
elif fork >= FkIstanbul: SLOAD_GAS_ISTANBUL
else: SLOAD_GAS_CONSTANTINOPLE
result -= SLOAD_GAS
let SSTORE_CLEARS_SCHEDULE = if fork >= FkLondon:
SSTORE_CLEARS_SCHEDULE_EIP3529
else:
SSTORE_CLEARS_SCHEDULE_EIP2200
if not originalValue.isZero:
if value.isZero:
result += SSTORE_CLEARS_SCHEDULE
@ -147,6 +154,10 @@ proc setStorage(host: TransactionHost, address: HostAddress,
elif value.isZero:
# Gas refund for `DELETED` (all forks).
# TODO: Refund depends on `Computation` at the moment.
let SSTORE_CLEARS_SCHEDULE = if host.vmState.fork >= FkLondon:
SSTORE_CLEARS_SCHEDULE_EIP3529
else:
SSTORE_CLEARS_SCHEDULE_EIP2200
host.computation.gasMeter.refundGas(SSTORE_CLEARS_SCHEDULE)
return EVMC_STORAGE_DELETED
else: