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

new(tests): EIP-7069 - EXTCALL with balance and other #755

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
48 changes: 36 additions & 12 deletions tests/prague/eip7692_eof_v1/eip7069_extcall/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,19 @@ def test_eof_calls_eof_then_fails(
"EOA",
"LegacyContract",
"EOFContract",
"LegacyContractInvalid",
"EOFContractInvalid",
),
ids=lambda x: x,
)
@pytest.mark.parametrize("value", [0, 1])
def test_eof_calls_clear_return_buffer(
state_test: StateTestFiller,
pre: Alloc,
sender: EOA,
opcode: Op,
target_account_type: str,
value: int,
):
"""Test EOF contracts calling clears returndata buffer"""
env = Environment()
Expand All @@ -606,13 +610,21 @@ def test_eof_calls_clear_return_buffer(
target_address = pre.deploy_contract(
code=Container.Code(Op.STOP),
)
case "LegacyContractInvalid":
target_address = pre.deploy_contract(
code=Op.INVALID,
)
case "EOFContractInvalid":
target_address = pre.deploy_contract(
code=Container.Code(Op.INVALID),
)

caller_contract = Container.Code(
# First fill the return buffer and sanity check
Op.EXTCALL(filling_callee_address, 0, 0, 0)
+ Op.SSTORE(slot_returndatasize_before_clear, Op.RETURNDATASIZE)
# Then call something that doesn't return and check returndata cleared
+ opcode(address=target_address)
+ opcode(address=target_address, value=value)
+ Op.SSTORE(slot_returndatasize, Op.RETURNDATASIZE)
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.STOP,
Expand Down Expand Up @@ -710,12 +722,14 @@ def test_eof_calls_static_flag_with_value(


@pytest.mark.parametrize(
"opcode",
["opcode", "extra_gas_value_transfer", "value"],
[
Op.EXTCALL,
Op.EXTSTATICCALL,
Op.EXTDELEGATECALL,
[Op.EXTCALL, 0, 0],
[Op.EXTCALL, 9_000, 1],
[Op.EXTSTATICCALL, 0, 0],
[Op.EXTDELEGATECALL, 0, 0],
],
ids=["extcall_without_value", "extcall_with_value", "extstaticcall", "extdelegatecall"],
)
@pytest.mark.parametrize(
["extra_gas_limit", "reverts"],
Expand All @@ -732,6 +746,8 @@ def test_eof_calls_min_callee_gas(
pre: Alloc,
sender: EOA,
opcode: Op,
extra_gas_value_transfer: int,
value: int,
extra_gas_limit: int,
reverts: bool,
):
Expand All @@ -752,12 +768,13 @@ def test_eof_calls_min_callee_gas(
calling_contract_address = pre.deploy_contract(
Container.Code(
Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.EQ(opcode(address=noop_callee_address), value_eof_call_reverted)
+ Op.EQ(opcode(address=noop_callee_address, value=value), value_eof_call_reverted)
# If the return code isn't 1, it means gas was enough to cover the allowances.
+ Op.RJUMPI[len(revert_block)]
+ revert_block
+ Op.STOP
)
),
balance=value,
)

# `no_oog_gas` is minimum amount of gas_limit which makes the transaction not go oog.
Expand All @@ -769,6 +786,7 @@ def test_eof_calls_min_callee_gas(
+ push_operations * 3 # PUSH operations
+ 100 # WARM_STORAGE_READ_COST
+ 2500 # COLD_ACCOUNT_ACCESS - WARM_STORAGE_READ_COST
+ extra_gas_value_transfer
+ 4 # RJUMPI
+ 3 # EQ
)
Expand Down Expand Up @@ -796,22 +814,27 @@ def test_eof_calls_min_callee_gas(
)


def test_eof_calls_no_balance(
@pytest.mark.parametrize("balance", [0, 1, 2, 2**256 - 1])
marioevz marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize("value", [0, 1, 2, 2**256 - 1])
def test_eof_calls_with_value(
state_test: StateTestFiller,
pre: Alloc,
sender: EOA,
balance: int,
value: int,
):
"""Test EOF contracts calls handle value calls with not enough balance"""
"""Test EOF contracts calls handle value calls with and without enough balance"""
env = Environment()

noop_callee_address = pre.deploy_contract(Container.Code(Op.STOP))

calling_contract_address = pre.deploy_contract(
Container.Code(
Op.SSTORE(slot_call_result, Op.EXTCALL(address=noop_callee_address, value=1))
Op.SSTORE(slot_call_result, Op.EXTCALL(address=noop_callee_address, value=value))
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.STOP
)
),
balance=balance,
)
tx = Transaction(
sender=sender,
Expand All @@ -822,11 +845,12 @@ def test_eof_calls_no_balance(

calling_storage = {
slot_code_worked: value_code_worked,
slot_call_result: value_eof_call_reverted,
slot_call_result: value_eof_call_reverted if balance < value else value_eof_call_worked,
}

post = {
calling_contract_address: Account(storage=calling_storage),
noop_callee_address: Account(balance=0 if balance < value else value),
}

state_test(
Expand Down
54 changes: 27 additions & 27 deletions tests/prague/eip7692_eof_v1/tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,48 +375,48 @@

### Execution

- [ ] EXTDELEGATECALL from EOF to EOF (evmone-tests: state_tests/state_transition/eof_calls/eof1_extdelegatecall_eof1.json)
- [ ] EXTDELEGATECALL from EOF to legacy fails (evmone-tests: state_tests/state_transition/eof_calls/eof1_extdelegatecall_legacy.json)
- [x] EXTDELEGATECALL from EOF to EOF (evmone-tests: state_tests/state_transition/eof_calls/eof1_extdelegatecall_eof1.json)
- [x] EXTDELEGATECALL from EOF to legacy fails (evmone-tests: state_tests/state_transition/eof_calls/eof1_extdelegatecall_legacy.json)
- [ ] EXTSTATICCALL forwards static mode (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_static.json)
- [ ] EXTCALL with value success (evmone-tests: state_tests/state_transition/eof_calls/extcall_with_value.json)
- [x] EXTCALL with value success (evmone-tests: state_tests/state_transition/eof_calls/extcall_with_value.json)
- [ ] EXTCALL with value from EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_static_with_value.json)
- [ ] EXTCALL with value, not enough balance (evmone-tests: state_tests/state_transition/eof_calls/extcall_failing_with_value_balance_check.json)
- [x] EXTCALL with value, not enough balance (evmone-tests: state_tests/state_transition/eof_calls/extcall_failing_with_value_balance_check.json)
- [ ] EXTCALL with value, check additional charge for value (evmone-tests: state_tests/state_transition/eof_calls/extcall_failing_with_value_additional_cost.json)
- [ ] EXTCALL with gas not enough for callee to get 5000 gas (evmone-tests: state_tests/state_transition/eof_calls/extcall_min_callee_gas_failure_mode.json)
- [ ] RETURNDATA* after EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_output.json)
- [ ] RETURNDATA* after EXTDELEGATECALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_output.json state_tests/state_transition/eof_calls/extdelegatecall_returndatasize.json state_tests/state_transition/eof_calls/returndatacopy.json state_tests/state_transition/eof_calls/returndataload.json)
- [ ] RETURNDATA* after EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_output.json)
- [ ] RETURNDATA* after aborted EXT*CALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_returndatasize_abort.json)
- [ ] Failed EXTCALL clears returndata from previous EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_clears_returndata.json)
- [x] EXTCALL with gas not enough for callee to get 5000 gas (evmone-tests: state_tests/state_transition/eof_calls/extcall_min_callee_gas_failure_mode.json)
- [x] RETURNDATA* after EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_output.json)
- [x] RETURNDATA* after EXTDELEGATECALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_output.json state_tests/state_transition/eof_calls/extdelegatecall_returndatasize.json state_tests/state_transition/eof_calls/returndatacopy.json state_tests/state_transition/eof_calls/returndataload.json)
- [x] RETURNDATA* after EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_output.json)
- [x] RETURNDATA* after aborted EXT*CALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_returndatasize_abort.json)
- [x] Failed EXTCALL clears returndata from previous EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_clears_returndata.json)
- [ ] EXTCALL not enough gas for input memory charge (evmone-tests: state_tests/state_transition/eof_calls/extcall_memory.json)
- [ ] EXTDELEGATECALL not enough gas for input memory charge (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_memory.json)
- [ ] EXTSTATICCALL not enough gas for input memory charge (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_memory.json)
- [ ] EXTCALL exception due to target address overflow (bits set in high 12 bytes) (evmone-tests: state_tests/state_transition/eof_calls/extcall_ase_ready_violation.json)
- [ ] EXTDELEGATECALL exception due to target address overflow (bits set in high 12 bytes) (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_ase_ready_violation.json)
- [ ] EXTSTATICCALL exception due to target address overflow (bits set in high 12 bytes) (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_ase_ready_violation.json)
- [x] EXTCALL exception due to target address overflow (bits set in high 12 bytes) (evmone-tests: state_tests/state_transition/eof_calls/extcall_ase_ready_violation.json)
- [x] EXTDELEGATECALL exception due to target address overflow (bits set in high 12 bytes) (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_ase_ready_violation.json)
- [x] EXTSTATICCALL exception due to target address overflow (bits set in high 12 bytes) (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_ase_ready_violation.json)
- [ ] EXTCALL not enough gas for warming up target address (evmone-tests: state_tests/state_transition/eof_calls/extcall_cold_oog.json)
- [ ] EXTDELEGATECALL not enough gas for warming up target address (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_cold_oog.json)
- [ ] EXTSTATICCALL not enough gas for warming up target address (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_cold_oog.json)
- [ ] EXTCALL not enough gas for account creation cost (transfer value to non-existing account) (evmone-tests: state_tests/state_transition/eof_calls/extcall_value_zero_to_nonexistent_account.json)
- [ ] OOG after EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_then_oog.json)
- [ ] OOG after EXTDELEGATECALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_then_oog.json)
- [ ] OOG after EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_then_oog.json)
- [ ] REVERT inside EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_callee_revert.json)
- [ ] REVERT inside EXTDELEGATECALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_callee_revert.json)
- [ ] REVERT inside EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_callee_revert.json)
- [ ] EXTCALL with input (evmone-tests: state_tests/state_transition/eof_calls/extcall_input.json)
- [ ] EXTDELEGATECALL with input (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_input.json)
- [ ] EXTSTATICCALL with input (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_input.json)
- [ ] EXTCALL with just enough gas for MIN_RETAINED_GAS and MIN_CALLEE_GAS (evmone-tests: state_tests/state_transition/eof_calls/extcall_with_value_enough_gas.json)
- [ ] EXTCALL with not enough gas for MIN_CALLEE_GAS (evmone-tests: state_tests/state_transition/eof_calls/extcall_with_value_enough_gasextcall_with_value_low_gas.json)
pdobacz marked this conversation as resolved.
Show resolved Hide resolved
- [x] OOG after EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_then_oog.json)
- [x] OOG after EXTDELEGATECALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_then_oog.json)
- [x] OOG after EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_then_oog.json)
- [x] REVERT inside EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_callee_revert.json)
- [x] REVERT inside EXTDELEGATECALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_callee_revert.json)
- [x] REVERT inside EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_callee_revert.json)
- [x] EXTCALL with input (evmone-tests: state_tests/state_transition/eof_calls/extcall_input.json)
- [x] EXTDELEGATECALL with input (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_input.json)
- [x] EXTSTATICCALL with input (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_input.json)
- [x] EXTCALL with just enough gas for MIN_RETAINED_GAS and MIN_CALLEE_GAS (evmone-tests: state_tests/state_transition/eof_calls/extcall_with_value_enough_gas.json)
- [x] EXTCALL with not enough gas for MIN_CALLEE_GAS (evmone-tests: state_tests/state_transition/eof_calls/extcall_with_value_low_gas.json)
- [ ] ADDRESS and CALLER inside EXTCALL (evmone-tests: state_tests/state_transition/eof_calls/extcall_recipient_and_code_address.json)
- [ ] ADDRESS and CALLER inside EXTDELEGATECALL (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_recipient_and_code_address.json)
- [ ] ADDRESS and CALLER inside EXTSTATICCALL (evmone-tests: state_tests/state_transition/eof_calls/extstaticcall_recipient_and_code_address.json)
- [ ] Refund inside EXTCALL is applied after the transaction (evmone-tests: state_tests/state_transition/eof_calls/extcall_gas_refund_propagation.json)
- [ ] Refund inside EXTDELEGATECALL is applied after the transaction (evmone-tests: state_tests/state_transition/eof_calls/extdelegatecall_gas_refund_propagation.json)
- [ ] EXTSTATICCALL from EOF to non-pure legacy contract failing (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP3540/EOF1_CallsFiller.yml)
- [ ] EXTSTATICCALL from EOF to pure EOF contract (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP3540/EOF1_CallsFiller.yml)
- [ ] EXTSTATICCALL from EOF to non-pure EOF contract failing (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP3540/EOF1_CallsFiller.yml)
- [x] EXTSTATICCALL from EOF to non-pure legacy contract failing (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP3540/EOF1_CallsFiller.yml)
- [x] EXTSTATICCALL from EOF to pure EOF contract (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP3540/EOF1_CallsFiller.yml)
- [x] EXTSTATICCALL from EOF to non-pure EOF contract failing (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP3540/EOF1_CallsFiller.yml)


## EIP-7620: EOF Contract Creation
Expand Down