Skip to content

test_data_size_leading_zeros()

Documentation for tests/frontier/validation/test_transaction_rlp.py::test_data_size_leading_zeros@622620d8.

Generate fixtures for these test cases for Amsterdam with:

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

Encode the size of the data field's long-form string header with a leading zero byte; the non-canonical encoding must be rejected.

Source code in tests/frontier/validation/test_transaction_rlp.py
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
@pytest.mark.ported_from(
    [
        f"{LEGACY_TX_TESTS}/ttWrongRLP/"
        "RLPArrayLengthWithFirstZerosCopier.json",
    ],
)
@pytest.mark.exception_test
def test_data_size_leading_zeros(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Encode the size of the data field's long-form string header with a
    leading zero byte; the non-canonical encoding must be rejected.
    """
    fields = signed_tx_fields(pre, fork, data=b"\xff" * 64)
    payload = fields["data"]
    # The corruption assumes the long-form string header.
    assert len(payload) >= 56
    size = len(payload).to_bytes(2, "big")
    assert size[0] == 0
    corrupted = bytes([0x80 + 55 + len(size)]) + size + payload
    rlp = encode_tx(fields, {"data": corrupted})
    transaction_test(
        pre=pre,
        tx=invalid_tx(
            pre, rlp, TransactionException.RLP_LEADING_ZEROS_DATA_SIZE
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 16 forks.