Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/testing/src/execution_testing/config/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
class DocsConfig(BaseModel):
"""A class for accessing documentation-related configurations."""

TARGET_FORK: str = "Osaka"
TARGET_FORK: str = "Amsterdam"
"""The target fork for the documentation."""

GENERATE_UNTIL_FORK: str = "Osaka"
GENERATE_UNTIL_FORK: str = "Amsterdam"
"""The fork until which documentation should be generated."""

DOCS_BASE_URL: str = "https://eest.ethereum.org"
Expand Down
113 changes: 45 additions & 68 deletions src/ethereum/forks/amsterdam/vm/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
set_code,
)
from ..state_tracker import (
StateChanges,
capture_pre_balance,
capture_pre_code,
merge_on_failure,
Expand Down Expand Up @@ -270,6 +269,28 @@ def process_message(message: Message) -> Evm:
if message.depth > STACK_DEPTH_LIMIT:
raise StackDepthLimitError("Stack depth limit reached")

code = message.code
valid_jump_destinations = get_valid_jump_destinations(code)
evm = Evm(
pc=Uint(0),
stack=[],
memory=bytearray(),
code=code,
gas_left=message.gas,
valid_jump_destinations=valid_jump_destinations,
logs=(),
refund_counter=0,
running=True,
message=message,
output=b"",
accounts_to_delete=set(),
return_data=b"",
error=None,
accessed_addresses=message.accessed_addresses,
accessed_storage_keys=message.accessed_storage_keys,
state_changes=message.state_changes,
)

# take snapshot of state before processing the message
begin_transaction(state, transient_storage)

Expand Down Expand Up @@ -310,77 +331,24 @@ def process_message(message: Message) -> Evm:
U256(recipient_new_balance),
)

evm = execute_code(message, message.state_changes)
if evm.error:
rollback_transaction(state, transient_storage)
if not message.is_create:
merge_on_failure(evm.state_changes)
else:
commit_transaction(state, transient_storage)
if not message.is_create:
merge_on_success(evm.state_changes)
return evm


def execute_code(message: Message, state_changes: StateChanges) -> Evm:
"""
Executes bytecode present in the `message`.

Parameters
----------
message :
Transaction specific items.
state_changes :
The state changes frame to use for tracking.

Returns
-------
evm: `ethereum.vm.EVM`
Items containing execution specific objects

"""
code = message.code
valid_jump_destinations = get_valid_jump_destinations(code)

evm = Evm(
pc=Uint(0),
stack=[],
memory=bytearray(),
code=code,
gas_left=message.gas,
valid_jump_destinations=valid_jump_destinations,
logs=(),
refund_counter=0,
running=True,
message=message,
output=b"",
accounts_to_delete=set(),
return_data=b"",
error=None,
accessed_addresses=message.accessed_addresses,
accessed_storage_keys=message.accessed_storage_keys,
state_changes=state_changes,
)
try:
if evm.message.code_address in PRE_COMPILED_CONTRACTS:
if message.disable_precompiles:
return evm
evm_trace(evm, PrecompileStart(evm.message.code_address))
PRE_COMPILED_CONTRACTS[evm.message.code_address](evm)
evm_trace(evm, PrecompileEnd())
return evm

while evm.running and evm.pc < ulen(evm.code):
try:
op = Ops(evm.code[evm.pc])
except ValueError as e:
raise InvalidOpcode(evm.code[evm.pc]) from e
if not message.disable_precompiles:
evm_trace(evm, PrecompileStart(evm.message.code_address))
PRE_COMPILED_CONTRACTS[evm.message.code_address](evm)
evm_trace(evm, PrecompileEnd())
else:
while evm.running and evm.pc < ulen(evm.code):
try:
op = Ops(evm.code[evm.pc])
except ValueError as e:
raise InvalidOpcode(evm.code[evm.pc]) from e

evm_trace(evm, OpStart(op))
op_implementation[op](evm)
evm_trace(evm, OpEnd())
evm_trace(evm, OpStart(op))
op_implementation[op](evm)
evm_trace(evm, OpEnd())

evm_trace(evm, EvmStop(Ops.STOP))
evm_trace(evm, EvmStop(Ops.STOP))

except ExceptionalHalt as error:
evm_trace(evm, OpException(error))
Expand All @@ -390,4 +358,13 @@ def execute_code(message: Message, state_changes: StateChanges) -> Evm:
except Revert as error:
evm_trace(evm, OpException(error))
evm.error = error

if evm.error:
rollback_transaction(state, transient_storage)
if not message.is_create:
merge_on_failure(evm.state_changes)
else:
commit_transaction(state, transient_storage)
if not message.is_create:
merge_on_success(evm.state_changes)
return evm
75 changes: 28 additions & 47 deletions src/ethereum/forks/arrow_glacier/vm/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,44 +225,8 @@ def process_message(message: Message) -> Evm:
if message.depth > STACK_DEPTH_LIMIT:
raise StackDepthLimitError("Stack depth limit reached")

# take snapshot of state before processing the message
begin_transaction(state)

touch_account(state, message.current_target)

if message.should_transfer_value and message.value != 0:
move_ether(
state, message.caller, message.current_target, message.value
)

