ethereum.forks.bpo5.vm.instructions.systemethereum.forks.amsterdam.vm.instructions.system

Ethereum Virtual Machine (EVM) System Instructions.

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

Introduction

Implementations of the EVM system related instructions.

generic_create

Core logic used by the CREATE* family of opcodes.

def generic_create(evm: Evm, ​​endowment: U256, ​​contract_address: Address, ​​memory_start_position: U256, ​​memory_size: U256) -> None:
68
    <snip>
71
    # This import causes a circular import error
72
    # if it's not moved inside this method
73
    from ...vm.interpreter import (
74
        MAX_INIT_CODE_SIZE,
75
        STACK_DEPTH_LIMIT,
76
        process_create_message,
77
    )
78
79
    # Check static context first
80
    if evm.message.is_static:
81
        raise WriteInStaticContext
82
83
    # Check max init code size early before memory read
84
    if memory_size > U256(MAX_INIT_CODE_SIZE):
85
        raise OutOfGasError
86
87
    tx_state = evm.message.tx_env.state
88
89
    call_data = memory_read_bytes(
90
        evm.memory, memory_start_position, memory_size
91
    )
75
    if len(call_data) > MAX_INIT_CODE_SIZE:
76
        raise OutOfGasError
92
93
    create_message_gas = max_message_call_gas(Uint(evm.gas_left))
94
    evm.gas_left -= create_message_gas
80
    if evm.message.is_static:
81
        raise WriteInStaticContext
95
    evm.return_data = b""
96
97
    sender_address = evm.message.current_target
85
    sender = get_account(evm.message.tx_env.state, sender_address)
98
    sender = get_account(tx_state, sender_address)
99
100
    if (
101
        sender.balance < endowment
102
        or sender.nonce == Uint(2**64 - 1)
103
        or evm.message.depth + Uint(1) > STACK_DEPTH_LIMIT
104
    ):
105
        evm.gas_left += create_message_gas
106
        push(evm.stack, U256(0))
107
        return
108
109
    evm.accessed_addresses.add(contract_address)
110
111
    if account_has_code_or_nonce(
99
        evm.message.tx_env.state, contract_address
100
    ) or account_has_storage(evm.message.tx_env.state, contract_address):
101
        increment_nonce(evm.message.tx_env.state, evm.message.current_target)
112
        tx_state, contract_address
113
    ) or account_has_storage(tx_state, contract_address):
114
        increment_nonce(tx_state, evm.message.current_target)
115
        push(evm.stack, U256(0))
116
        return
117
105
    increment_nonce(evm.message.tx_env.state, evm.message.current_target)
118
    increment_nonce(tx_state, evm.message.current_target)
119
120
    child_message = Message(
121
        block_env=evm.message.block_env,
122
        tx_env=evm.message.tx_env,
123
        caller=evm.message.current_target,
124
        target=Bytes0(),
125
        gas=create_message_gas,
126
        value=endowment,
127
        data=b"",
128
        code=call_data,
129
        current_target=contract_address,
130
        depth=evm.message.depth + Uint(1),
131
        code_address=None,
132
        should_transfer_value=True,
133
        is_static=False,
134
        accessed_addresses=evm.accessed_addresses.copy(),
135
        accessed_storage_keys=evm.accessed_storage_keys.copy(),
136
        disable_precompiles=False,
137
        parent_evm=evm,
138
    )
139
    child_evm = process_create_message(child_message)
140
141
    if child_evm.error:
142
        incorporate_child_on_error(evm, child_evm)
143
        evm.return_data = child_evm.output
144
        push(evm.stack, U256(0))
145
    else:
146
        incorporate_child_on_success(evm, child_evm)
147
        evm.return_data = b""
148
        push(evm.stack, U256.from_be_bytes(child_evm.message.current_target))

create

Creates a new account with associated code.

Parameters

evm : The current EVM frame.

def create(evm: Evm) -> None:
152
    <snip>
161
    # STACK
162
    endowment = pop(evm.stack)
163
    memory_start_position = pop(evm.stack)
164
    memory_size = pop(evm.stack)
165
166
    # GAS
167
    extend_memory = calculate_gas_extend_memory(
168
        evm.memory, [(memory_start_position, memory_size)]
169
    )
170
    init_code_gas = init_code_cost(Uint(memory_size))
171
172
    charge_gas(
160
        evm,
161
        GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas,
173
        evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas
174
    )
175
176
    # OPERATION
177
    evm.memory += b"\x00" * extend_memory.expand_by
178
    contract_address = compute_contract_address(
179
        evm.message.current_target,
180
        get_account(
181
            evm.message.tx_env.state, evm.message.current_target
182
        ).nonce,
183
    )
184
185
    generic_create(
186
        evm,
187
        endowment,
188
        contract_address,
189
        memory_start_position,
190
        memory_size,
191
    )
192
193
    # PROGRAM COUNTER
194
    evm.pc += Uint(1)

create2

Creates a new account with associated code.

It's similar to the CREATE opcode except that the address of the new account depends on the init_code instead of the nonce of sender.

Parameters

evm : The current EVM frame.

def create2(evm: Evm) -> None:
198
    <snip>
210
    # STACK
211
    endowment = pop(evm.stack)
212
    memory_start_position = pop(evm.stack)
213
    memory_size = pop(evm.stack)
214
    salt = pop(evm.stack).to_be_bytes32()
215
216
    # GAS
217
    extend_memory = calculate_gas_extend_memory(
218
        evm.memory, [(memory_start_position, memory_size)]
219
    )
220
    call_data_words = ceil32(Uint(memory_size)) // Uint(32)
221
    init_code_gas = init_code_cost(Uint(memory_size))
222
    charge_gas(
223
        evm,
224
        GasCosts.OPCODE_CREATE_BASE
225
        + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words
226
        + extend_memory.cost
227
        + init_code_gas,
228
    )
229
230
    # OPERATION
231
    evm.memory += b"\x00" * extend_memory.expand_by
232
    contract_address = compute_create2_contract_address(
233
        evm.message.current_target,
234
        salt,
235
        memory_read_bytes(evm.memory, memory_start_position, memory_size),
236
    )
237
238
    generic_create(
239
        evm,
240
        endowment,
241
        contract_address,
242
        memory_start_position,
243
        memory_size,
244
    )
245
246
    # PROGRAM COUNTER
247
    evm.pc += Uint(1)

return_

Halts execution returning output data.

Parameters

evm : The current EVM frame.

def return_(evm: Evm) -> None:
251
    <snip>
260
    # STACK
261
    memory_start_position = pop(evm.stack)
262
    memory_size = pop(evm.stack)
263
264
    # GAS
265
    extend_memory = calculate_gas_extend_memory(
266
        evm.memory, [(memory_start_position, memory_size)]
267
    )
268
269
    charge_gas(evm, GasCosts.ZERO + extend_memory.cost)
270
271
    # OPERATION
272
    evm.memory += b"\x00" * extend_memory.expand_by
273
    evm.output = memory_read_bytes(
274
        evm.memory, memory_start_position, memory_size
275
    )
276
277
    evm.running = False
278
279
    # PROGRAM COUNTER
280
    pass

generic_call

Perform the core logic of the CALL* family of opcodes.

def generic_call(evm: Evm, ​​gas: Uint, ​​value: U256, ​​caller: Address, ​​to: Address, ​​code_address: Address, ​​should_transfer_value: bool, ​​is_staticcall: bool, ​​memory_input_start_position: U256, ​​memory_input_size: U256, ​​memory_output_start_position: U256, ​​memory_output_size: U256, ​​code: Bytes, ​​disable_precompiles: bool) -> None:
298
    <snip>
