Skip to content

test_bad_v_r_s()

Documentation for tests/frontier/validation/test_transaction.py::test_bad_v_r_s@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/frontier/validation/test_transaction.py::test_bad_v_r_s --fork Bogota

The v/y_parity component of a signature must be 35 or greater (if it isn't 27/28).

Source code in tests/frontier/validation/test_transaction.py
@pytest.mark.inclusion_test
@pytest.mark.valid_from("Frontier")
@pytest.mark.exception_test
@pytest.mark.eels_base_coverage
@pytest.mark.with_all_tx_types
@pytest.mark.parametrize(
    ("v", "r", "s"),
    [
        # Other than 27/28, anything less than 35 for v is invalid.
        (34, 1, 1),
        # Equal to or above these values are invalid.
        (27, SECP256K1N, 1),
        pytest.param(27, 1, SECP256K1N, id="s=SECP256K1N"),
        pytest.param(
            27,
            1,
            (SECP256K1N // 2) + 1,
            id="s=SECP256K1N//2+1",
            marks=pytest.mark.valid_from("Homestead"),
        ),
    ],
)
def test_bad_v_r_s(
    state_test: StateTestFiller,
    pre: Alloc,
    tx_type: int,
    v: int,
    r: int,
    s: int,
) -> None:
    """
    The v/y_parity component of a signature must be 35 or greater (if it isn't
    27/28).
    """
    to = pre.fund_eoa(0xDEADBEEE)

    error: TransactionExceptionInstanceOrList = (
        TransactionException.INVALID_SIGNATURE_VRS
    )
    if tx_type == 0 and v not in (27, 28):
        # A legacy transaction encodes its chain id within v, so a client that
        # derives the chain id from an out-of-range v rejects the transaction
        # with a chain id mismatch instead of an invalid signature.
        error = [
            TransactionException.INVALID_SIGNATURE_VRS,
            TransactionException.INVALID_CHAINID,
        ]

    blob_versioned_hashes = add_kzg_version([0], 1) if tx_type == 3 else None
    tx = Transaction(
        sender=pre.fund_eoa(),
        to=to,
        error=error,
        ty=tx_type,
        blob_versioned_hashes=blob_versioned_hashes,
        value=1,
        v=v,
        r=r,
        s=s,
    )

    state_test(
        pre=pre,
        post={to: Account(balance=0xDEADBEEE)},
        tx=tx,
    )

Parametrized Test Cases

This test generates 20 parametrized test cases across 16 forks.