ethereum.forks.bogota.vm.instructions.frame

Implementations of the EVM instructions defined only during the execution of an EIP-8141 frame transaction. Executing any of them in the context of any other transaction type results in an exceptional halt.

TransactionParameter

Values of the TXPARAM parameter operand.

32
@final
class TransactionParameter:

TYPE

38
    TYPE = Uint(0x00)

NONCE

39
    NONCE = Uint(0x01)

SENDER

40
    SENDER = Uint(0x02)

MAX_PRIORITY_FEE_PER_GAS

41
    MAX_PRIORITY_FEE_PER_GAS = Uint(0x03)

MAX_FEE

42
    MAX_FEE = Uint(0x04)

BLOB_COUNT

43
    BLOB_COUNT = Uint(0x07)

SIG_HASH

44
    SIG_HASH = Uint(0x08)

FRAME_COUNT

45
    FRAME_COUNT = Uint(0x09)

CURRENT_FRAME_INDEX

46
    CURRENT_FRAME_INDEX = Uint(0x0A)

SIGNATURE_COUNT

47
    SIGNATURE_COUNT = Uint(0x0B)

STATE_GAS_LEFT

48
    STATE_GAS_LEFT = Uint(0x0C)

FrameParameter

Values of the FRAMEPARAM parameter operand.

51
@final
class FrameParameter:

RESOLVED_TARGET

57
    RESOLVED_TARGET = Uint(0x00)

EXECUTION_GAS_LIMIT

58
    EXECUTION_GAS_LIMIT = Uint(0x01)

MODE

59
    MODE = Uint(0x02)

FLAGS

60
    FLAGS = Uint(0x03)

DATA_LENGTH

61
    DATA_LENGTH = Uint(0x04)

STATUS

62
    STATUS = Uint(0x05)

ALLOWED_SCOPE

63
    ALLOWED_SCOPE = Uint(0x06)

ATOMIC_BATCH

64
    ATOMIC_BATCH = Uint(0x07)

VALUE

65
    VALUE = Uint(0x08)

STATE_GAS_LIMIT

66
    STATE_GAS_LIMIT = Uint(0x09)

EXECUTION_GAS_USED

67
    EXECUTION_GAS_USED = Uint(0x0A)

STATE_GAS_USED

68
    STATE_GAS_USED = Uint(0x0B)

SignatureParameter

Values of the SIGPARAM parameter operand.

71
@final
class SignatureParameter:

RESOLVED_SIGNER

77
    RESOLVED_SIGNER = Uint(0x00)

SCHEME

78
    SCHEME = Uint(0x01)

MSG

79
    MSG = Uint(0x02)

SIGNATURE_LENGTH

80
    SIGNATURE_LENGTH = Uint(0x03)

frame_transaction_context

Return the executing frame transaction's context, or exceptionally halt when the current transaction is not a frame transaction.

def frame_transaction_context(​evm: Evm​) -> FrameContext:
84
    <snip>
88
    frame_context = evm.tx_env.frame_context
89
    if frame_context is None:
90
        raise InvalidParameter("not a frame transaction")
91
    return frame_context

approve

Exit the current call frame successfully, updating the transaction-scoped approval context based on the scope operand.

The memory region designated by the offset and length operands becomes the call frame's return data, following RETURN semantics — only the memory expansion is charged. A refused approval — an ADDRESS other than the frame's resolved target, a scope outside the frame's allowed flags, or a failed precondition — reverts the current call frame, not the whole frame: a caller that handles the revert carries on. The approval's writes deliberately bypass the VERIFY static restriction: only APPROVE may mutate state there.

def approve(​evm: Evm​) -> None:
95
    <snip>
109
    # STACK
110
    offset = pop(evm.stack)
111
    length = pop(evm.stack)
112
    scope = pop(evm.stack)
113
114
    # GAS
115
    extend_memory = calculate_gas_extend_memory(evm.memory, [(offset, length)])
116
    charge_gas(evm, GasCosts.ZERO + extend_memory.cost)
117
118
    # OPERATION
119
    frame_context = frame_transaction_context(evm)
120
    tx = frame_context.tx
121
    frame = tx.frames[int(frame_context.current_frame_index)]
