Skip to content
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
10 changes: 9 additions & 1 deletion tests/byzantium/eip198_modexp_precompile/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,18 @@ class ModExpOutput(TestParameterGroup):
call_success (bool): The return_code from CALL, 0 indicates
unsuccessful call (out-of-gas), 1 indicates call
succeeded.
returned_data(str): The output returnData is the expected
returned_data (Bytes): The output returnData is the expected
output of the call.

"""

call_success: bool = True
returned_data: Bytes

def __len__(self) -> int:
"""Return the length of the returned data."""
return len(self.returned_data)

def __bytes__(self) -> bytes:
"""Return the returned data as bytes."""
return bytes(self.returned_data)
98 changes: 98 additions & 0 deletions tests/osaka/eip7823_modexp_upper_bounds/test_eip_mainnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
Mainnet marked execute checklist tests for
[EIP-7823: ModExp Upper Bound](https://eips.ethereum.org/EIPS/eip-7823).
"""

from typing import Dict

import pytest
from execution_testing import (
Alloc,
StateTestFiller,
Transaction,
)
from execution_testing.base_types.base_types import Bytes
from execution_testing.test_types.block_types import Environment

from ...byzantium.eip198_modexp_precompile.helpers import (
ModExpInput,
ModExpOutput,
)
from ..eip7883_modexp_gas_increase.spec import Spec
from .spec import ref_spec_7823

REFERENCE_SPEC_GIT_PATH = ref_spec_7823.git_path
REFERENCE_SPEC_VERSION = ref_spec_7823.version

pytestmark = [pytest.mark.valid_at("Osaka"), pytest.mark.mainnet]


@pytest.fixture
def call_succeeds(modexp_expected: ModExpOutput) -> bool:
"""Override `call_succeeds` to use the parametrized ModExpOutput value."""
return modexp_expected.call_success


@pytest.mark.parametrize(
"modexp_input,modexp_expected",
[
pytest.param(
ModExpInput(
base=b"\x01" * Spec.MAX_LENGTH_BYTES,
exponent=b"\x00",
modulus=b"\x02",
),
ModExpOutput(
call_success=True,
returned_data=Bytes(bytes.fromhex("01")),
),
id="base-boundary-1024-bytes",
),
],
)
def test_modexp_boundary(
state_test: StateTestFiller,
pre: Alloc,
tx: Transaction,
post: Dict,
) -> None:
"""
Mainnet test at the 1024-byte boundary.
Tests that the ModExp precompile correctly handles input at the maximum
allowed length (1024 bytes) per EIP-7823.
"""
state_test(env=Environment(), pre=pre, tx=tx, post=post)


