ethereum.forks.amsterdam.vm.gas

Ethereum Virtual Machine (EVM) Gas.

.. contents:: Table of Contents :backlinks: none :local:

Introduction

EVM gas constants and calculators.

StateCosts

State byte costs and per byte gas charge.

Kept separate from GasCosts so the two dimensions don't share units. NEW_ACCOUNT, STORAGE_SET, AUTH_BASE are byte counts (not gas) — compute_state_byte_diff returns a signed sum of these, multiplied by PER_BYTE at frame-end to convert into gas.

class StateCosts:

NEW_ACCOUNT

40
    NEW_ACCOUNT = Uint(112)

STORAGE_SET

41
    STORAGE_SET = Uint(32)

AUTH_BASE

42
    AUTH_BASE = Uint(23)

PER_BYTE

45
    PER_BYTE = Uint(1174)

GasCosts

Constant gas values for the EVM.

class GasCosts:

BASE

55
    BASE = Uint(2)

VERY_LOW

56
    VERY_LOW = Uint(3)

LOW

57
    LOW = Uint(5)

MID

58
    MID = Uint(8)

HIGH

59
    HIGH = Uint(10)

WARM_ACCESS

62
    WARM_ACCESS = Uint(100)

COLD_ACCOUNT_ACCESS

63
    COLD_ACCOUNT_ACCESS = Uint(2600)

COLD_STORAGE_ACCESS

64
    COLD_STORAGE_ACCESS = Uint(2100)

STORAGE_SET

67
    STORAGE_SET = Uint(20000)

COLD_STORAGE_WRITE

68
    COLD_STORAGE_WRITE = Uint(5000)

CALL_VALUE

71
    CALL_VALUE = Uint(9000)

CALL_STIPEND

72
    CALL_STIPEND = Uint(2300)

NEW_ACCOUNT

73
    NEW_ACCOUNT = Uint(25000)

CODE_DEPOSIT_PER_BYTE

76
    CODE_DEPOSIT_PER_BYTE = Uint(200)

CODE_INIT_PER_WORD

77
    CODE_INIT_PER_WORD = Uint(2)

PER_AUTH_BASE_COST

80
    PER_AUTH_BASE_COST = Uint(7500)

ZERO

83
    ZERO = Uint(0)

MEMORY_PER_WORD

84
    MEMORY_PER_WORD = Uint(3)

FAST_STEP

85
    FAST_STEP = Uint(5)

REFUND_STORAGE_CLEAR

88
    REFUND_STORAGE_CLEAR = 4800

PRECOMPILE_ECRECOVER

91
    PRECOMPILE_ECRECOVER = Uint(3000)

PRECOMPILE_P256VERIFY

92
    PRECOMPILE_P256VERIFY = Uint(6900)

PRECOMPILE_SHA256_BASE

93
    PRECOMPILE_SHA256_BASE = Uint(60)

PRECOMPILE_SHA256_PER_WORD

94
    PRECOMPILE_SHA256_PER_WORD = Uint(12)

PRECOMPILE_RIPEMD160_BASE

95
    PRECOMPILE_RIPEMD160_BASE = Uint(600)

PRECOMPILE_RIPEMD160_PER_WORD

96
    PRECOMPILE_RIPEMD160_PER_WORD = Uint(120)

PRECOMPILE_IDENTITY_BASE

97
    PRECOMPILE_IDENTITY_BASE = Uint(15)

PRECOMPILE_IDENTITY_PER_WORD

98
    PRECOMPILE_IDENTITY_PER_WORD = Uint(3)

PRECOMPILE_BLAKE2F_PER_ROUND

99
    PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1)

PRECOMPILE_POINT_EVALUATION

100
    PRECOMPILE_POINT_EVALUATION = Uint(50000)

PRECOMPILE_BLS_G1ADD

101
    PRECOMPILE_BLS_G1ADD = Uint(375)

PRECOMPILE_BLS_G1MUL

102
    PRECOMPILE_BLS_G1MUL = Uint(12000)

PRECOMPILE_BLS_G1MAP

103
    PRECOMPILE_BLS_G1MAP = Uint(5500)

PRECOMPILE_BLS_G2ADD

104
    PRECOMPILE_BLS_G2ADD = Uint(600)

