Skip to content

Commit

Permalink
verkle: reenable call subtests
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Sep 20, 2024
1 parent d0e104e commit 7ea89a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
40 changes: 26 additions & 14 deletions tests/verkle/eip4762_verkle_gas_witness/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

from ethereum_test_forks import Verkle
from ethereum_test_forks import Fork
from ethereum_test_tools import (
Account,
Address,
Expand Down Expand Up @@ -48,22 +49,22 @@
@pytest.mark.parametrize(
"target",
[
# TestAddress2,
TestAddress2,
precompile_address,
# system_contract_address,
system_contract_address,
],
)
def test_calls(
blockchain_test: BlockchainTestFiller,
fork: str,
fork: Fork,
call_instruction: Bytecode,
target: Address,
value,
):
"""
Test *CALL instructions gas and witness.
"""
_generic_call(blockchain_test, call_instruction, target, value)
_generic_call(blockchain_test, fork, call_instruction, target, value)


@pytest.mark.valid_from("Verkle")
Expand All @@ -76,11 +77,11 @@ def test_calls(
Op.STATICCALL,
],
)
def test_calls_warm(blockchain_test: BlockchainTestFiller, fork: str, call_instruction: Bytecode):
def test_calls_warm(blockchain_test: BlockchainTestFiller, fork: Fork, call_instruction: Bytecode):
"""
Test *CALL warm cost.
"""
_generic_call(blockchain_test, call_instruction, TestAddress2, 0, warm=True)
_generic_call(blockchain_test, fork, call_instruction, TestAddress2, 0, warm=True)


@pytest.mark.valid_from("Verkle")
Expand Down Expand Up @@ -113,13 +114,14 @@ def test_calls_warm(blockchain_test: BlockchainTestFiller, fork: str, call_instr
],
)
def test_calls_insufficient_gas(
blockchain_test: BlockchainTestFiller, call_instruction: Bytecode, gas_limit
blockchain_test: BlockchainTestFiller, fork: Fork, call_instruction: Bytecode, gas_limit
):
"""
Test *CALL witness assertion when there's insufficient gas for different scenarios.
"""
_generic_call(
blockchain_test,
fork,
call_instruction,
TestAddress2,
0,
Expand All @@ -130,6 +132,7 @@ def test_calls_insufficient_gas(

def _generic_call(
blockchain_test: BlockchainTestFiller,
fork: Fork,
call_instruction,
target: Address,
value,
Expand Down Expand Up @@ -159,7 +162,6 @@ def _generic_call(
balance=2000000000000000000000, code=caller_code * (2 if warm else 1)
),
precompile_address: Account(balance=3000000000000000000000),
system_contract_address: Account(balance=4000000000000000000000),
}

tx = Transaction(
Expand All @@ -171,22 +173,32 @@ def _generic_call(
gas_price=10,
value=tx_value,
)

target_account = (
pre[target]
if target != system_contract_address
else Account(**fork.pre_allocation_blockchain()[system_contract_address])
)
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 value > 0 or (target != precompile_address and target != precompile_address):
witness_check.add_account_basic_data(address=target, account=pre[target])
witness_check.add_account_basic_data(address=target, account=target_account)

code_chunks = chunkify_code(pre[caller_address].code)
for i, chunk in enumerate(code_chunks, start=0):
witness_check.add_code_chunk(address=caller_address, chunk_number=i, value=chunk)
code_chunks = chunkify_code(pre[target].code)
if target != precompile_address and target != system_contract_address:
if target != precompile_address:
code_chunks = chunkify_code(target_account.code)
for i, chunk in enumerate(code_chunks, start=0):
witness_check.add_code_chunk(address=target, chunk_number=i, value=chunk)

if target == system_contract_address:
# If the target is the 2935 system contract, we should check for the first storage-slot.
# The account storage address depends on the kind of *CALL done.
sslot_target = system_contract_address if call_instruction == Op.CALL else caller_address
witness_check.add_storage_slot(address=sslot_target, storage_slot=0, value=None)

blocks = [
Block(
txs=[tx],
Expand All @@ -199,11 +211,11 @@ def _generic_call(
caller_address: Account(
balance=pre[caller_address].balance + value, code=pre[caller_address].code
),
target: pre[target],
target: target_account,
}
else:
post = {
target: Account(balance=pre[target].balance + value, code=pre[target].code),
target: Account(balance=target_account.balance + value, code=target_account.code),
}

blockchain_test(
Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ verkle
vkt
chunkify
chunkified
sslot

fi
url
Expand Down

0 comments on commit 7ea89a9

Please sign in to comment.