Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fillers/eips/eip3860: Update EIP-3860 Due to Spec Change #29

Merged
merged 10 commits into from
Jan 13, 2023
44 changes: 40 additions & 4 deletions fillers/eips/eip3860.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ def generate_create_opcode_initcode_test_cases(
"""
env = Environment()

call_code = Yul(
"""
{
calldatacopy(0, 0, calldatasize())
let call_result := call(5000000, \
0x0000000000000000000000000000000000000100, \
0, 0, calldatasize(), 0, 0)
sstore(call_result, 1)
}
"""
)

if opcode == "create":
code = Yul(
"""
Expand All @@ -483,7 +495,7 @@ def generate_create_opcode_initcode_test_cases(
let contract_length := calldatasize()
calldatacopy(0, 0, contract_length)
let gas1 := gas()
let res := create2(0, 0, contract_length, 0xdeadbeef)
let res := create2(0, 0, contract_length, 0xDEADBEEF)
let gas2 := gas()
sstore(0, res)
sstore(1, sub(gas1, gas2))
Expand All @@ -492,9 +504,10 @@ def generate_create_opcode_initcode_test_cases(
)
created_contract_address = compute_create2_address(
address=0x100,
salt=0,
salt=0xDEADBEEF,
initcode=initcode.assemble(),
)

else:
raise Exception("invalid opcode for generator")

Expand All @@ -504,13 +517,17 @@ def generate_create_opcode_initcode_test_cases(
code=code,
nonce=1,
),
to_address(0x200): Account(
code=call_code,
nonce=1,
),
}

post: Dict[Any, Any] = {}

tx = Transaction(
nonce=0,
to=to_address(0x100),
to=to_address(0x200),
data=initcode,
gas_limit=10000000,
gas_price=10,
Expand All @@ -525,14 +542,24 @@ def generate_create_opcode_initcode_test_cases(
expected_gas_usage += PUSH_DUP_OPCODE_GAS

if len(initcode.assemble()) > MAX_INITCODE_SIZE and eip_3860_active:
# Call returns 0 as out of gas s[0]==1
post[to_address(0x200)] = Account(
nonce=1,
storage={
0: 1,
marioevz marked this conversation as resolved.
Show resolved Hide resolved
1: 0,
},
)

post[created_contract_address] = Account.NONEXISTENT
post[to_address(0x100)] = Account(
nonce=1,
storage={
0: 0,
1: expected_gas_usage,
1: 0,
},
)

else:
# The initcode is only executed if the length check succeeds
expected_gas_usage += initcode.execution_gas
Expand All @@ -552,6 +579,15 @@ def generate_create_opcode_initcode_test_cases(
len(initcode.assemble())
)

# Call returns 1 as valid initcode length s[0]==1 && s[1]==1
post[to_address(0x200)] = Account(
nonce=1,
storage={
0: 0,
1: 1,
},
)

post[created_contract_address] = Account(code=initcode.deploy_code)
post[to_address(0x100)] = Account(
nonce=2,
Expand Down