PRECOMPILE_BLS_G2MUL

105
    PRECOMPILE_BLS_G2MUL = Uint(22500)

PRECOMPILE_BLS_G2MAP

106
    PRECOMPILE_BLS_G2MAP = Uint(23800)

PRECOMPILE_ECADD

107
    PRECOMPILE_ECADD = Uint(150)

PRECOMPILE_ECMUL

108
    PRECOMPILE_ECMUL = Uint(6000)

PRECOMPILE_ECPAIRING_BASE

109
    PRECOMPILE_ECPAIRING_BASE = Uint(45000)

PRECOMPILE_ECPAIRING_PER_POINT

110
    PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000)

PER_BLOB

113
    PER_BLOB = U64(2**17)

BLOB_SCHEDULE_TARGET

114
    BLOB_SCHEDULE_TARGET = U64(14)

BLOB_TARGET_GAS_PER_BLOCK

115
    BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET

BLOB_BASE_COST

116
    BLOB_BASE_COST = Uint(2**13)

BLOB_SCHEDULE_MAX

117
    BLOB_SCHEDULE_MAX = U64(21)

BLOB_MIN_GASPRICE

118
    BLOB_MIN_GASPRICE = Uint(1)

BLOB_BASE_FEE_UPDATE_FRACTION

119
    BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671)

BLOCK_ACCESS_LIST_ITEM

122
    BLOCK_ACCESS_LIST_ITEM = Uint(2000)

TX_BASE

125
    TX_BASE = Uint(21000)

TX_CREATE

126
    TX_CREATE = Uint(9000)

TX_DATA_TOKEN_STANDARD

127
    TX_DATA_TOKEN_STANDARD = Uint(4)

TX_DATA_TOKEN_FLOOR

128
    TX_DATA_TOKEN_FLOOR = Uint(16)

TX_ACCESS_LIST_ADDRESS

129
    TX_ACCESS_LIST_ADDRESS = Uint(2400)

TX_ACCESS_LIST_STORAGE_KEY

130
    TX_ACCESS_LIST_STORAGE_KEY = Uint(1900)

LIMIT_ADJUSTMENT_FACTOR

133
    LIMIT_ADJUSTMENT_FACTOR = Uint(1024)

LIMIT_MINIMUM

134
    LIMIT_MINIMUM = Uint(5000)

OPCODE_ADD

137
    OPCODE_ADD = VERY_LOW

OPCODE_SUB

138
    OPCODE_SUB = VERY_LOW

OPCODE_MUL

139
    OPCODE_MUL = LOW

OPCODE_DIV

140
    OPCODE_DIV = LOW

OPCODE_SDIV

141
    OPCODE_SDIV = LOW

OPCODE_MOD

142
    OPCODE_MOD = LOW

OPCODE_SMOD

143
    OPCODE_SMOD = LOW

OPCODE_ADDMOD

144
    OPCODE_ADDMOD = MID

OPCODE_MULMOD

145
    OPCODE_MULMOD = MID

OPCODE_SIGNEXTEND

146
    OPCODE_SIGNEXTEND = LOW

OPCODE_LT

147
    OPCODE_LT = VERY_LOW

OPCODE_GT

148
    OPCODE_GT = VERY_LOW

OPCODE_SLT

149
    OPCODE_SLT = VERY_LOW

OPCODE_SGT

150
    OPCODE_SGT = VERY_LOW

OPCODE_EQ

151
    OPCODE_EQ = VERY_LOW

OPCODE_ISZERO

152
    OPCODE_ISZERO = VERY_LOW

OPCODE_AND

153
    OPCODE_AND = VERY_LOW

OPCODE_OR

154
    OPCODE_OR = VERY_LOW

OPCODE_XOR

155
    OPCODE_XOR = VERY_LOW

OPCODE_NOT

156
    OPCODE_NOT = VERY_LOW

OPCODE_BYTE

157
    OPCODE_BYTE = VERY_LOW

OPCODE_SHL

158
    OPCODE_SHL = VERY_LOW

OPCODE_SHR

159
    OPCODE_SHR = VERY_LOW

OPCODE_SAR

160
    OPCODE_SAR = VERY_LOW

OPCODE_CLZ

161
    OPCODE_CLZ = LOW

OPCODE_JUMP

