EIP-3529: Reduce the max gas refunded after a transaction
Previously max gas refunded was defined as gas_used div 2. Here we name the constant 2 as MAX_REFUND_QUOTIENT and change its value to 5. The new equation will be: gas_used div MAX_REFUND_QUOTIENT
This commit is contained in:
parent
05d905b136
commit
472e4457e3
|
@ -21,10 +21,6 @@ func intrinsicGas*(data: openarray[byte], fork: Fork): GasInt =
|
|||
result += gasFees[fork][GasTXDataNonZero]
|
||||
|
||||
proc intrinsicGas*(tx: Transaction, fork: Fork): GasInt =
|
||||
const
|
||||
ADDRESS_COST = 2400
|
||||
STORAGE_KEY_COST = 1900
|
||||
|
||||
# Compute the baseline gas cost for this transaction. This is the amount
|
||||
# of gas needed to send this transaction (but that is not actually used
|
||||
# for computation)
|
||||
|
@ -34,11 +30,11 @@ proc intrinsicGas*(tx: Transaction, fork: Fork): GasInt =
|
|||
result = result + gasFees[fork][GasTXCreate]
|
||||
|
||||
if tx.txType > TxLegacy:
|
||||
result = result + tx.accessList.len * ADDRESS_COST
|
||||
result = result + tx.accessList.len * ACCESS_LIST_ADDRESS_COST
|
||||
var numKeys = 0
|
||||
for n in tx.accessList:
|
||||
inc(numKeys, n.storageKeys.len)
|
||||
result = result + numKeys * STORAGE_KEY_COST
|
||||
result = result + numKeys * ACCESS_LIST_STORAGE_KEY_COST
|
||||
|
||||
proc getSignature*(tx: Transaction, output: var Signature): bool =
|
||||
var bytes: array[65, byte]
|
||||
|
|
|
@ -60,11 +60,6 @@ proc hostToComputationMessage*(msg: EvmcMessage): Message =
|
|||
flags: if msg.isStatic: emvcStatic else: emvcNoFlags
|
||||
)
|
||||
|
||||
# From EIP-2930 (Berlin).
|
||||
const
|
||||
ACCESS_LIST_STORAGE_KEY_COST = 1900.GasInt
|
||||
ACCESS_LIST_ADDRESS_COST = 2400.GasInt
|
||||
|
||||
func intrinsicGas(call: CallParams, fork: Fork): GasInt {.inline.} =
|
||||
# Compute the baseline gas cost for this transaction. This is the amount
|
||||
# of gas needed to send this transaction (but that is not actually used
|
||||
|
@ -215,12 +210,18 @@ proc runComputation*(call: CallParams): CallResult =
|
|||
else:
|
||||
doExec(host, call)
|
||||
|
||||
# EIP-3529: Reduction in refunds
|
||||
let MaxRefundQuotient = if host.vmState.fork >= FkLondon:
|
||||
5.GasInt
|
||||
else:
|
||||
2.GasInt
|
||||
|
||||
# Calculated gas used, taking into account refund rules.
|
||||
var gasRemaining: GasInt = 0
|
||||
if call.noRefund:
|
||||
gasRemaining = c.gasMeter.gasRemaining
|
||||
elif not c.shouldBurnGas:
|
||||
let maxRefund = (call.gasLimit - c.gasMeter.gasRemaining) div 2
|
||||
let maxRefund = (call.gasLimit - c.gasMeter.gasRemaining) div MaxRefundQuotient
|
||||
let refund = min(c.getGasRefund(), maxRefund)
|
||||
c.gasMeter.returnGas(refund)
|
||||
gasRemaining = c.gasMeter.gasRemaining
|
||||
|
|
Loading…
Reference in New Issue