Skip to content

test_invalid_signature_values()

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

Generate fixtures for these test cases for Amsterdam with:

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

Replace a signature field with a well-encoded but invalid value: zero r or s, or a v that is neither 27, 28 nor an EIP-155 value.

Before EIP-155 any v other than 27 or 28 is a plain invalid v; afterwards clients may instead derive a chain id from the invalid v and reject the transaction for the chain id mismatch.

Source code in tests/frontier/validation/test_transaction_rlp.py
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
@pytest.mark.ported_from(
    [
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithRvalue0Filler.json",
        f"{LEGACY_TX_TESTS}/ttRSValue/TransactionWithSvalue0Filler.json",
        f"{LEGACY_TX_TESTS}/ttVValue/V_wrongvalue_ffFiller.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/tr201506052141PYTHONCopier.json",
    ],
)
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "field, payload, error",
    [
        ("r", b"", TransactionException.INVALID_SIGNATURE_VRS),
        ("s", b"", TransactionException.INVALID_SIGNATURE_VRS),
        (
            "v",
            b"",
            [
                TransactionException.INVALID_SIGNATURE_VRS,
                TransactionException.INVALID_CHAINID,
            ],
        ),
        (
            "v",
            b"\x1d",
            [
                TransactionException.INVALID_SIGNATURE_VRS,
                TransactionException.INVALID_CHAINID,
            ],
        ),
        (
            "v",
            b"\xff",
            [
                TransactionException.INVALID_SIGNATURE_VRS,
                TransactionException.INVALID_CHAINID,
            ],
        ),
    ],
    ids=["r_zero", "s_zero", "v_zero", "v_29", "v_255"],
)
def test_invalid_signature_values(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    fork: Fork,
    field: str,
    payload: bytes,
    error: TransactionException | list[TransactionException],
) -> None:
    """
    Replace a signature field with a well-encoded but invalid value:
    zero r or s, or a v that is neither 27, 28 nor an EIP-155 value.

    Before EIP-155 any v other than 27 or 28 is a plain invalid v;
    afterwards clients may instead derive a chain id from the invalid
    v and reject the transaction for the chain id mismatch.
    """
    fields = signed_tx_fields(pre, fork)
    fields[field] = payload
    rlp = encode_tx(fields)
    transaction_test(pre=pre, tx=invalid_tx(pre, rlp, error))

Parametrized Test Cases

This test generates 5 parametrized test cases across 16 forks.