162
    OPCODE_JUMP = MID

OPCODE_JUMPI

163
    OPCODE_JUMPI = HIGH

OPCODE_JUMPDEST

164
    OPCODE_JUMPDEST = Uint(1)

OPCODE_CALLDATALOAD

165
    OPCODE_CALLDATALOAD = VERY_LOW

OPCODE_BLOCKHASH

166
    OPCODE_BLOCKHASH = Uint(20)

OPCODE_COINBASE

167
    OPCODE_COINBASE = BASE

OPCODE_POP

168
    OPCODE_POP = BASE

OPCODE_MSIZE

169
    OPCODE_MSIZE = BASE

OPCODE_PC

170
    OPCODE_PC = BASE

OPCODE_GAS

171
    OPCODE_GAS = BASE

OPCODE_ADDRESS

172
    OPCODE_ADDRESS = BASE

OPCODE_ORIGIN

173
    OPCODE_ORIGIN = BASE

OPCODE_CALLER

174
    OPCODE_CALLER = BASE

OPCODE_CALLVALUE

175
    OPCODE_CALLVALUE = BASE

OPCODE_CALLDATASIZE

176
    OPCODE_CALLDATASIZE = BASE

OPCODE_CODESIZE

177
    OPCODE_CODESIZE = BASE

OPCODE_GASPRICE

178
    OPCODE_GASPRICE = BASE

OPCODE_TIMESTAMP

179
    OPCODE_TIMESTAMP = BASE

OPCODE_NUMBER

180
    OPCODE_NUMBER = BASE

OPCODE_GASLIMIT

181
    OPCODE_GASLIMIT = BASE

OPCODE_PREVRANDAO

182
    OPCODE_PREVRANDAO = BASE

OPCODE_RETURNDATASIZE

183
    OPCODE_RETURNDATASIZE = BASE

OPCODE_CHAINID

184
    OPCODE_CHAINID = BASE

OPCODE_BASEFEE

185
    OPCODE_BASEFEE = BASE

OPCODE_BLOBBASEFEE

186
    OPCODE_BLOBBASEFEE = BASE

OPCODE_SLOTNUM

187
    OPCODE_SLOTNUM = BASE

OPCODE_BLOBHASH

188
    OPCODE_BLOBHASH = Uint(3)

OPCODE_PUSH

189
    OPCODE_PUSH = VERY_LOW

OPCODE_PUSH0

190
    OPCODE_PUSH0 = BASE

OPCODE_DUP

191
    OPCODE_DUP = VERY_LOW

OPCODE_SWAP

192
    OPCODE_SWAP = VERY_LOW

OPCODE_DUPN

193
    OPCODE_DUPN = VERY_LOW

OPCODE_SWAPN

194
    OPCODE_SWAPN = VERY_LOW

OPCODE_EXCHANGE

195
    OPCODE_EXCHANGE = VERY_LOW

OPCODE_RETURNDATACOPY_BASE

198
    OPCODE_RETURNDATACOPY_BASE = VERY_LOW

OPCODE_RETURNDATACOPY_PER_WORD

199
    OPCODE_RETURNDATACOPY_PER_WORD = Uint(3)

OPCODE_CALLDATACOPY_BASE

200
    OPCODE_CALLDATACOPY_BASE = VERY_LOW

OPCODE_CODECOPY_BASE

201
    OPCODE_CODECOPY_BASE = VERY_LOW

OPCODE_MCOPY_BASE

202
    OPCODE_MCOPY_BASE = VERY_LOW

OPCODE_MLOAD_BASE

203
    OPCODE_MLOAD_BASE = VERY_LOW

OPCODE_MSTORE_BASE

204
    OPCODE_MSTORE_BASE = VERY_LOW

OPCODE_MSTORE8_BASE

205
    OPCODE_MSTORE8_BASE = VERY_LOW

OPCODE_COPY_PER_WORD

206
    OPCODE_COPY_PER_WORD = Uint(3)

OPCODE_CREATE_BASE

207
    OPCODE_CREATE_BASE = Uint(9000)

OPCODE_EXP_BASE

208
    OPCODE_EXP_BASE = Uint(10)

OPCODE_EXP_PER_BYTE

209
    OPCODE_EXP_PER_BYTE = Uint(50)

OPCODE_KECCAK256_BASE

