Skip to content

test_field_overflow()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
@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 16 forks.