301
    from ...vm.interpreter import STACK_DEPTH_LIMIT, process_message
302
303
    evm.return_data = b""
304
305
    if evm.message.depth + Uint(1) > STACK_DEPTH_LIMIT:
306
        evm.gas_left += gas
307
        push(evm.stack, U256(0))
308
        return
309
310
    tx_state = evm.message.tx_env.state
311
    code_hash = get_account(tx_state, code_address).code_hash
312
    code = get_code(tx_state, code_hash)
313
314
    call_data = memory_read_bytes(
315
        evm.memory, memory_input_start_position, memory_input_size
316
    )
317
318
    child_message = Message(
319
        block_env=evm.message.block_env,
320
        tx_env=evm.message.tx_env,
321
        caller=caller,
322
        target=to,
323
        gas=gas,
324
        value=value,
325
        data=call_data,
326
        code=code,
327
        current_target=to,
328
        depth=evm.message.depth + Uint(1),
329
        code_address=code_address,
330
        should_transfer_value=should_transfer_value,
331
        is_static=True if is_staticcall else evm.message.is_static,
332
        accessed_addresses=evm.accessed_addresses.copy(),
333
        accessed_storage_keys=evm.accessed_storage_keys.copy(),
334
        disable_precompiles=disable_precompiles,
335
        parent_evm=evm,
336
    )
337
338
    child_evm = process_message(child_message)
339
340
    if child_evm.error:
341
        incorporate_child_on_error(evm, child_evm)
342
        evm.return_data = child_evm.output
343
        push(evm.stack, U256(0))
344
    else:
345
        incorporate_child_on_success(evm, child_evm)
346
        evm.return_data = child_evm.output
331
        push(evm.stack, U256(1))
347
        push(evm.stack, CALL_SUCCESS)
348
349
    actual_output_size = min(memory_output_size, U256(len(child_evm.output)))
350
    memory_write(
351
        evm.memory,
352
        memory_output_start_position,
353
        child_evm.output[:actual_output_size],
354
    )

call

Message-call into an account.

Parameters

evm : The current EVM frame.

def call(evm: Evm) -> None:
358
    <snip>
367
    # STACK
368
    gas = Uint(pop(evm.stack))
369
    to = to_address_masked(pop(evm.stack))
370
    value = pop(evm.stack)
371
    memory_input_start_position = pop(evm.stack)
372
    memory_input_size = pop(evm.stack)
373
    memory_output_start_position = pop(evm.stack)
374
    memory_output_size = pop(evm.stack)
375
376
    if evm.message.is_static and value != U256(0):
377
        raise WriteInStaticContext
378
379
    # GAS
380
    extend_memory = calculate_gas_extend_memory(
381
        evm.memory,
382
        [
383
            (memory_input_start_position, memory_input_size),
384
            (memory_output_start_position, memory_output_size),
385
        ],
386
    )
387
369
    if to in evm.accessed_addresses:
370
        access_gas_cost = GasCosts.WARM_ACCESS
388
    is_cold_access = to not in evm.accessed_addresses
389
    if is_cold_access:
390
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
391
    else:
372
        evm.accessed_addresses.add(to)
373
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
392
        access_gas_cost = GasCosts.WARM_ACCESS
393
375
    code_address = to
376
    (
377
        disable_precompiles,
378
        code_address,
379
        code,
380
        delegated_access_gas_cost,
381
    ) = access_delegation(evm, code_address)
382
    access_gas_cost += delegated_access_gas_cost
394
    transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE
395
396
    # check static gas before state access
397
    check_gas(
398
        evm,
399
        access_gas_cost + transfer_gas_cost + extend_memory.cost,
400
    )
401
402
    # STATE ACCESS
403
    tx_state = evm.message.tx_env.state
404
    if is_cold_access:
405
        evm.accessed_addresses.add(to)
406
407
    create_gas_cost = GasCosts.NEW_ACCOUNT