210
    OPCODE_KECCAK256_BASE = Uint(30)

OPCODE_KECCACK256_PER_WORD

211
    OPCODE_KECCACK256_PER_WORD = Uint(6)

OPCODE_LOG_BASE

212
    OPCODE_LOG_BASE = Uint(375)

OPCODE_LOG_DATA_PER_BYTE

213
    OPCODE_LOG_DATA_PER_BYTE = Uint(8)

OPCODE_LOG_TOPIC

214
    OPCODE_LOG_TOPIC = Uint(375)

OPCODE_SELFDESTRUCT_BASE

215
    OPCODE_SELFDESTRUCT_BASE = Uint(5000)

OPCODE_SELFDESTRUCT_NEW_ACCOUNT

216
    OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000)

ExtendMemory

Define the parameters for memory extension in opcodes.

cost: ethereum.base_types.Uint The gas required to perform the extension expand_by: ethereum.base_types.Uint The size by which the memory will be extended

219
@dataclass
class ExtendMemory:

cost

230
    cost: Uint

expand_by

231
    expand_by: Uint

MessageCallGas

Define the gas cost and gas given to the sub-call for executing the call opcodes.

cost: ethereum.base_types.Uint The gas required to execute the call opcode, excludes memory expansion costs. sub_call: ethereum.base_types.Uint The portion of gas available to sub-calls that is refundable if not consumed.

234
@dataclass
class MessageCallGas:

cost

248
    cost: Uint

sub_call

249
    sub_call: Uint

check_gas

Checks if amount gas is available without charging it. Raises OutOfGasError if insufficient gas.

Parameters

evm : The current EVM. amount : The amount of gas to check.

def check_gas(evm: Evm, ​​amount: Uint) -> None:
253
    """
254
    Checks if `amount` gas is available without charging it.
255
    Raises OutOfGasError if insufficient gas.
256
257
    Parameters
258
    ----------
259
    evm :
260
        The current EVM.
261
    amount :
262
        The amount of gas to check.
263
264
    """
265
    if evm.gas_left < amount:
266
        raise OutOfGasError

charge_gas

Subtracts amount from evm.gas_left (regular gas) and records usage.

Parameters

evm : The current EVM. amount : The amount of regular gas the current operation requires.

def charge_gas(evm: Evm, ​​amount: Uint) -> None:
270
    """
271
    Subtracts `amount` from `evm.gas_left` (regular gas) and records usage.
272
273
    Parameters
274
    ----------
275
    evm :
276
        The current EVM.
277
    amount :
278
        The amount of regular gas the current operation requires.
279
280
    """
281
    evm_trace(evm, GasAndRefund(int(amount)))
282
283
    if evm.gas_left < amount:
284
        raise OutOfGasError
285
    evm.gas_left -= amount
286
287
    evm.regular_gas_used += amount

calculate_memory_gas_cost

Calculates the gas cost for allocating memory to the smallest multiple of 32 bytes, such that the allocated size is at least as big as the given size.

Parameters

size_in_bytes : The size of the data in bytes.

Returns

total_gas_cost : ethereum.base_types.Uint The gas cost for storing data in memory.

def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint:
291
    """
292
    Calculates the gas cost for allocating memory
293
    to the smallest multiple of 32 bytes,
294
    such that the allocated size is at least as big as the given size.
295
296
    Parameters
297
    ----------
298
    size_in_bytes :
299
        The size of the data in bytes.
300
301
    Returns
302
    -------
303
    total_gas_cost : `ethereum.base_types.Uint`
304
        The gas cost for storing data in memory.
305
306
    """
307
    size_in_words = ceil32(size_in_bytes) // Uint(32)
308
    linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD
309
    quadratic_cost = size_in_words ** Uint(2) // Uint(512)
310
    total_gas_cost = linear_cost + quadratic_cost
311
    try:
312
        return total_gas_cost
313
    except ValueError as e:
314
        raise OutOfGasError from e

calculate_gas_extend_memory

Calculates the gas amount to extend memory.

Parameters

memory : Memory contents of the EVM. extensions: List of extensions to be made to the memory. Consists of a tuple of start position and size.

Returns

extend_memory: ExtendMemory

