Skip to content

Add independent P2MR/CTV commitment vectors for script tests #21

Closed

Description

@kiwidream

Summary

Some P2MR and CTV script tests construct expected-good spends using the same production helper functions that consensus code relies on.

That gives useful coverage for wiring and script execution, but it leaves a test-oracle gap: a helper regression can become self-confirming if the test uses the same helper to build the expected value and the consensus path uses it to verify the spend.

Impact

A shared bug in P2MR commitment construction, leaf/root hashing, CTV hash assembly, or witness construction could pass tests because both sides are wrong in the same way.

This is a test coverage hardening issue, not evidence that current P2MR or CTV behavior is broken.

Source Trace

Relevant areas:

  • src/test/script_p2mr_tests.cpp: P2MR and CTV script-level tests
  • src/test/fuzz/p2mr_script.cpp: P2MR script fuzz target
  • test/functional/feature_p2mr.py: functional P2MR coverage
  • src/script/interpreter.cpp: P2MR and CTV verification behavior
  • src/script/p2mr.h and related script commitment helpers

The functional suite has some independent P2MR tagged-hash derivation, but end-to-end accepted/rejected spend construction should also include fixed vectors that do not call production commitment/hash helpers to build expected-good cases.

Expected Behavior

The test suite should include fixed independent vectors for at least:

  • one end-to-end P2MR commitment path
  • one CTV spend path

Those vectors should be derived from serialized bytes or an external/review-local oracle, not from the same production helpers used by the consensus implementation.

Proposed Fix

Add fixture-based tests that include:

  • serialized script bytes
  • leaf version
  • expected P2MR leaf hash
  • branch/control data, if applicable
  • expected P2MR root/program
  • serialized transaction context
  • expected CTV hash for at least one CTV spend
  • positive and negative expected results

The positive vectors should verify successfully through the normal script path.

The negative companion vectors should fail after mutating one of:

  • script bytes
  • leaf version
  • branch/control path
  • output program/root
  • CTV committed hash
  • transaction field covered by the CTV hash

Suggested Tests

Add coverage that verifies:

  • a fixed independently-derived P2MR output/spend succeeds
  • a one-byte script or branch mutation fails
  • a wrong leaf version fails when expected
  • a fixed independently-derived CTV spend succeeds
  • a mutated CTV-covered transaction field fails
  • the vectors remain stable even if helper implementations are refactored

The goal is to prevent production P2MR/CTV helper code and test setup code from accidentally redefining the same consensus byte contract together.

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