@pytest.mark.parametrize(
"modexp_input,modexp_expected",
[
pytest.param(
ModExpInput(
base=b"\x01" * (Spec.MAX_LENGTH_BYTES + 1),
exponent=b"\x00",
modulus=b"\x02",
),
ModExpOutput(
call_success=False,
returned_data=Bytes(),
),
id="base-over-boundary-1025-bytes",
),
],
)
def test_modexp_over_boundary(
state_test: StateTestFiller,
pre: Alloc,
tx: Transaction,
post: Dict,
) -> None:
"""
Mainnet test exceeding the 1024-byte boundary.
Tests that the ModExp precompile correctly rejects input exceeding the
maximum allowed length (1024 bytes) per EIP-7823. This proves the EIP
is correctly activated.
"""
state_test(env=Environment(), pre=pre, tx=tx, post=post)
68 changes: 68 additions & 0 deletions tests/osaka/eip7825_transaction_gas_limit_cap/test_eip_mainnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Mainnet marked execute checklist tests for
[EIP-7825: Transaction Gas Limit Cap](https://eips.ethereum.org/EIPS/eip-7825).
"""

import pytest
from execution_testing import (
Account,
Alloc,
Environment,
Op,
StateTestFiller,
Storage,
Transaction,
TransactionException,
)

from .spec import Spec, ref_spec_7825

REFERENCE_SPEC_GIT_PATH = ref_spec_7825.git_path
REFERENCE_SPEC_VERSION = ref_spec_7825.version

pytestmark = [pytest.mark.valid_at("Osaka"), pytest.mark.mainnet]


def test_tx_gas_limit_cap_at_maximum(
state_test: StateTestFiller,
pre: Alloc,
env: Environment,
) -> None:
"""Test transaction at exactly the gas limit cap (2^24)."""
storage = Storage()
contract_address = pre.deploy_contract(
code=Op.SSTORE(storage.store_next(1), 1) + Op.STOP,
)

tx = Transaction(
to=contract_address,
sender=pre.fund_eoa(),
gas_limit=Spec.tx_gas_limit_cap,
)

post = {
contract_address: Account(storage=storage),
}

state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.exception_test
def test_tx_gas_limit_cap_exceeded(
state_test: StateTestFiller,
pre: Alloc,
env: Environment,
) -> None:
"""Test transaction exceeding the gas limit cap (2^24 + 1)."""
contract_address = pre.deploy_contract(
code=Op.SSTORE(0, 1) + Op.STOP,
)

tx = Transaction(
to=contract_address,
sender=pre.fund_eoa(),
gas_limit=Spec.tx_gas_limit_cap + 1,
error=TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM,
)

state_test(env=env, pre=pre, post={}, tx=tx)
59 changes: 40 additions & 19 deletions tests/osaka/eip7883_modexp_gas_increase/test_eip_mainnet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
Mainnet marked tests for EIP-7883 ModExp gas cost increase.

Tests for ModExp gas cost increase in
Mainnet marked execute checklist tests for
[EIP-7883: ModExp Gas Cost Increase](https://eips.ethereum.org/EIPS/eip-7883).
"""

Expand All @@ -13,8 +11,13 @@
StateTestFiller,
Transaction,
)
from execution_testing.base_types.base_types import Bytes
from execution_testing.test_types.block_types import Environment

from ...byzantium.eip198_modexp_precompile.helpers import ModExpInput
from ...byzantium.eip198_modexp_precompile.helpers import (
ModExpInput,
ModExpOutput,
)
from .spec import Spec, ref_spec_7883

REFERENCE_SPEC_GIT_PATH = ref_spec_7883.git_path
Expand All @@ -23,6 +26,12 @@
pytestmark = [pytest.mark.valid_at("Osaka"), pytest.mark.mainnet]


@pytest.fixture
def call_succeeds(modexp_expected: ModExpOutput) -> bool:
"""Override `call_succeeds` to use the parametrized ModExpOutput value."""
return modexp_expected.call_success


