Skip to content

test_field_leading_zeros()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
@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 16 forks.