def calculate_gas_extend_memory(memory: bytearray, ​​extensions: List[Tuple[U256, U256]]) -> ExtendMemory:
320
    """
321
    Calculates the gas amount to extend memory.
322
323
    Parameters
324
    ----------
325
    memory :
326
        Memory contents of the EVM.
327
    extensions:
328
        List of extensions to be made to the memory.
329
        Consists of a tuple of start position and size.
330
331
    Returns
332
    -------
333
    extend_memory: `ExtendMemory`
334
335
    """
336
    size_to_extend = Uint(0)
337
    to_be_paid = Uint(0)
338
    current_size = ulen(memory)
339
    for start_position, size in extensions:
340
        if size == 0:
341
            continue
342
        before_size = ceil32(current_size)
343
        after_size = ceil32(Uint(start_position) + Uint(size))
344
        if after_size <= before_size:
345
            continue
346
347
        size_to_extend += after_size - before_size
348
        already_paid = calculate_memory_gas_cost(before_size)
349
        total_cost = calculate_memory_gas_cost(after_size)
350
        to_be_paid += total_cost - already_paid
351
352
        current_size = after_size
353
354
    return ExtendMemory(to_be_paid, size_to_extend)

calculate_message_call_gas

Calculates the MessageCallGas (cost and gas made available to the sub-call) for executing call Opcodes.

Parameters

value: The amount of ETH that needs to be transferred. gas : The amount of gas provided to the message-call. gas_left : The amount of gas left in the current frame. memory_cost : The amount needed to extend the memory in the current frame. extra_gas : The amount of gas needed for transferring value + creating a new account inside a message call. call_stipend : The amount of stipend provided to a message call to execute code while transferring value (ETH).

Returns

message_call_gas: MessageCallGas

def calculate_message_call_gas(value: U256, ​​gas: Uint, ​​gas_left: Uint, ​​memory_cost: Uint, ​​extra_gas: Uint, ​​call_stipend: Uint) -> MessageCallGas:
365
    """
366
    Calculates the MessageCallGas (cost and gas made available to the sub-call)
367
    for executing call Opcodes.
368
369
    Parameters
370
    ----------
371
    value:
372
        The amount of `ETH` that needs to be transferred.
373
    gas :
374
        The amount of gas provided to the message-call.
375
    gas_left :
376
        The amount of gas left in the current frame.
377
    memory_cost :
378
        The amount needed to extend the memory in the current frame.
379
    extra_gas :
380
        The amount of gas needed for transferring value + creating a new
381
        account inside a message call.
382
    call_stipend :
383
        The amount of stipend provided to a message call to execute code while
384
        transferring value (ETH).
385
386
    Returns
387
    -------
388
    message_call_gas: `MessageCallGas`
389
390
    """
391
    call_stipend = Uint(0) if value == 0 else call_stipend
392
    if gas_left < extra_gas + memory_cost:
393
        return MessageCallGas(gas + extra_gas, gas + call_stipend)
394
395
    gas = min(gas, max_message_call_gas(gas_left - memory_cost - extra_gas))
396
397
    return MessageCallGas(gas + extra_gas, gas + call_stipend)

max_message_call_gas

Calculates the maximum gas that is allowed for making a message call.

Parameters

gas : The amount of gas provided to the message-call.

Returns

max_allowed_message_call_gas: ethereum.base_types.Uint The maximum gas allowed for making the message-call.

def max_message_call_gas(gas: Uint) -> Uint:
401
    """
402
    Calculates the maximum gas that is allowed for making a message call.
403
404
    Parameters
405
    ----------
406
    gas :
407
        The amount of gas provided to the message-call.
408
409
    Returns
410
    -------
411
    max_allowed_message_call_gas: `ethereum.base_types.Uint`
412
        The maximum gas allowed for making the message-call.
413
414
    """
415
    return gas - (gas // Uint(64))

init_code_cost

Calculates the gas to be charged for the init code in CREATE* opcodes as well as create transactions.

Parameters

init_code_length : The length of the init code provided to the opcode or a create transaction

Returns

init_code_gas: ethereum.base_types.Uint The gas to be charged for the init code.

def init_code_cost(init_code_length: Uint) -> Uint:
419
    """
420
    Calculates the gas to be charged for the init code in CREATE*
421
    opcodes as well as create transactions.
422
423
    Parameters
424
    ----------
425
    init_code_length :
426
        The length of the init code provided to the opcode
427
        or a create transaction
428
429
    Returns
430
    -------
431
    init_code_gas: `ethereum.base_types.Uint`
432
        The gas to be charged for the init code.
433
434
    """
435
    return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32)