122
    resolved_target = resolve_frame_target(tx, frame)
123
124
    evm.memory += b"\x00" * extend_memory.expand_by
125
126
    # Only the frame's resolved target may approve.
127
    if evm.current_target != resolved_target:
128
        raise Revert
129
    # A scope with bits beyond the approval mask is never allowed.
130
    if scope & ~U256(APPROVE_SCOPE_MASK) != U256(0):
131
        raise Revert
132
    if not attempt_approval(evm.tx_env, FrameFlag(Uint(scope))):
133
        raise Revert
134
135
    evm.output = Bytes(memory_read_bytes(evm.memory, offset, length))
136
    evm.running = False
137
138
    # PROGRAM COUNTER
139
    pass

txparam

Push transaction-scoped information of the executing frame transaction onto the stack, selected by the parameter operand.

def txparam(​evm: Evm​) -> None:
143
    <snip>
147
    # STACK
148
    param = pop(evm.stack)
149
150
    # GAS
151
    charge_gas(evm, GasCosts.OPCODE_TXPARAM)
152
153
    # OPERATION
154
    frame_context = frame_transaction_context(evm)
155
    tx = frame_context.tx
156
157
    if param == TransactionParameter.TYPE:
158
        # The frame transaction's type identifier.
159
        value = U256(0x06)
160
    elif param == TransactionParameter.NONCE:
161
        value = U256(tx.nonce)
162
    elif param == TransactionParameter.SENDER:
163
        value = U256.from_be_bytes(tx.sender)
164
    elif param == TransactionParameter.MAX_PRIORITY_FEE_PER_GAS:
165
        value = U256(tx.fees.max_priority_fee_per_gas)
166
    elif param == TransactionParameter.MAX_FEE:
167
        value = U256(tx.fees.max_fee)
168
    elif param == TransactionParameter.BLOB_COUNT:
169
        value = U256(len(tx.blob_versioned_hashes))
170
    elif param == TransactionParameter.SIG_HASH:
171
        value = U256.from_be_bytes(frame_context.signature_hash)
172
    elif param == TransactionParameter.FRAME_COUNT:
173
        value = U256(len(tx.frames))
174
    elif param == TransactionParameter.CURRENT_FRAME_INDEX:
175
        value = U256(frame_context.current_frame_index)
176
    elif param == TransactionParameter.SIGNATURE_COUNT:
177
        value = U256(len(tx.signatures))
178
    elif param == TransactionParameter.STATE_GAS_LEFT:
179
        # State gas remaining in the executing frame's pool.
180
        value = U256(frame_context.state_gas_left)
181
    else:
182
        raise InvalidParameter("undefined TXPARAM parameter")
183
184
    push(evm.stack, value)
185
186
    # PROGRAM COUNTER
187
    evm.pc += Uint(1)

framedataload

Push a word (32 bytes) of the chosen frame's data onto the stack.

The operation semantics match CALLDATALOAD: bytes beyond the end of the frame's data read as zeroes.

def framedataload(​evm: Evm​) -> None:
191
    <snip>
197
    # STACK
198
    offset = pop(evm.stack)
199
    frame_index = pop(evm.stack)
200
201
    # GAS
202
    charge_gas(evm, GasCosts.OPCODE_FRAMEDATALOAD)
203
204
    # OPERATION
205
    frame_context = frame_transaction_context(evm)
206
    frames = frame_context.tx.frames
207
    if frame_index >= U256(len(frames)):
208
        raise InvalidParameter("frame index out of bounds")
209
    data = frames[int(frame_index)].data
210
211
    value = buffer_read(data, offset, U256(32))
212
    push(evm.stack, U256.from_be_bytes(value))
213
214
    # PROGRAM COUNTER
215
    evm.pc += Uint(1)

framedatacopy

Copy a portion of the chosen frame's data to memory.

The operation semantics and gas match CALLDATACOPY: bytes beyond the end of the frame's data are copied as zeroes, and the memory is expanded as needed.

def framedatacopy(​evm: Evm​) -> None:
219
    <snip>
226
    # STACK
227
    memory_offset = pop(evm.stack)
228
    data_offset = pop(evm.stack)
229
    length = pop(evm.stack)
230
    frame_index = pop(evm.stack)
