ethereum.forks.bpo4.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:
| 61 | """ |
|---|---|
| 62 | Core logic used by the `CREATE*` family of opcodes. |
| 63 | """ |
| 64 | # This import causes a circular import error |
| 65 | # if it's not moved inside this method |
| 66 | from ...vm.interpreter import ( |
| 67 | MAX_INIT_CODE_SIZE, |
| 68 | STACK_DEPTH_LIMIT, |
| 69 | process_create_message, |
| 70 | ) |
| 71 | |
| 72 | call_data = memory_read_bytes( |
| 73 | evm.memory, memory_start_position, memory_size |
| 74 | ) |
| 75 | if len(call_data) > MAX_INIT_CODE_SIZE: |
| 76 | raise OutOfGasError |
| 77 | |
| 78 | create_message_gas = max_message_call_gas(Uint(evm.gas_left)) |
| 79 | evm.gas_left -= create_message_gas |
| 80 | if evm.message.is_static: |
| 81 | raise WriteInStaticContext |
| 82 | evm.return_data = b"" |
| 83 | |
| 84 | sender_address = evm.message.current_target |
| 85 | sender = get_account(evm.message.block_env.state, sender_address) |
| 86 | |
| 87 | if ( |
| 88 | sender.balance < endowment |
| 89 | or sender.nonce == Uint(2**64 - 1) |
| 90 | or evm.message.depth + Uint(1) > STACK_DEPTH_LIMIT |
| 91 | ): |
| 92 | evm.gas_left += create_message_gas |
| 93 | push(evm.stack, U256(0)) |
| 94 | return |
| 95 | |
| 96 | evm.accessed_addresses.add(contract_address) |
| 97 | |
| 98 | if account_has_code_or_nonce( |
| 99 | evm.message.block_env.state, contract_address |
| 100 | ) or account_has_storage(evm.message.block_env.state, contract_address): |
| 101 | increment_nonce( |
| 102 | evm.message.block_env.state, evm.message.current_target |
| 103 | ) |
| 104 | push(evm.stack, U256(0)) |
| 105 | return |
| 106 | |
| 107 | increment_nonce(evm.message.block_env.state, evm.message.current_target) |
| 108 | |
| 109 | child_message = Message( |
| 110 | block_env=evm.message.block_env, |
| 111 | tx_env=evm.message.tx_env, |
| 112 | caller=evm.message.current_target, |
| 113 | target=Bytes0(), |
| 114 | gas=create_message_gas, |
| 115 | value=endowment, |
| 116 | data=b"", |
| 117 | code=call_data, |
| 118 | current_target=contract_address, |
| 119 | depth=evm.message.depth + Uint(1), |
| 120 | code_address=None, |
| 121 | should_transfer_value=True, |
| 122 | is_static=False, |
| 123 | accessed_addresses=evm.accessed_addresses.copy(), |
| 124 | accessed_storage_keys=evm.accessed_storage_keys.copy(), |
| 125 | disable_precompiles=False, |
| 126 | parent_evm=evm, |
| 127 | ) |
| 128 | child_evm = process_create_message(child_message) |
| 129 | |
| 130 | if child_evm.error: |
| 131 | incorporate_child_on_error(evm, child_evm) |
| 132 | evm.return_data = child_evm.output |
| 133 | push(evm.stack, U256(0)) |
| 134 | else: |
| 135 | incorporate_child_on_success(evm, child_evm) |
| 136 | evm.return_data = b"" |
| 137 | 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:
| 141 | """ |
|---|---|
| 142 | Creates a new account with associated code. |
| 143 | |
| 144 | Parameters |
| 145 | ---------- |
| 146 | evm : |
| 147 | The current EVM frame. |
| 148 | |
| 149 | """ |
| 150 | # STACK |
| 151 | endowment = pop(evm.stack) |
| 152 | memory_start_position = pop(evm.stack) |
| 153 | memory_size = pop(evm.stack) |
| 154 | |
| 155 | # GAS |
| 156 | extend_memory = calculate_gas_extend_memory( |
| 157 | evm.memory, [(memory_start_position, memory_size)] |
| 158 | ) |
| 159 | init_code_gas = init_code_cost(Uint(memory_size)) |
| 160 | |
| 161 | charge_gas( |
| 162 | evm, |
| 163 | GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas, |
| 164 | ) |
| 165 | |
| 166 | # OPERATION |
| 167 | evm.memory += b"\x00" * extend_memory.expand_by |
| 168 | contract_address = compute_contract_address( |
| 169 | evm.message.current_target, |
| 170 | get_account( |
| 171 | evm.message.block_env.state, evm.message.current_target |
| 172 | ).nonce, |
| 173 | ) |
| 174 | |
| 175 | generic_create( |
| 176 | evm, |
| 177 | endowment, |
| 178 | contract_address, |
| 179 | memory_start_position, |
| 180 | memory_size, |
| 181 | ) |
| 182 | |
| 183 | # PROGRAM COUNTER |
| 184 | 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:
| 188 | """ |
|---|---|
| 189 | Creates a new account with associated code. |
| 190 | |
| 191 | It's similar to the CREATE opcode except that the address of the new |
| 192 | account depends on the init_code instead of the nonce of sender. |
| 193 | |
| 194 | Parameters |
| 195 | ---------- |
| 196 | evm : |
| 197 | The current EVM frame. |
| 198 | |
| 199 | """ |
| 200 | # STACK |
| 201 | endowment = pop(evm.stack) |
| 202 | memory_start_position = pop(evm.stack) |
| 203 | memory_size = pop(evm.stack) |
| 204 | salt = pop(evm.stack).to_be_bytes32() |
| 205 | |
| 206 | # GAS |
| 207 | extend_memory = calculate_gas_extend_memory( |
| 208 | evm.memory, [(memory_start_position, memory_size)] |
| 209 | ) |
| 210 | call_data_words = ceil32(Uint(memory_size)) // Uint(32) |
| 211 | init_code_gas = init_code_cost(Uint(memory_size)) |
| 212 | charge_gas( |
| 213 | evm, |
| 214 | GasCosts.OPCODE_CREATE_BASE |
| 215 | + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words |
| 216 | + extend_memory.cost |
| 217 | + init_code_gas, |
| 218 | ) |
| 219 | |
| 220 | # OPERATION |
| 221 | evm.memory += b"\x00" * extend_memory.expand_by |
| 222 | contract_address = compute_create2_contract_address( |
| 223 | evm.message.current_target, |
| 224 | salt, |
| 225 | memory_read_bytes(evm.memory, memory_start_position, memory_size), |
| 226 | ) |
| 227 | |
| 228 | generic_create( |
| 229 | evm, |
| 230 | endowment, |
| 231 | contract_address, |
| 232 | memory_start_position, |
| 233 | memory_size, |
| 234 | ) |
| 235 | |
| 236 | # PROGRAM COUNTER |
| 237 | evm.pc += Uint(1) |
return_ ¶
Halts execution returning output data.
Parameters
evm : The current EVM frame.
def return_(evm: Evm) -> None:
| 241 | """ |
|---|---|
| 242 | Halts execution returning output data. |
| 243 | |
| 244 | Parameters |
| 245 | ---------- |
| 246 | evm : |
| 247 | The current EVM frame. |
| 248 | |
| 249 | """ |
| 250 | # STACK |
| 251 | memory_start_position = pop(evm.stack) |
| 252 | memory_size = pop(evm.stack) |
| 253 | |
| 254 | # GAS |
| 255 | extend_memory = calculate_gas_extend_memory( |
| 256 | evm.memory, [(memory_start_position, memory_size)] |
| 257 | ) |
| 258 | |
| 259 | charge_gas(evm, GasCosts.ZERO + extend_memory.cost) |
| 260 | |
| 261 | # OPERATION |
| 262 | evm.memory += b"\x00" * extend_memory.expand_by |
| 263 | evm.output = memory_read_bytes( |
| 264 | evm.memory, memory_start_position, memory_size |
| 265 | ) |
| 266 | |
| 267 | evm.running = False |
| 268 | |
| 269 | # PROGRAM COUNTER |
| 270 | 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:
| 289 | """ |
|---|---|
| 290 | Perform the core logic of the `CALL*` family of opcodes. |
| 291 | """ |
| 292 | from ...vm.interpreter import STACK_DEPTH_LIMIT, process_message |
| 293 | |
| 294 | evm.return_data = b"" |
| 295 | |
| 296 | if evm.message.depth + Uint(1) > STACK_DEPTH_LIMIT: |
| 297 | evm.gas_left += gas |
| 298 | push(evm.stack, U256(0)) |
| 299 | return |
| 300 | |
| 301 | call_data = memory_read_bytes( |
| 302 | evm.memory, memory_input_start_position, memory_input_size |
| 303 | ) |
| 304 | |
| 305 | child_message = Message( |
| 306 | block_env=evm.message.block_env, |
| 307 | tx_env=evm.message.tx_env, |
| 308 | caller=caller, |
| 309 | target=to, |
| 310 | gas=gas, |
| 311 | value=value, |
| 312 | data=call_data, |
| 313 | code=code, |
| 314 | current_target=to, |
| 315 | depth=evm.message.depth + Uint(1), |
| 316 | code_address=code_address, |
| 317 | should_transfer_value=should_transfer_value, |
| 318 | is_static=True if is_staticcall else evm.message.is_static, |
| 319 | accessed_addresses=evm.accessed_addresses.copy(), |
| 320 | accessed_storage_keys=evm.accessed_storage_keys.copy(), |
| 321 | disable_precompiles=disable_precompiles, |
| 322 | parent_evm=evm, |
| 323 | ) |
| 324 | child_evm = process_message(child_message) |
| 325 | |
| 326 | if child_evm.error: |
| 327 | incorporate_child_on_error(evm, child_evm) |
| 328 | evm.return_data = child_evm.output |
| 329 | push(evm.stack, U256(0)) |
| 330 | else: |
| 331 | incorporate_child_on_success(evm, child_evm) |
| 332 | evm.return_data = child_evm.output |
| 333 | push(evm.stack, U256(1)) |
| 334 | |
| 335 | actual_output_size = min(memory_output_size, U256(len(child_evm.output))) |
| 336 | memory_write( |
| 337 | evm.memory, |
| 338 | memory_output_start_position, |
| 339 | child_evm.output[:actual_output_size], |
| 340 | ) |
call ¶
Message-call into an account.
Parameters
evm : The current EVM frame.
def call(evm: Evm) -> None:
| 344 | """ |
|---|---|
| 345 | Message-call into an account. |
| 346 | |
| 347 | Parameters |
| 348 | ---------- |
| 349 | evm : |
| 350 | The current EVM frame. |
| 351 | |
| 352 | """ |
| 353 | # STACK |
| 354 | gas = Uint(pop(evm.stack)) |
| 355 | to = to_address_masked(pop(evm.stack)) |
| 356 | value = pop(evm.stack) |
| 357 | memory_input_start_position = pop(evm.stack) |
| 358 | memory_input_size = pop(evm.stack) |
| 359 | memory_output_start_position = pop(evm.stack) |
| 360 | memory_output_size = pop(evm.stack) |
| 361 | |
| 362 | # GAS |
| 363 | extend_memory = calculate_gas_extend_memory( |
| 364 | evm.memory, |
| 365 | [ |
| 366 | (memory_input_start_position, memory_input_size), |
| 367 | (memory_output_start_position, memory_output_size), |
| 368 | ], |
| 369 | ) |
| 370 | |
| 371 | if to in evm.accessed_addresses: |
| 372 | access_gas_cost = GasCosts.WARM_ACCESS |
| 373 | else: |
| 374 | evm.accessed_addresses.add(to) |
| 375 | access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS |
| 376 | |
| 377 | code_address = to |
| 378 | ( |
| 379 | disable_precompiles, |
| 380 | code_address, |
| 381 | code, |
| 382 | delegated_access_gas_cost, |
| 383 | ) = access_delegation(evm, code_address) |
| 384 | access_gas_cost += delegated_access_gas_cost |
| 385 | |
| 386 | create_gas_cost = GasCosts.NEW_ACCOUNT |
| 387 | if value == 0 or is_account_alive(evm.message.block_env.state, to): |
| 388 | create_gas_cost = Uint(0) |
| 389 | transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE |
| 390 | message_call_gas = calculate_message_call_gas( |
| 391 | value, |
| 392 | gas, |
| 393 | Uint(evm.gas_left), |
| 394 | extend_memory.cost, |
| 395 | access_gas_cost + create_gas_cost + transfer_gas_cost, |
| 396 | ) |
| 397 | charge_gas(evm, message_call_gas.cost + extend_memory.cost) |
| 398 | if evm.message.is_static and value != U256(0): |
| 399 | raise WriteInStaticContext |
| 400 | evm.memory += b"\x00" * extend_memory.expand_by |
| 401 | sender_balance = get_account( |
| 402 | evm.message.block_env.state, evm.message.current_target |
| 403 | ).balance |
| 404 | if sender_balance < value: |
| 405 | push(evm.stack, U256(0)) |
| 406 | evm.return_data = b"" |
| 407 | evm.gas_left += message_call_gas.sub_call |
| 408 | else: |
| 409 | generic_call( |
| 410 | evm, |
| 411 | message_call_gas.sub_call, |
| 412 | value, |
| 413 | evm.message.current_target, |
| 414 | to, |
| 415 | code_address, |
| 416 | True, |
| 417 | False, |
| 418 | memory_input_start_position, |
| 419 | memory_input_size, |
| 420 | memory_output_start_position, |
| 421 | memory_output_size, |
| 422 | code, |
| 423 | disable_precompiles, |
| 424 | ) |
| 425 | |
| 426 | # PROGRAM COUNTER |
| 427 | evm.pc += Uint(1) |
callcode ¶
Message-call into this account with alternative account’s code.
Parameters
evm : The current EVM frame.
def callcode(evm: Evm) -> None:
| 431 | """ |
|---|---|
| 432 | Message-call into this account with alternative account’s code. |
| 433 | |
| 434 | Parameters |
| 435 | ---------- |
| 436 | evm : |
| 437 | The current EVM frame. |
| 438 | |
| 439 | """ |
| 440 | # STACK |
| 441 | gas = Uint(pop(evm.stack)) |
| 442 | code_address = to_address_masked(pop(evm.stack)) |
| 443 | value = pop(evm.stack) |
| 444 | memory_input_start_position = pop(evm.stack) |
| 445 | memory_input_size = pop(evm.stack) |
| 446 | memory_output_start_position = pop(evm.stack) |
| 447 | memory_output_size = pop(evm.stack) |
| 448 | |
| 449 | # GAS |
| 450 | to = evm.message.current_target |
| 451 | |
| 452 | extend_memory = calculate_gas_extend_memory( |
| 453 | evm.memory, |
| 454 | [ |
| 455 | (memory_input_start_position, memory_input_size), |
| 456 | (memory_output_start_position, memory_output_size), |
| 457 | ], |
| 458 | ) |
| 459 | |
| 460 | if code_address in evm.accessed_addresses: |
| 461 | access_gas_cost = GasCosts.WARM_ACCESS |
| 462 | else: |
| 463 | evm.accessed_addresses.add(code_address) |
| 464 | access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS |
| 465 | |
| 466 | ( |
| 467 | disable_precompiles, |
| 468 | code_address, |
| 469 | code, |
| 470 | delegated_access_gas_cost, |
| 471 | ) = access_delegation(evm, code_address) |
| 472 | access_gas_cost += delegated_access_gas_cost |
| 473 | |
| 474 | transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE |
| 475 | message_call_gas = calculate_message_call_gas( |
| 476 | value, |
| 477 | gas, |
| 478 | Uint(evm.gas_left), |
| 479 | extend_memory.cost, |
| 480 | access_gas_cost + transfer_gas_cost, |
| 481 | ) |
| 482 | charge_gas(evm, message_call_gas.cost + extend_memory.cost) |
| 483 | |
| 484 | # OPERATION |
| 485 | evm.memory += b"\x00" * extend_memory.expand_by |
| 486 | sender_balance = get_account( |
| 487 | evm.message.block_env.state, evm.message.current_target |
| 488 | ).balance |
| 489 | if sender_balance < value: |
| 490 | push(evm.stack, U256(0)) |
| 491 | evm.return_data = b"" |
| 492 | evm.gas_left += message_call_gas.sub_call |
| 493 | else: |
| 494 | generic_call( |
| 495 | evm, |
| 496 | message_call_gas.sub_call, |
| 497 | value, |
| 498 | evm.message.current_target, |
| 499 | to, |
| 500 | code_address, |
| 501 | True, |
| 502 | False, |
| 503 | memory_input_start_position, |
| 504 | memory_input_size, |
| 505 | memory_output_start_position, |
| 506 | memory_output_size, |
| 507 | code, |
| 508 | disable_precompiles, |
| 509 | ) |
| 510 | |
| 511 | # PROGRAM COUNTER |
| 512 | evm.pc += Uint(1) |
selfdestruct ¶
Halt execution and register account for later deletion.
Parameters
evm : The current EVM frame.
def selfdestruct(evm: Evm) -> None:
| 516 | """ |
|---|---|
| 517 | Halt execution and register account for later deletion. |
| 518 | |
| 519 | Parameters |
| 520 | ---------- |
| 521 | evm : |
| 522 | The current EVM frame. |
| 523 | |
| 524 | """ |
| 525 | # STACK |
| 526 | beneficiary = to_address_masked(pop(evm.stack)) |
| 527 | |
| 528 | # GAS |
| 529 | gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE |
| 530 | if beneficiary not in evm.accessed_addresses: |
| 531 | evm.accessed_addresses.add(beneficiary) |
| 532 | gas_cost += GasCosts.COLD_ACCOUNT_ACCESS |
| 533 | |
| 534 | if ( |
| 535 | not is_account_alive(evm.message.block_env.state, beneficiary) |
| 536 | and get_account( |
| 537 | evm.message.block_env.state, evm.message.current_target |
| 538 | ).balance |
| 539 | != 0 |
| 540 | ): |
| 541 | gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT |
| 542 | |
| 543 | charge_gas(evm, gas_cost) |
| 544 | if evm.message.is_static: |
| 545 | raise WriteInStaticContext |
| 546 | |
| 547 | originator = evm.message.current_target |
| 548 | originator_balance = get_account( |
| 549 | evm.message.block_env.state, originator |
| 550 | ).balance |
| 551 | |
| 552 | move_ether( |
| 553 | evm.message.block_env.state, |
| 554 | originator, |
| 555 | beneficiary, |
| 556 | originator_balance, |
| 557 | ) |
| 558 | |
| 559 | # register account for deletion only if it was created |
| 560 | # in the same transaction |
| 561 | if originator in evm.message.block_env.state.created_accounts: |
| 562 | # If beneficiary is the same as originator, then |
| 563 | # the ether is burnt. |
| 564 | set_account_balance(evm.message.block_env.state, originator, U256(0)) |
| 565 | evm.accounts_to_delete.add(originator) |
| 566 | |
| 567 | # HALT the execution |
| 568 | evm.running = False |
| 569 | |
| 570 | # PROGRAM COUNTER |
| 571 | pass |
delegatecall ¶
Message-call into an account.
Parameters
evm : The current EVM frame.
def delegatecall(evm: Evm) -> None:
| 575 | """ |
|---|---|
| 576 | Message-call into an account. |
| 577 | |
| 578 | Parameters |
| 579 | ---------- |
| 580 | evm : |
| 581 | The current EVM frame. |
| 582 | |
| 583 | """ |
| 584 | # STACK |
| 585 | gas = Uint(pop(evm.stack)) |
| 586 | code_address = to_address_masked(pop(evm.stack)) |
| 587 | memory_input_start_position = pop(evm.stack) |
| 588 | memory_input_size = pop(evm.stack) |
| 589 | memory_output_start_position = pop(evm.stack) |
| 590 | memory_output_size = pop(evm.stack) |
| 591 | |
| 592 | # GAS |
| 593 | extend_memory = calculate_gas_extend_memory( |
| 594 | evm.memory, |
| 595 | [ |
| 596 | (memory_input_start_position, memory_input_size), |
| 597 | (memory_output_start_position, memory_output_size), |
| 598 | ], |
| 599 | ) |
| 600 | |
| 601 | if code_address in evm.accessed_addresses: |
| 602 | access_gas_cost = GasCosts.WARM_ACCESS |
| 603 | else: |
| 604 | evm.accessed_addresses.add(code_address) |
| 605 | access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS |
| 606 | |
| 607 | ( |
| 608 | disable_precompiles, |
| 609 | code_address, |
| 610 | code, |
| 611 | delegated_access_gas_cost, |
| 612 | ) = access_delegation(evm, code_address) |
| 613 | access_gas_cost += delegated_access_gas_cost |
| 614 | |
| 615 | message_call_gas = calculate_message_call_gas( |
| 616 | U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost |
| 617 | ) |
| 618 | charge_gas(evm, message_call_gas.cost + extend_memory.cost) |
| 619 | |
| 620 | # OPERATION |
| 621 | evm.memory += b"\x00" * extend_memory.expand_by |
| 622 | generic_call( |
| 623 | evm, |
| 624 | message_call_gas.sub_call, |
| 625 | evm.message.value, |
| 626 | evm.message.caller, |
| 627 | evm.message.current_target, |
| 628 | code_address, |
| 629 | False, |
| 630 | False, |
| 631 | memory_input_start_position, |
| 632 | memory_input_size, |
| 633 | memory_output_start_position, |
| 634 | memory_output_size, |
| 635 | code, |
| 636 | disable_precompiles, |
| 637 | ) |
| 638 | |
| 639 | # PROGRAM COUNTER |
| 640 | evm.pc += Uint(1) |
staticcall ¶
Message-call into an account.
Parameters
evm : The current EVM frame.
def staticcall(evm: Evm) -> None:
| 644 | """ |
|---|---|
| 645 | Message-call into an account. |
| 646 | |
| 647 | Parameters |
| 648 | ---------- |
| 649 | evm : |
| 650 | The current EVM frame. |
| 651 | |
| 652 | """ |
| 653 | # STACK |
| 654 | gas = Uint(pop(evm.stack)) |
| 655 | to = to_address_masked(pop(evm.stack)) |
| 656 | memory_input_start_position = pop(evm.stack) |
| 657 | memory_input_size = pop(evm.stack) |
| 658 | memory_output_start_position = pop(evm.stack) |
| 659 | memory_output_size = pop(evm.stack) |
| 660 | |
| 661 | # GAS |
| 662 | extend_memory = calculate_gas_extend_memory( |
| 663 | evm.memory, |
| 664 | [ |
| 665 | (memory_input_start_position, memory_input_size), |
| 666 | (memory_output_start_position, memory_output_size), |
| 667 | ], |
| 668 | ) |
| 669 | |
| 670 | if to in evm.accessed_addresses: |
| 671 | access_gas_cost = GasCosts.WARM_ACCESS |
| 672 | else: |
| 673 | evm.accessed_addresses.add(to) |
| 674 | access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS |
| 675 | |
| 676 | code_address = to |
| 677 | ( |
| 678 | disable_precompiles, |
| 679 | code_address, |
| 680 | code, |
| 681 | delegated_access_gas_cost, |
| 682 | ) = access_delegation(evm, code_address) |
| 683 | access_gas_cost += delegated_access_gas_cost |
| 684 | |
| 685 | message_call_gas = calculate_message_call_gas( |
| 686 | U256(0), |
| 687 | gas, |
| 688 | Uint(evm.gas_left), |
| 689 | extend_memory.cost, |
| 690 | access_gas_cost, |
| 691 | ) |
| 692 | charge_gas(evm, message_call_gas.cost + extend_memory.cost) |
| 693 | |
| 694 | # OPERATION |
| 695 | evm.memory += b"\x00" * extend_memory.expand_by |
| 696 | generic_call( |
| 697 | evm, |
| 698 | message_call_gas.sub_call, |
| 699 | U256(0), |
| 700 | evm.message.current_target, |
| 701 | to, |
| 702 | code_address, |
| 703 | True, |
| 704 | True, |
| 705 | memory_input_start_position, |
| 706 | memory_input_size, |
| 707 | memory_output_start_position, |
| 708 | memory_output_size, |
| 709 | code, |
| 710 | disable_precompiles, |
| 711 | ) |
| 712 | |
| 713 | # PROGRAM COUNTER |
| 714 | 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:
| 718 | """ |
|---|---|
| 719 | Stop execution and revert state changes, without consuming all provided gas |
| 720 | and also has the ability to return a reason. |
| 721 | |
| 722 | Parameters |
| 723 | ---------- |
| 724 | evm : |
| 725 | The current EVM frame. |
| 726 | |
| 727 | """ |
| 728 | # STACK |
| 729 | memory_start_index = pop(evm.stack) |
| 730 | size = pop(evm.stack) |
| 731 | |
| 732 | # GAS |
| 733 | extend_memory = calculate_gas_extend_memory( |
| 734 | evm.memory, [(memory_start_index, size)] |
| 735 | ) |
| 736 | |
| 737 | charge_gas(evm, extend_memory.cost) |
| 738 | |
| 739 | # OPERATION |
| 740 | evm.memory += b"\x00" * extend_memory.expand_by |
| 741 | output = memory_read_bytes(evm.memory, memory_start_index, size) |
| 742 | evm.output = Bytes(output) |
| 743 | raise Revert |
| 744 | |
| 745 | # PROGRAM COUNTER |
| 746 | # no-op |