Skip to content
Closed
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
6 changes: 4 additions & 2 deletions src/ethereum/osaka/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
return b"\x03" + rlp.encode(receipt)
elif isinstance(tx, SetCodeTransaction):
return b"\x04" + rlp.encode(receipt)
# Type 5 is skipped as it is used for EIP-7702 delegate signing
elif isinstance(tx, EofInitCodeTransaction):
return b"\x05" + rlp.encode(receipt)
return b"\x06" + rlp.encode(receipt)
else:
return receipt

Expand All @@ -133,7 +134,8 @@ def decode_receipt(receipt: Union[Bytes, Receipt]) -> Receipt:
Decodes a receipt.
"""
if isinstance(receipt, Bytes):
assert receipt[0] in (1, 2, 3, 4, 5)
# Type 5 is skipped as it is used for EIP-7702 delegate signing
assert receipt[0] in (1, 2, 3, 4, 6)
return rlp.decode_to(Receipt, receipt[1:])
else:
return receipt
1 change: 1 addition & 0 deletions src/ethereum/osaka/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def process_system_transaction(
is_static=False,
accessed_addresses=set(),
accessed_storage_keys=set(),
is_delegated=False,
parent_evm=None,
eof=None,
)
Expand Down
16 changes: 9 additions & 7 deletions src/ethereum/osaka/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
return b"\x03" + rlp.encode(tx)
elif isinstance(tx, SetCodeTransaction):
return b"\x04" + rlp.encode(tx)
# Type 5 is skipped as it is used for EIP-7702 delegate signing
elif isinstance(tx, EofInitCodeTransaction):
return b"\x05" + rlp.encode(tx)
return b"\x06" + rlp.encode(tx)
else:
raise Exception(f"Unable to encode transaction of type {type(tx)}")

Expand All @@ -197,7 +198,8 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
return rlp.decode_to(BlobTransaction, tx[1:])
elif tx[0] == 4:
return rlp.decode_to(SetCodeTransaction, tx[1:])
elif tx[0] == 5:
# Type 5 is skipped as it is used for EIP-7702 delegate signing
elif tx[0] == 6:
return rlp.decode_to(EofInitCodeTransaction, tx[1:])
else:
raise TransactionTypeError(tx[0])
Expand Down Expand Up @@ -242,9 +244,9 @@ def validate_transaction(tx: Transaction) -> Tuple[Uint, Uint]:

if isinstance(tx, EofInitCodeTransaction):
if len(tx.init_codes) == 0:
raise InvalidTransaction("Type 5 tx with no init codes")
raise InvalidTransaction("Type 6 tx with no init codes")
if len(tx.init_codes) > MAX_INIT_CODE_COUNT:
raise InvalidTransaction("Type 5 tx with too many init codes")
raise InvalidTransaction("Type 6 tx with too many init codes")

intrinsic_gas, calldata_floor_gas_cost = calculate_intrinsic_cost(tx)
if max(intrinsic_gas, calldata_floor_gas_cost) > tx.gas:
Expand Down Expand Up @@ -317,10 +319,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
for init_code in tx.init_codes:
if len(init_code) == 0:
raise InvalidTransaction(
"Type 5 tx with zero-length init code"
"Type 6 tx with zero-length init code"
)
if len(init_code) > 2 * MAX_CODE_SIZE:
raise InvalidTransaction("Type 5 tx with too large init code")
raise InvalidTransaction("Type 6 tx with too large init code")

tokens_in_tx += calculate_tokens_in_data(init_code)

Expand Down Expand Up @@ -645,7 +647,7 @@ def signing_hash_7873(tx: EofInitCodeTransaction) -> Hash32:
Hash of the transaction.
"""
return keccak256(
b"\x05"
b"\x06"
+ rlp.encode(
(
tx.chain_id,
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/osaka/utils/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def compute_eof_tx_create_contract_address(
address: `ethereum.osaka.fork_types.Address`
The computed address of the new account.
"""
preimage = b"\xff" + address + salt
preimage = b"\xff" + left_pad_zero_bytes(address, 32) + salt
computed_address = keccak256(preimage)
canonical_address = computed_address[-20:]
padded_address = left_pad_zero_bytes(canonical_address, 20)
Expand Down
4 changes: 4 additions & 0 deletions src/ethereum/osaka/utils/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def prepare_message(
accessed_addresses.update(PRE_COMPILED_CONTRACTS.keys())
accessed_addresses.update(tx_env.access_list_addresses)

is_delegated = False

if isinstance(tx.to, Bytes0):
current_target = compute_contract_address(
tx_env.origin,
Expand All @@ -74,6 +76,7 @@ def prepare_message(

delegated_address = get_delegated_code_address(code)
if delegated_address is not None:
is_delegated = True
accessed_addresses.add(delegated_address)
code = get_account(block_env.state, delegated_address).code

Expand Down Expand Up @@ -113,6 +116,7 @@ def prepare_message(
is_static=False,
accessed_addresses=accessed_addresses,
accessed_storage_keys=set(tx_env.access_list_storage_keys),
is_delegated=is_delegated,
parent_evm=None,
eof=eof,
)
1 change: 1 addition & 0 deletions src/ethereum/osaka/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class Message:
is_static: bool
accessed_addresses: Set[Address]
accessed_storage_keys: Set[Tuple[Address, Bytes32]]
is_delegated: bool
parent_evm: Optional["Evm"]
eof: Optional["Eof"]

Expand Down
1 change: 1 addition & 0 deletions src/ethereum/osaka/vm/eoa_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def set_delegation(message: Message) -> U256:
message.code = get_account(state, message.code_address).code

if is_valid_delegation(message.code):
message.is_delegated = True
message.code_address = Address(
message.code[EOA_DELEGATION_MARKER_LENGTH:]
)
Expand Down
8 changes: 4 additions & 4 deletions src/ethereum/osaka/vm/eof/stack_height_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def stack_validation_callf(validator: Validator) -> None:
]
target_inputs = target_section_type[0]
target_outputs = target_section_type[1]
target_max_height = int.from_bytes(target_section_type[2:], "big")
target_max_stack_increase = int.from_bytes(target_section_type[2:], "big")

# Stack Height Check
if op_metadata.stack_height.min < target_inputs:
raise InvalidEof("Invalid stack height")

# Stack Overflow Check
if op_metadata.stack_height.max > 1024 - target_max_height + target_inputs:
if op_metadata.stack_height.max > 1024 - target_max_stack_increase:
raise InvalidEof("Stack overflow")

# Update the stack height after instruction
Expand Down Expand Up @@ -75,7 +75,7 @@ def stack_validation_jumpf(validator: Validator) -> None:
current_outputs = current_section_type[1]
target_inputs = target_section_type[0]
target_outputs = target_section_type[1]
target_max_height = int.from_bytes(target_section_type[2:], "big")
target_max_stack_increase = int.from_bytes(target_section_type[2:], "big")

# Stack Height Check
if target_outputs != 0x80:
Expand All @@ -91,7 +91,7 @@ def stack_validation_jumpf(validator: Validator) -> None:
raise InvalidEof("Invalid stack height")

# Stack Overflow Check
if op_metadata.stack_height.max > 1024 - target_max_height + target_inputs:
if op_metadata.stack_height.max > 1024 - target_max_stack_increase:
raise InvalidEof("Stack overflow")

# Update the stack height after instruction
Expand Down
14 changes: 7 additions & 7 deletions src/ethereum/osaka/vm/eof/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def metadata_from_container(
raise InvalidEof("Invalid number of container sections")

for i in range(num_container_sections):
# Get the 2 bytes container_size
if validate and len(container) < counter + 2:
# Get the 4 bytes container_size
if validate and len(container) < counter + 4:
raise InvalidEof(
f"Container section {i} does not have a size specified"
)
container_size = Uint.from_be_bytes(
container[counter : counter + 2]
container[counter : counter + 4]
)
counter += 2
counter += 4
if validate and container_size == 0:
raise InvalidEof("Invalid container size")
container_sizes.append(container_size)
Expand All @@ -133,7 +133,7 @@ def metadata_from_container(
# Get 1 byte kind_data
kind_data = container[counter]
counter += 1
if validate and kind_data != 4:
if validate and kind_data != 0xFF:
raise InvalidEof("Invalid kind data")
# Get 2 bytes data_size
if validate and len(container) < counter + 2:
Expand Down Expand Up @@ -254,10 +254,10 @@ def container_from_metadata(eof_metadata: EofMetadata) -> bytes:
Uint(2), "big"
)
for container_size in eof_metadata.container_sizes:
container += container_size.to_bytes(Uint(2), "big")
container += container_size.to_bytes(Uint(4), "big")

# Add the kind data
container += b"\x04"
container += b"\xff"
container += eof_metadata.data_size.to_bytes(Uint(2), "big")

# Add the terminator
Expand Down
15 changes: 8 additions & 7 deletions src/ethereum/osaka/vm/eof/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def validate_body(validator: Validator) -> None:
if num_outputs > 128:
raise InvalidEof(f"Invalid number of outputs for type {i}")

max_stack_height = Uint.from_be_bytes(type_section[2:])
if max_stack_height > Uint(1023):
max_stack_increase = Uint.from_be_bytes(type_section[2:])
if max_stack_increase + Uint(num_inputs) > Uint(1023):
raise InvalidEof(f"Invalid max stack height for type {i}")

# 4750: Input and output for first section should
Expand All @@ -81,7 +81,6 @@ def update_successor_stack_height(validator: Validator) -> None:
section_metadata = validator.sections[index]
code = validator.eof.metadata.code_section_contents[index]
op_metadata = section_metadata[validator.current_pc]
valid_opcode_positions = list(section_metadata.keys())
current_stack_height = validator.current_stack_height
assert current_stack_height is not None

Expand All @@ -95,7 +94,7 @@ def update_successor_stack_height(validator: Validator) -> None:
)
if (
successor_position + Uint(1) > ulen(code)
or successor_position not in valid_opcode_positions
or successor_position not in section_metadata.keys()
):
raise InvalidEof("Invalid successor or jump destination")

Expand Down Expand Up @@ -160,7 +159,7 @@ def validate_code_section(validator: Validator) -> None:
section_type = validator.eof.metadata.type_section_contents[code_index]
section_inputs = section_type[0]
section_outputs = section_type[1]
section_max_stack_height = Uint.from_be_bytes(section_type[2:])
section_max_stack_increase = Uint.from_be_bytes(section_type[2:])

# If the return flag from the section type does not agree with
# the instructions in the code.
Expand Down Expand Up @@ -202,8 +201,10 @@ def validate_code_section(validator: Validator) -> None:
if computed_maximum_stack_height > 1023:
raise InvalidEof("Invalid stack height")

if computed_maximum_stack_height != section_max_stack_height:
raise InvalidEof("Invalid stack height")
if computed_maximum_stack_height != section_max_stack_increase + Uint(
section_inputs
):
raise InvalidEof("Invalid max stack increase")


def get_reached_code_sections(
Expand Down
1 change: 0 additions & 1 deletion src/ethereum/osaka/vm/instructions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ class Ops(enum.Enum):
Ops.EXCHANGE,
# System Operations
Ops.EOFCREATE,
Ops.TXCREATE,
Ops.RETURNDATALOAD,
Ops.EXTCALL,
Ops.EXTDELEGATECALL,
Expand Down
10 changes: 4 additions & 6 deletions src/ethereum/osaka/vm/instructions/control_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,9 @@ def callf(evm: Evm) -> None:
target_section = evm.eof.metadata.type_section_contents[
target_section_index
]
target_inputs = Uint(target_section[0])
target_max_stack_height = Uint.from_be_bytes(target_section[2:])
target_max_increase = Uint.from_be_bytes(target_section[2:])

if ulen(evm.stack) > Uint(1024) - target_max_stack_height + target_inputs:
if ulen(evm.stack) > Uint(1024) - target_max_increase:
raise StackOverflowError
if ulen(evm.return_stack) == Uint(1024):
raise StackOverflowError("Return stack overflow")
Expand Down Expand Up @@ -379,10 +378,9 @@ def jumpf(evm: Evm) -> None:
target_section = evm.eof.metadata.type_section_contents[
target_section_index
]
target_inputs = Uint(target_section[0])
target_max_stack_height = Uint.from_be_bytes(target_section[2:])
target_max_stack_increase = Uint.from_be_bytes(target_section[2:])

if ulen(evm.stack) > Uint(1024) - target_max_stack_height + target_inputs:
if ulen(evm.stack) > Uint(1024) - target_max_stack_increase:
raise StackOverflowError

# PROGRAM COUNTER
Expand Down
Loading
Loading