evm = execute_code(message)
if evm.error:
# revert state to the last saved checkpoint
# since the message call resulted in an error
rollback_transaction(state)
else:
commit_transaction(state)
return evm


def execute_code(message: Message) -> Evm:
"""
Executes bytecode present in the `message`.

Parameters
----------
message :
Transaction specific items.

Returns
-------
evm: `ethereum.vm.EVM`
Items containing execution specific objects

"""
code = message.code
valid_jump_destinations = get_valid_jump_destinations(code)

evm = Evm(
pc=Uint(0),
stack=[],
Expand All @@ -282,24 +246,34 @@ def execute_code(message: Message) -> Evm:
accessed_addresses=message.accessed_addresses,
accessed_storage_keys=message.accessed_storage_keys,
)

# take snapshot of state before processing the message
begin_transaction(state)

touch_account(state, message.current_target)

if message.should_transfer_value and message.value != 0:
move_ether(
state, message.caller, message.current_target, message.value
)

try:
if evm.message.code_address in PRE_COMPILED_CONTRACTS:
evm_trace(evm, PrecompileStart(evm.message.code_address))
PRE_COMPILED_CONTRACTS[evm.message.code_address](evm)
evm_trace(evm, PrecompileEnd())
return evm

while evm.running and evm.pc < ulen(evm.code):
try:
op = Ops(evm.code[evm.pc])
except ValueError as e:
raise InvalidOpcode(evm.code[evm.pc]) from e
else:
while evm.running and evm.pc < ulen(evm.code):
try:
op = Ops(evm.code[evm.pc])
except ValueError as e:
raise InvalidOpcode(evm.code[evm.pc]) from e

evm_trace(evm, OpStart(op))
op_implementation[op](evm)
evm_trace(evm, OpEnd())
evm_trace(evm, OpStart(op))
op_implementation[op](evm)
evm_trace(evm, OpEnd())

evm_trace(evm, EvmStop(Ops.STOP))
evm_trace(evm, EvmStop(Ops.STOP))

except ExceptionalHalt as error:
evm_trace(evm, OpException(error))
Expand All @@ -309,4 +283,11 @@ def execute_code(message: Message) -> Evm:
except Revert as error:
evm_trace(evm, OpException(error))
evm.error = error

if evm.error:
# revert state to the last saved checkpoint
# since the message call resulted in an error
rollback_transaction(state)
else:
commit_transaction(state)
return evm
75 changes: 28 additions & 47 deletions src/ethereum/forks/berlin/vm/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,44 +221,8 @@ def process_message(message: Message) -> Evm:
if message.depth > STACK_DEPTH_LIMIT:
raise StackDepthLimitError("Stack depth limit reached")

# take snapshot of state before processing the message
begin_transaction(state)

touch_account(state, message.current_target)

if message.should_transfer_value and message.value != 0:
move_ether(
state, message.caller, message.current_target, message.value
)

evm = execute_code(message)
if evm.error:
# revert state to the last saved checkpoint
# since the message call resulted in an error
rollback_transaction(state)
else:
commit_transaction(state)
return evm


def execute_code(message: Message) -> Evm:
"""
Executes bytecode present in the `message`.

Parameters
----------
message :
Transaction specific items.

Returns
-------
evm: `ethereum.vm.EVM`
Items containing execution specific objects

"""
code = message.code
valid_jump_destinations = get_valid_jump_destinations(code)

evm = Evm(
pc=Uint(0),
stack=[],
Expand All @@ -278,24 +242,34 @@ def execute_code(message: Message) -> Evm:
accessed_addresses=message.accessed_addresses,
accessed_storage_keys=message.accessed_storage_keys,
)

# take snapshot of state before processing the message
begin_transaction(state)

touch_account(state, message.current_target)

if message.should_transfer_value and message.value != 0:
move_ether(
state, message.caller, message.current_target, message.value
)

try:
if evm.message.code_address in PRE_COMPILED_CONTRACTS:
evm_trace(evm, PrecompileStart(evm.message.code_address))
PRE_COMPILED_CONTRACTS[evm.message.code_address](evm)
evm_trace(evm, PrecompileEnd())
return evm

while evm.running and evm.pc < ulen(evm.code):
try:
op = Ops(evm.code[evm.pc])
except ValueError as e:
raise InvalidOpcode(evm.code[evm.pc]) from e
else:
while evm.running and evm.pc < ulen(evm.code):
try:
op = Ops(evm.code[evm.pc])
except ValueError as e:
raise InvalidOpcode(evm.code[evm.pc]) from e

evm_trace(evm, OpStart(op))
op_implementation[op](evm)
evm_trace(evm, OpEnd())
evm_trace(evm, OpStart(op))
op_implementation[op](evm)
evm_trace(evm, OpEnd())

evm_trace(evm, EvmStop(Ops.STOP))
evm_trace(evm, EvmStop(Ops.STOP))

except ExceptionalHalt as error:
evm_trace(evm, OpException(error))
Expand All @@ -305,4 +279,11 @@ def execute_code(message: Message) -> Evm:
except Revert as error:
evm_trace(evm, OpException(error))
evm.error = error

if evm.error:
# revert state to the last saved checkpoint
# since the message call resulted in an error
rollback_transaction(state)
else:
commit_transaction(state)
return evm
Loading
Loading