Skip to content

Add fixed P2MR CHECKSIGPQC coverage for missing-output SIGHASH_SINGLE #48

Closed

Description

@kiwidream

Expected Behavior

P2MR OP_CHECKSIGPQC with SIGHASH_SINGLE must reject when the signing input has no corresponding transaction output.

Source behavior on 0.1.x:

  • SignatureHashP2MR uses SignatureHashSchnorrCommon with the P2MRSighash tag.
  • In that common path, SIGHASH_SINGLE returns failure when in_pos >= tx_to.vout.size().
  • CheckPQCSignature maps that failed P2MR sighash computation to SCRIPT_ERR_P2MR_SIG_HASHTYPE.
  • Wallet signing also avoids producing SIGHASH_SINGLE signatures for inputs without matching outputs.

So the intended behavior appears to be rejection with SCRIPT_ERR_P2MR_SIG_HASHTYPE, not substitution with another mode and not a defined digest.

Current Evidence Gap

Generic Bitcoin tests cover legacy/taproot missing-output SIGHASH_SINGLE, but I did not find a fixed P2MR/PQC-specific fixture for this edge.

Checked:

Consensus Risk

This is a consensus-sensitive edge because P2MR uses a P2MR-specific sighash domain and PQC signature verification path. Relying on inherited legacy/taproot tests leaves a gap where a future refactor could accidentally:

  • produce a digest for missing-output SIGHASH_SINGLE,
  • map the failure to a different script error,
  • sign such inputs in wallet/PSBT code,
  • or diverge from intended P2MR behavior while generic tests still pass.

Randomized fuzz coverage is useful but not a launch-blocking oracle for this exact consensus boundary.

Recommended Fixed Fixture

Add independent P2MR CHECKSIGPQC vectors, preferably in p2mr_pqc_witness_vectors.json, with tests in script_p2mr_tests.

Cover these boundaries:

  1. input_index == outputs.size() - 1

    • Valid matched-output SIGHASH_SINGLE.
    • Include exact transaction transcript, prevout, leaf script, control block, p2mrSigMsg, p2mrSighash, and PQC signature.
    • Expected result: SCRIPT_ERR_OK.
  2. input_index == outputs.size()

    • First missing-output case.
    • Include exact transaction/witness transcript and signature bytes with explicit SIGHASH_SINGLE.
    • Expected result: SCRIPT_ERR_P2MR_SIG_HASHTYPE.
    • Assert SignatureHashP2MR(..., MissingDataBehavior::FAIL) returns false.
  3. input_index > outputs.size()

    • Beyond-bound missing-output case.
    • Same expected result: SCRIPT_ERR_P2MR_SIG_HASHTYPE.
    • This prevents an off-by-one-only test from missing deeper out-of-range handling.

If practical, repeat the missing-output cases for SIGHASH_SINGLE | SIGHASH_ANYONECANPAY, since the output selector is still SIGHASH_SINGLE.

Closure Criteria

  • A PR adds fixed, deterministic P2MR/PQC fixture coverage for the three boundary cases above.
  • The valid boundary vector includes independently generated p2mrSigMsg, p2mrSighash, and signature.
  • The missing-output vectors assert exact rejection reason SCRIPT_ERR_P2MR_SIG_HASHTYPE.
  • Tests prove P2MR behavior directly through VerifyScript/CHECKSIGPQC, not only wallet signing refusal.
  • The test comments explain that P2MR intentionally rejects missing-output SIGHASH_SINGLE rather than inheriting legacy’s uint256::ONE behavior.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions