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-4762 *CALL with insufficient gas #867

Merged
merged 4 commits into from
Oct 2, 2024
Merged
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
58 changes: 31 additions & 27 deletions tests/verkle/eip4762_verkle_gas_witness/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,40 @@ def test_calls_warm(blockchain_test: BlockchainTestFiller, fork: Fork, call_inst


@pytest.mark.valid_from("Verkle")
@pytest.mark.skip("Pending TBD gas limits")
@pytest.mark.parametrize(
"call_instruction, gas_limit",
"call_instruction, value_bearing, gas_limit, enough_gas_call_target",
[
(Op.CALL, "TBD_insufficient_dynamic_cost"),
(Op.CALL, "TBD_insufficient_value_bearing"),
(Op.CALL, "TBD_insufficient_63/64"),
(Op.CALLCODE, "TBD_insufficient_dynamic_cost"),
(Op.CALLCODE, "TBD_insufficient_value_bearing"),
(Op.CALLCODE, "TBD_insufficient_63/64"),
(Op.DELEGATECALL, "TBD_insufficient_dynamic_cost"),
(Op.DELEGATECALL, "TBD_insufficient_63/64"),
(Op.STATICCALL, "TBD_insufficient_dynamic_cost"),
(Op.STATICCALL, "TBD_insufficient_63/64"),
(Op.CALL, True, 21_421 + 3503 + 5599, False),
(Op.CALL, True, 21_421 + 3503 + 5600, True),
(Op.CALL, False, 21_421 + 1003 + 2099, False),
(Op.CALL, False, 21_424 + 1003 + 2100, True),
(Op.CALLCODE, False, 21_421 + 1003 + 2099, False),
(Op.CALLCODE, False, 21_421 + 1003 + 2100, True),
(Op.DELEGATECALL, False, 21_418 + 1003 + 2099, False),
(Op.DELEGATECALL, False, 21_418 + 1003 + 2100, True),
(Op.STATICCALL, False, 21_418 + 1003 + 2099, False),
(Op.STATICCALL, False, 21_418 + 1003 + 2100, True),
],
ids=[
"CALL_insufficient_dynamic_cost",
"CALL_insufficient_value_bearing",
"CALL_insufficient_minimum_63/64",
"CALLCODE_insufficient_dynamic_cost",
"CALLCODE_insufficient_value_bearing",
"CALLCODE_insufficient_minimum_63/64",
"DELEGATECALL_insufficient_dynamic_cost",
"DELEGATECALL_insufficient_minimum_63/64",
"STATICCALL_insufficient_dynamic_cost",
"STATICCALL_insufficient_minimum_63/64",
"CALL_with_value_insufficient_for_value_transfer_target",
"CALL_with_value_only_sufficient_for_value_transfer_target",
"CALL_with_value_insufficient_for_target_basic_data",
"CALL_with_value_only_sufficient_for_target_basic_data",
"CALLCODE_insufficient_for_target_basic_data",
"CALLCODE_only_sufficient_for_target_basic_data",
"DELEGATECALL_insufficient_for_target_basic_data",
"DELEGATECODE_only_sufficient_for_target_basic_data",
"STATICCALL_insufficient_for_target_basic_data",
"STATICCALL_only_sufficient_for_target_basic_data",
],
)
def test_calls_insufficient_gas(
blockchain_test: BlockchainTestFiller, fork: Fork, call_instruction: Bytecode, gas_limit
blockchain_test: BlockchainTestFiller,
fork: Fork,
call_instruction: Bytecode,
value_bearing: bool,
gas_limit,
enough_gas_call_target: bool,
):
"""
Test *CALL witness assertion when there's insufficient gas for different scenarios.
Expand All @@ -124,9 +128,9 @@ def test_calls_insufficient_gas(
fork,
call_instruction,
TestAddress2,
0,
1 if value_bearing else 0,
gas_limit=gas_limit,
enough_gas_read_witness=False,
enough_gas_call_target=enough_gas_call_target,
)


Expand All @@ -137,7 +141,7 @@ def _generic_call(
target: Address,
value,
gas_limit: int = 100000000,
enough_gas_read_witness: bool = True,
enough_gas_call_target: bool = True,
warm=False,
):
env = Environment(
Expand Down Expand Up @@ -181,7 +185,7 @@ def _generic_call(
witness_check = WitnessCheck(fork=Verkle)
for address in [TestAddress, caller_address, env.fee_recipient]:
witness_check.add_account_full(address=address, account=pre.get(address))
if enough_gas_read_witness:
if enough_gas_call_target:
if value > 0 or (target != precompile_address and target != precompile_address):
witness_check.add_account_basic_data(address=target, account=target_account)

Expand Down
Loading