231
232
    # GAS
233
    words = ceil32(Uint(length)) // Uint(32)
234
    copy_gas_cost = ExecutionGas(GasCosts.OPCODE_COPY_PER_WORD * words)
235
    extend_memory = calculate_gas_extend_memory(
236
        evm.memory, [(memory_offset, length)]
237
    )
238
    charge_gas(
239
        evm,
240
        GasCosts.OPCODE_FRAMEDATACOPY_BASE
241
        + copy_gas_cost
242
        + extend_memory.cost,
243
    )
244
245
    # OPERATION
246
    frame_context = frame_transaction_context(evm)
247
    frames = frame_context.tx.frames
248
    if frame_index >= U256(len(frames)):
249
        raise InvalidParameter("frame index out of bounds")
250
    data = frames[int(frame_index)].data
251
252
    evm.memory += b"\x00" * extend_memory.expand_by
253
    value = buffer_read(data, data_offset, length)
254
    memory_write(evm.memory, memory_offset, value)
255
256
    # PROGRAM COUNTER
257
    evm.pc += Uint(1)

frameparam

Push frame-scoped information of the chosen frame onto the stack, selected by the parameter operand.

A frame's status and gas usage are read from its receipt, which exists only once the frame has completed: requesting them for the current or a subsequent frame results in an exceptional halt. The receipt values are live, not final — a completed frame's state gas usage decreases when a later frame refills a state charge attributed to it, and is restored when that refill rolls back.

def frameparam(​evm: Evm​) -> None:
261
    <snip>
272
    # STACK
273
    frame_index = pop(evm.stack)
274
    param = pop(evm.stack)
275
276
    # GAS
277
    charge_gas(evm, GasCosts.OPCODE_FRAMEPARAM)
278
279
    # OPERATION
280
    frame_context = frame_transaction_context(evm)
281
    tx = frame_context.tx
282
    if frame_index >= U256(len(tx.frames)):
283
        raise InvalidParameter("frame index out of bounds")
284
    frame = tx.frames[int(frame_index)]
285
286
    if param == FrameParameter.RESOLVED_TARGET:
287
        value = U256.from_be_bytes(resolve_frame_target(tx, frame))
288
    elif param == FrameParameter.EXECUTION_GAS_LIMIT:
289
        value = U256(frame.gas_limits.execution)
290
    elif param == FrameParameter.MODE:
291
        value = U256(frame.mode)
292
    elif param == FrameParameter.FLAGS:
293
        value = U256(frame.flags)
294
    elif param == FrameParameter.DATA_LENGTH:
295
        value = U256(len(frame.data))
296
    elif param == FrameParameter.STATUS:
297
        if frame_index >= U256(frame_context.current_frame_index):
298
            raise InvalidParameter(
299
                "status of the current or a subsequent frame"
300
            )
301
        receipt = frame_context.frame_receipts[int(frame_index)]
302
        value = U256(receipt.status)
303
    elif param == FrameParameter.ALLOWED_SCOPE:
304
        value = U256(frame.flags & APPROVE_SCOPE_MASK)
305
    elif param == FrameParameter.ATOMIC_BATCH:
306
        if FrameFlag.ATOMIC_BATCH in frame.flags:
307
            value = U256(1)
308
        else:
309
            value = U256(0)
310
    elif param == FrameParameter.VALUE:
311
        value = frame.value
312
    elif param == FrameParameter.STATE_GAS_LIMIT:
313
        value = U256(frame.gas_limits.state)
314
    elif param == FrameParameter.EXECUTION_GAS_USED:
315
        if frame_index >= U256(frame_context.current_frame_index):
316
            raise InvalidParameter(
317
                "gas usage of the current or a subsequent frame"
318
            )
319
        receipt = frame_context.frame_receipts[int(frame_index)]
320
        value = U256(receipt.gas_used.execution)
321
    elif param == FrameParameter.STATE_GAS_USED:
322
        if frame_index >= U256(frame_context.current_frame_index):
323
            raise InvalidParameter(
324
                "gas usage of the current or a subsequent frame"
325
            )
326
        receipt = frame_context.frame_receipts[int(frame_index)]
327
        value = U256(receipt.gas_used.state)
328
    else:
329
        raise InvalidParameter("undefined FRAMEPARAM parameter")
330
331
    push(evm.stack, value)
332
333
    # PROGRAM COUNTER
334
    evm.pc += Uint(1)

sigparam

Push signature-scoped metadata of the chosen signature entry onto the stack, selected by the parameter operand.

Each scheme family withholds the metadata the protocol does not define for it: the resolved signer is available only for protocol-validated entries, to which the protocol assigns one, and the signature byte length only for ARBITRARY entries — the raw signature bytes of protocol-validated schemes, including their length, are not introspectable.

def sigparam(​evm: Evm​) -> None:
338
    <snip>
349
    # STACK
350
    signature_index = pop(evm.stack)
351
    param = pop(evm.stack)
352
353
    # GAS
354
    charge_gas(evm, GasCosts.OPCODE_SIGPARAM)
355
356
    # OPERATION
357
    frame_context = frame_transaction_context(evm)
358
    signatures = frame_context.tx.signatures
359
    if signature_index >= U256(len(signatures)):
360
        raise InvalidParameter("signature index out of bounds")
361
    signature = signatures[int(signature_index)]
362
363
    if param == SignatureParameter.RESOLVED_SIGNER:
364
        resolved_signer = frame_context.resolved_signers[int(signature_index)]
365
        if resolved_signer is None:
366
            raise InvalidParameter("resolved signer of an ARBITRARY entry")
367
        value = U256.from_be_bytes(resolved_signer)
368
    elif param == SignatureParameter.SCHEME:
369
        value = U256(signature.scheme)
370
    elif param == SignatureParameter.MSG:
371
        if len(signature.message) == 0:
372
            value = U256(0)
373
        else:
374
            value = U256.from_be_bytes(signature.message)
375
    elif param == SignatureParameter.SIGNATURE_LENGTH:
376
        if signature.scheme != FrameSignatureScheme.ARBITRARY:
377
            raise InvalidParameter(
378
                "signature length of a protocol-validated scheme"
379
            )
380
        value = U256(len(signature.signature))
381
    else:
382
        raise InvalidParameter("undefined SIGPARAM parameter")
383
384
    push(evm.stack, value)
385
386
    # PROGRAM COUNTER
387
    evm.pc += Uint(1)

sigdatacopy

Copy a portion of the chosen signature entry's raw signature bytes to memory.

The copy is defined only for ARBITRARY entries, whose bytes the protocol does not validate; the raw signature bytes of protocol-validated schemes are intentionally not accessible. The operation semantics and gas match CALLDATACOPY: bytes beyond the end of the signature are copied as zeroes, and the memory is expanded as needed.

def sigdatacopy(​evm: Evm​) -> None:
391
    <snip>
402
    # STACK
403
    memory_offset = pop(evm.stack)
404
    data_offset = pop(evm.stack)
405
    length = pop(evm.stack)
406
    signature_index = pop(evm.stack)
407
408
    # GAS
409
    words = ceil32(Uint(length)) // Uint(32)
410
    copy_gas_cost = ExecutionGas(GasCosts.OPCODE_COPY_PER_WORD * words)
411
    extend_memory = calculate_gas_extend_memory(
412
        evm.memory, [(memory_offset, length)]
413
    )
414
    charge_gas(
415
        evm,
416
        GasCosts.OPCODE_SIGDATACOPY_BASE + copy_gas_cost + extend_memory.cost,
417
    )
418
419
    # OPERATION
420
    frame_context = frame_transaction_context(evm)
421
    signatures = frame_context.tx.signatures
422
    if signature_index >= U256(len(signatures)):
423
        raise InvalidParameter("signature index out of bounds")
424
    signature = signatures[int(signature_index)]
425
    if signature.scheme != FrameSignatureScheme.ARBITRARY:
426
        raise InvalidParameter(
427
            "signature bytes of a protocol-validated scheme"
428
        )
429
430
    evm.memory += b"\x00" * extend_memory.expand_by
431
    signature_bytes = buffer_read(signature.signature, data_offset, length)
432
    memory_write(evm.memory, memory_offset, signature_bytes)
433
434
    # PROGRAM COUNTER
435
    evm.pc += Uint(1)