@pytest.mark.parametrize(
"modexp_input,modexp_expected",
[
Expand All @@ -35,8 +44,10 @@
declared_exponent_length=1,
declared_modulus_length=1,
),
# expected result:
bytes.fromhex("04"),
ModExpOutput(
call_success=True,
returned_data=Bytes(bytes.fromhex("04")),
),
id="32-bytes-long-base",
),
pytest.param(
Expand All @@ -48,8 +59,10 @@
declared_exponent_length=1,
declared_modulus_length=1,
),
# expected result:
bytes.fromhex("01"),
ModExpOutput(
call_success=True,
returned_data=Bytes(bytes.fromhex("01")),
),
id="33-bytes-long-base", # higher cost than 32 bytes
),
pytest.param(
Expand All @@ -61,8 +74,10 @@
declared_exponent_length=1024,
declared_modulus_length=1,
),
# expected result:
bytes.fromhex("02"),
ModExpOutput(
call_success=True,
returned_data=Bytes(bytes.fromhex("02")),
),
id="1024-bytes-long-exp",
),
pytest.param(
Expand All @@ -74,9 +89,13 @@
declared_exponent_length=3,
declared_modulus_length=64,
),
# expected result:
bytes.fromhex(
"c36d804180c35d4426b57b50c5bfcca5c01856d104564cd513b461d3c8b8409128a5573e416d0ebe38f5f736766d9dc27143e4da981dfa4d67f7dc474cbee6d2"
ModExpOutput(
call_success=True,
returned_data=Bytes(
bytes.fromhex(
"c36d804180c35d4426b57b50c5bfcca5c01856d104564cd513b461d3c8b8409128a5573e416d0ebe38f5f736766d9dc27143e4da981dfa4d67f7dc474cbee6d2"
)
),
),
id="nagydani-1-pow0x10001",
),
Expand All @@ -89,9 +108,13 @@
declared_exponent_length=64,
declared_modulus_length=32,
),
# expected result:
bytes.fromhex(
"0000000000000000000000000000000000000000000000000000000000000001"
ModExpOutput(
call_success=True,
returned_data=Bytes(
bytes.fromhex(
"0000000000000000000000000000000000000000000000000000000000000001"
)
),
),
id="zero-exponent-64bytes",
),
Expand All @@ -102,8 +125,6 @@ def test_modexp_different_base_lengths(
pre: Alloc,
tx: Transaction,
post: Dict,
modexp_input: ModExpInput,
modexp_expected: ModExpInput,
) -> None:
"""Mainnet test for triggering gas cost increase."""
state_test(pre=pre, tx=tx, post=post)
state_test(env=Environment(), pre=pre, tx=tx, post=post)
57 changes: 57 additions & 0 deletions tests/osaka/eip7939_count_leading_zeros/test_eip_mainnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Mainnet marked execute checklist tests for
[EIP-7939: Count leading zeros (CLZ)](https://eips.ethereum.org/EIPS/eip-7939).
"""

import pytest
from execution_testing import (
Account,
Alloc,
Op,
StateTestFiller,
Transaction,
)
from execution_testing.test_types.block_types import Environment

from .spec import ref_spec_7939

REFERENCE_SPEC_GIT_PATH = ref_spec_7939.git_path
REFERENCE_SPEC_VERSION = ref_spec_7939.version

pytestmark = [pytest.mark.valid_at("Osaka"), pytest.mark.mainnet]


@pytest.mark.parametrize(
"clz_input,clz_expected",
[
pytest.param(
0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
8,
id="clz-8-leading-zeros",
),
pytest.param(0, 256, id="clz-all-zeros"),
],
)
def test_clz_mainnet(
state_test: StateTestFiller,
pre: Alloc,
clz_input: int,
clz_expected: int,
) -> None:
"""
Test CLZ opcode on mainnet.
"""
sender = pre.fund_eoa()
contract_address = pre.deploy_contract(
code=Op.SSTORE(0, Op.CLZ(clz_input)),
storage={"0x00": "0xdeadbeef"},
)
tx = Transaction(
to=contract_address,
sender=sender,
gas_limit=200_000,
)
post = {
contract_address: Account(storage={"0x00": clz_expected}),
}
state_test(env=Environment(), pre=pre, post=post, tx=tx)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Mainnet marked tests for [EIP-7951: Precompile for secp256r1 Curve Support](https://eips.ethereum.org/EIPS/eip-7951).
Mainnet marked execute checklist tests for
[EIP-7951: Precompile for secp256r1 Curve Support](https://eips.ethereum.org/EIPS/eip-7951).
"""

import pytest
Expand All @@ -25,7 +26,7 @@
"input_data",
[
pytest.param(
H( # 'hello world' r1 signed with privkey 0xd946578401d1980aba1fc85df2a1ddc0d2d618aadd37b213f7f7f91a553b1499 # noqa: E501
H( # 'hello world' r1 signed with private key 0xd946578401d1980aba1fc85df2a1ddc0d2d618aadd37b213f7f7f91a553b1499 # noqa: E501
0xB94D27B9934D3E08A52E52D7DA7DABFAC484EFE37A5380EE9088F7ACE2EFCDE9
)
+ R(
Expand Down Expand Up @@ -59,7 +60,7 @@ def test_valid(
"input_data",
[
pytest.param(
H( # 'hello world' k1 signed (with eth prefix) with privkey 0xd946578401d1980aba1fc85df2a1ddc0d2d618aadd37b213f7f7f91a553b1499 # noqa: E501
H( # 'hello world' k1 signed (with eth prefix) with private key 0xd946578401d1980aba1fc85df2a1ddc0d2d618aadd37b213f7f7f91a553b1499 # noqa: E501
0xD9EBA16ED0ECAE432B71FE008C98CC872BB4CC214D3220A36F365326CF807D68
)
+ R(
Expand Down
Loading