385
    if value == 0 or is_account_alive(evm.message.tx_env.state, to):
408
    if value == 0 or is_account_alive(tx_state, to):
409
        create_gas_cost = Uint(0)
387
    transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE
410
411
    extra_gas = access_gas_cost + transfer_gas_cost + create_gas_cost
412
    (
413
        is_delegated,
414
        code_address,
415
        delegation_access_cost,
416
    ) = calculate_delegation_cost(evm, to)
417
418
    if is_delegated:
419
        # check enough gas for delegation access
420
        extra_gas += delegation_access_cost
421
        check_gas(evm, extra_gas + extend_memory.cost)
422
        if code_address not in evm.accessed_addresses:
423
            evm.accessed_addresses.add(code_address)
424
425
    message_call_gas = calculate_message_call_gas(
426
        value,
427
        gas,
428
        Uint(evm.gas_left),
429
        extend_memory.cost,
393
        access_gas_cost + create_gas_cost + transfer_gas_cost,
430
        extra_gas,
431
    )
432
    charge_gas(evm, message_call_gas.cost + extend_memory.cost)
396
    if evm.message.is_static and value != U256(0):
397
        raise WriteInStaticContext
398
    evm.memory += b"\x00" * extend_memory.expand_by
399
    sender_balance = get_account(
400
        evm.message.tx_env.state, evm.message.current_target
401
    ).balance
433
434
    # OPERATION
435
    evm.memory += b"\x00" * extend_memory.expand_by
436
    sender_balance = get_account(tx_state, evm.message.current_target).balance
437
    if sender_balance < value:
438
        push(evm.stack, U256(0))
439
        evm.return_data = b""
440
        evm.gas_left += message_call_gas.sub_call
441
    else:
442
        generic_call(
443
            evm,
444
            message_call_gas.sub_call,
445
            value,
446
            evm.message.current_target,
447
            to,
448
            code_address,
449
            True,
450
            False,
451
            memory_input_start_position,
452
            memory_input_size,
453
            memory_output_start_position,
454
            memory_output_size,
420
            code,
421
            disable_precompiles,
455
            is_delegated,
456
        )
457
458
    # PROGRAM COUNTER
459
    evm.pc += Uint(1)

callcode

Message-call into this account with alternative account’s code.Message-call into this account with alternative account's code.

Parameters

evm : The current EVM frame.

def callcode(evm: Evm) -> None:
463
    <snip>
472
    # STACK
473
    gas = Uint(pop(evm.stack))
474
    code_address = to_address_masked(pop(evm.stack))
475
    value = pop(evm.stack)
476
    memory_input_start_position = pop(evm.stack)
477
    memory_input_size = pop(evm.stack)
478
    memory_output_start_position = pop(evm.stack)
479
    memory_output_size = pop(evm.stack)
480
481
    # GAS
482
    to = evm.message.current_target
483
484
    extend_memory = calculate_gas_extend_memory(
485
        evm.memory,
486
        [
487
            (memory_input_start_position, memory_input_size),
488
            (memory_output_start_position, memory_output_size),
489
        ],
490
    )
491
458
    if code_address in evm.accessed_addresses:
459
        access_gas_cost = GasCosts.WARM_ACCESS
492
    is_cold_access = code_address not in evm.accessed_addresses
493
    if is_cold_access:
494
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
495
    else:
461
        evm.accessed_addresses.add(code_address)
462
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
463
464
    (
465
        disable_precompiles,
466
        code_address,
467
        code,
468
        delegated_access_gas_cost,
469
    ) = access_delegation(evm, code_address)
470
    access_gas_cost += delegated_access_gas_cost
496
        access_gas_cost = GasCosts.WARM_ACCESS
497
498
    transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE
499
500
    # check static gas before state access
501
    check_gas(
502
        evm,
503
        access_gas_cost + extend_memory.cost + transfer_gas_cost,
504
    )