calculate_excess_blob_gas

Calculates the excess blob gas for the current block based on the gas used in the parent block.

Parameters

parent_header : The parent block of the current block.

Returns

excess_blob_gas: ethereum.base_types.U64 The excess blob gas for the current block.

def calculate_excess_blob_gas(parent_header: Header | PreviousHeader) -> U64:
441
    """
442
    Calculates the excess blob gas for the current block based
443
    on the gas used in the parent block.
444
445
    Parameters
446
    ----------
447
    parent_header :
448
        The parent block of the current block.
449
450
    Returns
451
    -------
452
    excess_blob_gas: `ethereum.base_types.U64`
453
        The excess blob gas for the current block.
454
455
    """
456
    # At the fork block, these are defined as zero.
457
    excess_blob_gas = U64(0)
458
    blob_gas_used = U64(0)
459
    base_fee_per_gas = Uint(0)
460
461
    if isinstance(parent_header, Header):
462
        # After the fork block, read them from the parent header.
463
        excess_blob_gas = parent_header.excess_blob_gas
464
        blob_gas_used = parent_header.blob_gas_used
465
        base_fee_per_gas = parent_header.base_fee_per_gas
466
467
    parent_blob_gas = excess_blob_gas + blob_gas_used
468
    if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK:
469
        return U64(0)
470
471
    target_blob_gas_price = Uint(GasCosts.PER_BLOB)
472
    target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas)
473
474
    base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas
475
    if base_blob_tx_price > target_blob_gas_price:
476
        blob_schedule_delta = (
477
            GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET
478
        )
479
        return (
480
            excess_blob_gas
481
            + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX
482
        )
483
484
    return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK

calculate_total_blob_gas

Calculate the total blob gas for a transaction.

Parameters

tx : The transaction for which the blob gas is to be calculated.

Returns

total_blob_gas: ethereum.base_types.Uint The total blob gas for the transaction.

def calculate_total_blob_gas(tx: Transaction) -> U64:
488
    """
489
    Calculate the total blob gas for a transaction.
490
491
    Parameters
492
    ----------
493
    tx :
494
        The transaction for which the blob gas is to be calculated.
495
496
    Returns
497
    -------
498
    total_blob_gas: `ethereum.base_types.Uint`
499
        The total blob gas for the transaction.
500
501
    """
502
    if isinstance(tx, BlobTransaction):
503
        return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes))
504
    else:
505
        return U64(0)

calculate_blob_gas_price

Calculate the blob gasprice for a block.

Parameters

excess_blob_gas : The excess blob gas for the block.

Returns

blob_gasprice: Uint The blob gasprice.

def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint:
509
    """
510
    Calculate the blob gasprice for a block.
511
512
    Parameters
513
    ----------
514
    excess_blob_gas :
515
        The excess blob gas for the block.
516
517
    Returns
518
    -------
519
    blob_gasprice: `Uint`
520
        The blob gasprice.
521
522
    """
523
    return taylor_exponential(
524
        GasCosts.BLOB_MIN_GASPRICE,
525
        Uint(excess_blob_gas),
526
        GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION,
527
    )

calculate_data_fee

Calculate the blob data fee for a transaction.

Parameters

excess_blob_gas : The excess_blob_gas for the execution. tx : The transaction for which the blob data fee is to be calculated.

Returns

data_fee: Uint The blob data fee.

def calculate_data_fee(excess_blob_gas: U64, ​​tx: Transaction) -> Uint:
531
    """
532
    Calculate the blob data fee for a transaction.
533
534
    Parameters
535
    ----------
536
    excess_blob_gas :
537
        The excess_blob_gas for the execution.
538
    tx :
539
        The transaction for which the blob data fee is to be calculated.
540
541
    Returns
542
    -------
543
    data_fee: `Uint`
544
        The blob data fee.
545
546
    """
547
    return Uint(calculate_total_blob_gas(tx)) * calculate_blob_gas_price(
548
        excess_blob_gas
549
    )