Skip to content

Commit

Permalink
address issues
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Apr 10, 2024
1 parent 644fabc commit e1427fc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
4 changes: 2 additions & 2 deletions converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
([#497](https://github.com/ethereum/execution-spec-tests/pull/497))
- src/GeneralStateTestsFiller/stCreate2/call_outsize_then_create2_successful_then_returndatasizeFiller.json
- src/GeneralStateTestsFiller/stCreate2/call_then_create2_successful_then_returndatasizeFiller.json
GeneralStateTests/stCreate2/call_outsize_then_create2_successful_then_returndatasize.json
GeneralStateTests/stCreate2/call_then_create2_successful_then_returndatasize.json
59 changes: 35 additions & 24 deletions tests/constantinople/create2/test_create_returndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
Port call_then_create2_successful_then_returndatasizeFiller.json test
"""

from typing import Dict, Union

import pytest
from ethereum.crypto.hash import keccak256

from ethereum_test_tools import (
Account,
Address,
Environment,
Initcode,
StateTestFiller,
TestAddress,
Transaction,
Expand All @@ -21,7 +19,7 @@


@pytest.mark.valid_from("Istanbul")
@pytest.mark.parametrize("call_return_size", [0x20, 0])
@pytest.mark.parametrize("call_return_size", [35, 32, 0])
@pytest.mark.parametrize("create_type", [Op.CREATE, Op.CREATE2])
def test_create2_return_data(
call_return_size: int,
Expand All @@ -34,68 +32,81 @@ def test_create2_return_data(
# Storage vars
slot_returndatasize_before_create = 0
slot_returndatasize_after_create = 1
slot_code_worked = 2
slot_return_data_hash_before_create = 2
slot_return_data_hash_after_create = 3
slot_code_worked = 4

# Pre-Existing Addresses
address_to = Address(0x0600)
address_call = Address(0x0601)

# CREATE2 Initcode
create2_salt = 1
initcode = Initcode(
deploy_code=b"",
initcode_prefix=Op.MSTORE(0, 0x112233) + Op.RETURN(0, 32) + Op.STOP(),
)
initcode = Op.MSTORE(0, 0x112233) + Op.RETURN(0, 32) + Op.STOP()

def make_create() -> bytes:
if create_type == Op.CREATE2:
return Op.CREATE2(0, 0x100, Op.CALLDATASIZE(), create2_salt)
elif create_type == Op.CREATE:
return Op.CREATE(0, 0x100, Op.CALLDATASIZE())
return Op.STOP
raise NotImplementedError

call_return_data_value = 0x0000111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFF
call_return_data = int.to_bytes(call_return_data_value, 32, byteorder="big").ljust(
call_return_size, b"\0"
)[0:call_return_size]
empty_data = int.to_bytes(call_return_data_value, 32, byteorder="big").ljust(
call_return_size, b"\0"
)[0:0]

pre = {
address_to: Account(
balance=100000000,
balance=100_000_000,
nonce=0,
code=Op.JUMPDEST()
+ Op.MSTORE(0x100, Op.CALLDATALOAD(0))
+ Op.CALL(0x0900000000, address_call, 0, 0, 0, 0, call_return_size)
+ Op.SSTORE(slot_returndatasize_before_create, Op.RETURNDATASIZE())
+ Op.SSTORE(slot_return_data_hash_before_create, Op.SHA3(0, call_return_size))
+ make_create()
+ Op.SSTORE(slot_returndatasize_after_create, Op.RETURNDATASIZE())
+ Op.SSTORE(slot_return_data_hash_after_create, Op.SHA3(0, Op.RETURNDATASIZE()))
+ Op.SSTORE(slot_code_worked, 1)
+ Op.STOP(),
storage={
slot_returndatasize_before_create: 0xFF,
slot_returndatasize_after_create: 0xFF,
slot_return_data_hash_before_create: 0xFF,
slot_return_data_hash_after_create: 0xFF,
},
),
address_call: Account(
balance=0,
nonce=0,
code=Op.JUMPDEST()
+ Op.MSTORE(0, 0x0000111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFF)
+ Op.RETURN(0, 32),
+ Op.MSTORE(0, call_return_data_value)
+ Op.RETURN(0, call_return_size),
storage={},
),
TestAddress: Account(
balance=7000000000000000000,
balance=7_000_000_000_000_000_000,
nonce=0,
code="0x",
storage={},
),
}

post: Dict[Address, Union[Account, object]] = {}

post[address_to] = Account(
storage={
slot_code_worked: 1,
slot_returndatasize_before_create: 32,
slot_returndatasize_after_create: 0,
}
)
post = {
address_to: Account(
storage={
slot_code_worked: 1,
slot_returndatasize_before_create: call_return_size,
slot_returndatasize_after_create: 0,
slot_return_data_hash_before_create: keccak256(call_return_data),
slot_return_data_hash_after_create: keccak256(empty_data),
}
)
}

tx = Transaction(
ty=0x0,
Expand All @@ -104,7 +115,7 @@ def make_create() -> bytes:
to=address_to,
gas_price=10,
protected=False,
data=initcode.bytecode,
data=initcode,
gas_limit=0x0A00000000,
value=0,
)
Expand Down

0 comments on commit e1427fc

Please sign in to comment.