505
506
    # STATE ACCESS
507
    tx_state = evm.message.tx_env.state
508
    if is_cold_access:
509
        evm.accessed_addresses.add(code_address)
510
511
    extra_gas = access_gas_cost + transfer_gas_cost
512
    (
513
        is_delegated,
514
        code_address,
515
        delegation_access_cost,
516
    ) = calculate_delegation_cost(evm, code_address)
517
518
    if is_delegated:
519
        # check enough gas for delegation access
520
        extra_gas += delegation_access_cost
521
        check_gas(evm, extra_gas + extend_memory.cost)
522
        if code_address not in evm.accessed_addresses:
523
            evm.accessed_addresses.add(code_address)
524
525
    message_call_gas = calculate_message_call_gas(
526
        value,
527
        gas,
528
        Uint(evm.gas_left),
529
        extend_memory.cost,
478
        access_gas_cost + transfer_gas_cost,
530
        extra_gas,
531
    )
532
    charge_gas(evm, message_call_gas.cost + extend_memory.cost)
533
534
    # OPERATION
535
    evm.memory += b"\x00" * extend_memory.expand_by
484
    sender_balance = get_account(
485
        evm.message.tx_env.state, evm.message.current_target
486
    ).balance
536
    sender_balance = get_account(tx_state, evm.message.current_target).balance
537
538
    if sender_balance < value:
539
        push(evm.stack, U256(0))
540
        evm.return_data = b""
541
        evm.gas_left += message_call_gas.sub_call
542
    else:
543
        generic_call(
544
            evm,
545
            message_call_gas.sub_call,
546
            value,
547
            evm.message.current_target,
548
            to,
549
            code_address,
550
            True,
551
            False,
552
            memory_input_start_position,
553
            memory_input_size,
554
            memory_output_start_position,
555
            memory_output_size,
505
            code,
506
            disable_precompiles,
556
            is_delegated,
557
        )
558
559
    # PROGRAM COUNTER
560
    evm.pc += Uint(1)

selfdestruct

Halt execution and register account for later deletion.

Parameters

evm : The current EVM frame.

def selfdestruct(evm: Evm) -> None:
564
    <snip>
573
    if evm.message.is_static:
574
        raise WriteInStaticContext
575
576
    # STACK
577
    beneficiary = to_address_masked(pop(evm.stack))
578
579
    # GAS
580
    gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE
528
    if beneficiary not in evm.accessed_addresses:
529
        evm.accessed_addresses.add(beneficiary)
530
        gas_cost += GasCosts.COLD_ACCOUNT_ACCESS
581
582
    is_cold_access = beneficiary not in evm.accessed_addresses
583
    if is_cold_access:
584
        gas_cost += GasCosts.COLD_ACCOUNT_ACCESS
585
586
    # check access gas cost before state access
587
    check_gas(evm, gas_cost)
588
589
    # STATE ACCESS
590
    tx_state = evm.message.tx_env.state
591
    if is_cold_access:
592
        evm.accessed_addresses.add(beneficiary)
593
594
    if (
533
        not is_account_alive(evm.message.tx_env.state, beneficiary)
534
        and get_account(
535
            evm.message.tx_env.state, evm.message.current_target
536
        ).balance
537
        != 0
595
        not is_account_alive(tx_state, beneficiary)
596
        and get_account(tx_state, evm.message.current_target).balance != 0
597
    ):
598
        gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT
599
600
    charge_gas(evm, gas_cost)
542
    if evm.message.is_static:
543
        raise WriteInStaticContext
601
602
    originator = evm.message.current_target
546
    originator_balance = get_account(
547
        evm.message.tx_env.state, originator
548
    ).balance
603
    originator_balance = get_account(tx_state, originator).balance
604
550
    move_ether(
551
        evm.message.tx_env.state,
552
        originator,
553
        beneficiary,
554
        originator_balance,
555
    )
605
    # Transfer balance
