Skip to content

test_field_leading_zeros()

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

Generate fixtures for these test cases for Bogota with:

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

Prefix one integer field's payload with a zero byte; the non-canonical encoding must be rejected. The base nonce is zero, so its variant is the classic zero-encoded-as-0x00 case.

Source code in tests/frontier/validation/test_transaction_rlp.py
@pytest.mark.ported_from(
    [
        f"{LEGACY_TX_TESTS}/ttWrongRLP/RLPNonceWithFirstZerosCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/RLPgasPriceWithFirstZerosCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/RLPgasLimitWithFirstZerosCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/RLPValueWithFirstZerosCopier.json",
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithRvaluePrefixed00Filler.json",
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithSvaluePrefixed00Filler.json",
        f"{LEGACY_TX_TESTS}/ttRSValue/RightVRSTestVPrefixedBy0Filler.json",
        f"{LEGACY_TX_TESTS}/ttNonce/TransactionWithLeadingZerosNonceFiller.json",
        f"{LEGACY_TX_TESTS}/ttNonce/TransactionWithZerosBigIntFiller.json",
        f"{LEGACY_TX_TESTS}/ttGasPrice/"
        "TransactionWithLeadingZerosGasPriceFiller.json",
        f"{LEGACY_TX_TESTS}/ttGasLimit/"
        "TransactionWithLeadingZerosGasLimitFiller.json",
        f"{LEGACY_TX_TESTS}/ttValue/TransactionWithLeadingZerosValueFiller.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_gasLimit_Prefixed0000Copier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_rvalue_Prefixed0000Copier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_svalue_Prefixed0000Copier.json",
    ],
)
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "field, error",
    [
        ("nonce", TransactionException.RLP_LEADING_ZEROS_NONCE),
        ("gas_price", TransactionException.RLP_LEADING_ZEROS_GASPRICE),
        ("gas_limit", TransactionException.RLP_LEADING_ZEROS_GASLIMIT),
        ("value", TransactionException.RLP_LEADING_ZEROS_VALUE),
        ("v", TransactionException.RLP_LEADING_ZEROS_V),
        ("r", TransactionException.RLP_LEADING_ZEROS_R),
        ("s", TransactionException.RLP_LEADING_ZEROS_S),
    ],
)
def test_field_leading_zeros(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    fork: Fork,
    field: str,
    error: TransactionException,
) -> None:
    """
    Prefix one integer field's payload with a zero byte; the
    non-canonical encoding must be rejected. The base nonce is zero, so
    its variant is the classic zero-encoded-as-0x00 case.
    """
    fields = signed_tx_fields(pre, fork)
    corrupted = rlp_bytes(b"\x00" + fields[field])
    rlp = encode_tx(fields, {field: corrupted})
    transaction_test(pre=pre, tx=invalid_tx(pre, rlp, error))

Parametrized Test Cases

This test generates 7 parametrized test cases across 17 forks.