Skip to content

test_invalid_signature_values()

Documentation for tests/frontier/validation/test_transaction_rlp.py::test_invalid_signature_values@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/frontier/validation/test_transaction_rlp.py::test_invalid_signature_values --fork Bogota

Replace a signature field with a well-encoded but invalid value: zero r or s, or a v that is neither 27, 28 nor an EIP-155 value.

Before EIP-155 any v other than 27 or 28 is a plain invalid v; afterwards clients may instead derive a chain id from the invalid v and reject the transaction for the chain id mismatch.

Source code in tests/frontier/validation/test_transaction_rlp.py
@pytest.mark.ported_from(
    [
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithRvalue0Filler.json",
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithSvalue0Filler.json",
        f"{LEGACY_TX_TESTS}/ttVValue/V_wrongvalue_ffFiller.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/tr201506052141PYTHONCopier.json",
    ],
)
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "field, payload, error",
    [
        ("r", b"", TransactionException.INVALID_SIGNATURE_VRS),
        ("s", b"", TransactionException.INVALID_SIGNATURE_VRS),
        (
            "v",
            b"",
            [
                TransactionException.INVALID_SIGNATURE_VRS,
                TransactionException.INVALID_CHAINID,
            ],
        ),
        (
            "v",
            b"\x1d",
            [
                TransactionException.INVALID_SIGNATURE_VRS,
                TransactionException.INVALID_CHAINID,
            ],
        ),
        (
            "v",
            b"\xff",
            [
                TransactionException.INVALID_SIGNATURE_VRS,
                TransactionException.INVALID_CHAINID,
            ],
        ),
    ],
    ids=["r_zero", "s_zero", "v_zero", "v_29", "v_255"],
)
def test_invalid_signature_values(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    fork: Fork,
    field: str,
    payload: bytes,
    error: TransactionException | list[TransactionException],
) -> None:
    """
    Replace a signature field with a well-encoded but invalid value:
    zero r or s, or a v that is neither 27, 28 nor an EIP-155 value.

    Before EIP-155 any v other than 27 or 28 is a plain invalid v;
    afterwards clients may instead derive a chain id from the invalid
    v and reject the transaction for the chain id mismatch.
    """
    fields = signed_tx_fields(pre, fork)
    fields[field] = payload
    rlp = encode_tx(fields)
    transaction_test(pre=pre, tx=invalid_tx(pre, rlp, error))

Parametrized Test Cases

This test generates 5 parametrized test cases across 17 forks.