606
    move_ether(tx_state, originator, beneficiary, originator_balance)
607
557
    # register account for deletion only if it was created
558
    # in the same transaction
559
    if originator in evm.message.tx_env.state.created_accounts:
560
        # If beneficiary is the same as originator, then
561
        # the ether is burnt.
562
        set_account_balance(evm.message.tx_env.state, originator, U256(0))
608
    # Emit transfer or burn log
609
    if originator in tx_state.created_accounts and beneficiary == originator:
610
        emit_burn_log(evm, originator, originator_balance)
611
    elif beneficiary != originator:
612
        emit_transfer_log(evm, originator, beneficiary, originator_balance)
613
614
    # Register account for deletion iff created in same transaction
615
    if originator in tx_state.created_accounts:
616
        # If beneficiary and originator are the same then the ether is burnt.
617
        set_account_balance(tx_state, originator, U256(0))
618
        evm.accounts_to_delete.add(originator)
619
620
    # HALT the execution
621
    evm.running = False
622
623
    # PROGRAM COUNTER
624
    pass

delegatecall

Message-call into an account.

Parameters

evm : The current EVM frame.

def delegatecall(evm: Evm) -> None:
628
    <snip>
637
    # STACK
638
    gas = Uint(pop(evm.stack))
639
    code_address = to_address_masked(pop(evm.stack))
640
    memory_input_start_position = pop(evm.stack)
641
    memory_input_size = pop(evm.stack)
642
    memory_output_start_position = pop(evm.stack)
643
    memory_output_size = pop(evm.stack)
644
645
    # GAS
646
    extend_memory = calculate_gas_extend_memory(
647
        evm.memory,
648
        [
649
            (memory_input_start_position, memory_input_size),
650
            (memory_output_start_position, memory_output_size),
651
        ],
652
    )
653
599
    if code_address in evm.accessed_addresses:
600
        access_gas_cost = GasCosts.WARM_ACCESS
654
    is_cold_access = code_address not in evm.accessed_addresses
655
    if is_cold_access:
656
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
657
    else:
602
        evm.accessed_addresses.add(code_address)
603
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
658
        access_gas_cost = GasCosts.WARM_ACCESS
659
660
    # check static gas before state access
661
    check_gas(evm, access_gas_cost + extend_memory.cost)
662
663
    # STATE ACCESS
664
    if is_cold_access:
665
        evm.accessed_addresses.add(code_address)
666
667
    extra_gas = access_gas_cost
668
    (
606
        disable_precompiles,
669
        is_delegated,
670
        code_address,
608
        code,
609
        delegated_access_gas_cost,
610
    ) = access_delegation(evm, code_address)
611
    access_gas_cost += delegated_access_gas_cost
671
        delegation_access_cost,
672
    ) = calculate_delegation_cost(evm, code_address)
673
674
    if is_delegated:
675
        # check enough gas for delegation access
676
        extra_gas += delegation_access_cost
677
        check_gas(evm, extra_gas + extend_memory.cost)
678
        if code_address not in evm.accessed_addresses:
679
            evm.accessed_addresses.add(code_address)
680
681
    message_call_gas = calculate_message_call_gas(
614
        U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost
682
        U256(0),
683
        gas,
684
        Uint(evm.gas_left),
685
        extend_memory.cost,
686
        extra_gas,
687
    )
688
    charge_gas(evm, message_call_gas.cost + extend_memory.cost)
689
690
    # OPERATION
691
    evm.memory += b"\x00" * extend_memory.expand_by
692
    generic_call(
693
        evm,
694
        message_call_gas.sub_call,
695
        evm.message.value,
696
        evm.message.caller,
697
        evm.message.current_target,
698
        code_address,
699
        False,
700
        False,
701
        memory_input_start_position,
702
        memory_input_size,
703
        memory_output_start_position,
704
        memory_output_size,
633
        code,
634
        disable_precompiles,
705
        is_delegated,
706
    )
