Skip to content

test_bad_v_r_s()

Documentation for tests/frontier/validation/test_transaction.py::test_bad_v_r_s@5fa5938b.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/frontier/validation/test_transaction.py::test_bad_v_r_s --fork Amsterdam

The v/y_parity component of a signature must be 35 or greater (if it isn't 27/28).

Source code in tests/frontier/validation/test_transaction.py
252
253
254
255
256
257
258
259
260
261
262
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
307
308
309
310
311
312
313
314
315
316
@pytest.mark.valid_from("Frontier")
@pytest.mark.exception_test
@pytest.mark.eels_base_coverage
@pytest.mark.with_all_tx_types
@pytest.mark.parametrize(
    ("v", "r", "s"),
    [
        # Other than 27/28, anything less than 35 for v is invalid.
        (34, 1, 1),
        # Equal to or above these values are invalid.
        (27, SECP256K1N, 1),
        pytest.param(27, 1, SECP256K1N, id="s=SECP256K1N"),
        pytest.param(
            27,
            1,
            (SECP256K1N // 2) + 1,
            id="s=SECP256K1N//2+1",
            marks=pytest.mark.valid_from("Homestead"),
        ),
    ],
)
def test_bad_v_r_s(
    state_test: StateTestFiller,
    pre: Alloc,
    tx_type: int,
    v: int,
    r: int,
    s: int,
) -> None:
    """
    The v/y_parity component of a signature must be 35 or greater (if it isn't
    27/28).
    """
    to = pre.fund_eoa(0xDEADBEEE)

    error: TransactionExceptionInstanceOrList = (
        TransactionException.INVALID_SIGNATURE_VRS
    )
    if tx_type == 0 and v not in (27, 28):
        # A legacy transaction encodes its chain id within v, so a client that
        # derives the chain id from an out-of-range v rejects the transaction
        # with a chain id mismatch instead of an invalid signature.
        error = [
            TransactionException.INVALID_SIGNATURE_VRS,
            TransactionException.INVALID_CHAINID,
        ]

    blob_versioned_hashes = add_kzg_version([0], 1) if tx_type == 3 else None
    tx = Transaction(
        sender=pre.fund_eoa(),
        to=to,
        error=error,
        ty=tx_type,
        blob_versioned_hashes=blob_versioned_hashes,
        value=1,
        v=v,
        r=r,
        s=s,
    )

    state_test(
        pre=pre,
        post={to: Account(balance=0xDEADBEEE)},
        tx=tx,
    )

Parametrized Test Cases

This test generates 20 parametrized test cases across 15 forks.