Skip to content

Commit

Permalink
new(tests): eip-4762 *CALL with insufficient gas (#867)
Browse files Browse the repository at this point in the history
* insufficient gas

Signed-off-by: Ignacio Hagopian <[email protected]>

* verkle: add CALLCODE insufficient gas tests

Signed-off-by: Ignacio Hagopian <[email protected]>

* verkle: add DELEGATECODE insufficient gas tests

Signed-off-by: Ignacio Hagopian <[email protected]>

* verkle: add STATICCALL insufficient gas tests

Signed-off-by: Ignacio Hagopian <[email protected]>

---------

Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign authored Oct 2, 2024
1 parent a796b49 commit d29811d
Showing 1 changed file with 31 additions and 27 deletions.
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

0 comments on commit d29811d

Please sign in to comment.