Skip to content

test_field_overflow()

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

Generate fixtures for these test cases for Bogota with:

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

Encode one integer field as a 33-byte value (2**256), exceeding the 256-bit width of the field. The spec decodes the nonce as a 256-bit scalar as well; its 64-bit bound is a validation rule (EIP-2681), not a decoding one, and clients that store the nonce in 64 bits reject the oversized encoding all the same.

The gas limit and gas price are unbounded scalars in the spec, so oversized values there are not a decoding error and are rejected only in block context. The signature v is also a bounded 256-bit field, but has no field-specific decoding exception, so its oversized encoding is not covered here.

Source code in tests/frontier/validation/test_transaction_rlp.py
@pytest.mark.ported_from(
    [
        f"{LEGACY_TX_TESTS}/ttNonce/TransactionWithNonceOverflowFiller.json",
        f"{LEGACY_TX_TESTS}/ttValue/TransactionWithHighValueOverflowFiller.json",
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithRvalueOverflowFiller.json",
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithSvalueOverflowFiller.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_rvalue_TooLargeCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_svalue_TooLargeCopier.json",
    ],
)
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "field, error",
    [
        ("nonce", TransactionException.RLP_INVALID_NONCE),
        ("value", TransactionException.VALUE_OVERFLOW),
        ("r", TransactionException.RLP_INVALID_SIGNATURE_R),
        ("s", TransactionException.RLP_INVALID_SIGNATURE_S),
    ],
)
def test_field_overflow(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    fork: Fork,
    field: str,
    error: TransactionException,
) -> None:
    """
    Encode one integer field as a 33-byte value (2**256), exceeding the
    256-bit width of the field. The spec decodes the nonce as a 256-bit
    scalar as well; its 64-bit bound is a validation rule (EIP-2681),
    not a decoding one, and clients that store the nonce in 64 bits
    reject the oversized encoding all the same.

    The gas limit and gas price are unbounded scalars in the spec, so
    oversized values there are not a decoding error and are rejected
    only in block context. The signature v is also a bounded 256-bit
    field, but has no field-specific decoding exception, so its
    oversized encoding is not covered here.
    """
    fields = signed_tx_fields(pre, fork)
    corrupted = rlp_bytes(int_payload(2**256))
    rlp = encode_tx(fields, {field: corrupted})
    transaction_test(pre=pre, tx=invalid_tx(pre, rlp, error))

Parametrized Test Cases

This test generates 4 parametrized test cases across 17 forks.