707
708
    # PROGRAM COUNTER
709
    evm.pc += Uint(1)

staticcall

Message-call into an account.

Parameters

evm : The current EVM frame.

def staticcall(evm: Evm) -> None:
713
    <snip>
722
    # STACK
723
    gas = Uint(pop(evm.stack))
724
    to = to_address_masked(pop(evm.stack))
725
    memory_input_start_position = pop(evm.stack)
726
    memory_input_size = pop(evm.stack)
727
    memory_output_start_position = pop(evm.stack)
728
    memory_output_size = pop(evm.stack)
729
730
    # GAS
731
    extend_memory = calculate_gas_extend_memory(
732
        evm.memory,
733
        [
734
            (memory_input_start_position, memory_input_size),
735
            (memory_output_start_position, memory_output_size),
736
        ],
737
    )
738
668
    if to in evm.accessed_addresses:
669
        access_gas_cost = GasCosts.WARM_ACCESS
739
    is_cold_access = to not in evm.accessed_addresses
740
    if is_cold_access:
741
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
742
    else:
671
        evm.accessed_addresses.add(to)
672
        access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS
743
        access_gas_cost = GasCosts.WARM_ACCESS
744
674
    code_address = to
745
    # check static gas before state access
746
    check_gas(evm, access_gas_cost + extend_memory.cost)
747
748
    # STATE ACCESS
749
    if is_cold_access:
750
        evm.accessed_addresses.add(to)
751
752
    extra_gas = access_gas_cost
753
    (
676
        disable_precompiles,
754
        is_delegated,
755
        code_address,
678
        code,
679
        delegated_access_gas_cost,
680
    ) = access_delegation(evm, code_address)
681
    access_gas_cost += delegated_access_gas_cost
756
        delegation_access_cost,
757
    ) = calculate_delegation_cost(evm, to)
758
759
    if is_delegated:
760
        # check enough gas for delegation access
761
        extra_gas += delegation_access_cost
762
        check_gas(evm, extra_gas + extend_memory.cost)
763
        if code_address not in evm.accessed_addresses:
764
            evm.accessed_addresses.add(code_address)
765
766
    message_call_gas = calculate_message_call_gas(
767
        U256(0),
768
        gas,
769
        Uint(evm.gas_left),
770
        extend_memory.cost,
688
        access_gas_cost,
771
        extra_gas,
772
    )
773
    charge_gas(evm, message_call_gas.cost + extend_memory.cost)
774
775
    # OPERATION
776
    evm.memory += b"\x00" * extend_memory.expand_by
777
    generic_call(
778
        evm,
779
        message_call_gas.sub_call,
780
        U256(0),
781
        evm.message.current_target,
782
        to,
783
        code_address,
784
        True,
785
        True,
786
        memory_input_start_position,
787
        memory_input_size,
788
        memory_output_start_position,
789
        memory_output_size,
707
        code,
708
        disable_precompiles,
790
        is_delegated,
791
    )
792
793
    # PROGRAM COUNTER
794
    evm.pc += Uint(1)

revert

Stop execution and revert state changes, without consuming all provided gas and also has the ability to return a reason.

Parameters

evm : The current EVM frame.

def revert(evm: Evm) -> None:
798
    <snip>
808
    # STACK
809
    memory_start_index = pop(evm.stack)
810
    size = pop(evm.stack)
811
812
    # GAS
813
    extend_memory = calculate_gas_extend_memory(
814
        evm.memory, [(memory_start_index, size)]
815
    )
816
817
    charge_gas(evm, extend_memory.cost)
818
819
    # OPERATION
820
    evm.memory += b"\x00" * extend_memory.expand_by
821
    output = memory_read_bytes(evm.memory, memory_start_index, size)
822
    evm.output = Bytes(output)
823
    raise Revert
824
825
    # PROGRAM COUNTER
826
    # no-op