Skip to content

Use mathematical notation for semantic policy Display#914

Open
febyeji wants to merge 1 commit intorust-bitcoin:masterfrom
febyeji:semantic-policy-display
Open

Use mathematical notation for semantic policy Display#914
febyeji wants to merge 1 commit intorust-bitcoin:masterfrom
febyeji:semantic-policy-display

Conversation

@febyeji
Copy link
Copy Markdown

@febyeji febyeji commented Apr 1, 2026

Closes #885 (partially)

Summary

  • Change semantic::Policy Display impl to use mathematical notation:
    • and(a,b)(a ∧ b)
    • or(a,b)(a ∨ b)
    • thresh(k,a,b,c)#{a, b, c} = k
  • Remove serde_string_impl_pk! since Display is no longer round-trippable with FromStr

Note

  • The issue mentions several approaches for threshold notation (e.g. (2 = a + b + c)). This PR uses #{a, b, c} = k. Happy to change if a different notation is preferred!
  • The regression_descriptor_parse fuzz test previously compared lifted semantic policy to_string() output between the current crate and old_miniscript. Since the Display format has intentionally changed to mathematical notation, and cross-crate structural comparison is not possible (FuzzPk's Display/FromStr don't roundtrip), the test now only verifies that both crates agree on liftability (both succeed or both fail). Please tell me if we need more rigorous comparison here.

@febyeji febyeji force-pushed the semantic-policy-display branch from a0d28b3 to aee1d82 Compare April 1, 2026 05:50
@apoelstra
Copy link
Copy Markdown
Member

  • thresh(k,a,b,c)#{a, b, c} ≥ k

The correct inequality is =, not . If you provide too many satisfactions your witness will be invalid. But concept ACK using this brace/comma notation. I think it will be easier to read in a large expression than my notation was.

febyeji added a commit to febyeji/rust-miniscript that referenced this pull request Apr 2, 2026
thresh requires exactly k satisfactions to be valid, not k or more.
Providing too many satisfactions makes the witness invalid.

Addresses apoelstra's review feedback on PR rust-bitcoin#914.
@febyeji
Copy link
Copy Markdown
Author

febyeji commented Apr 2, 2026

Thanks for the review! Changed ≥ to = and added a doc comment to Display noting the notation and that it's not parseable.

@apoelstra
Copy link
Copy Markdown
Member

Can you squash these commits, so that there isn't one modifying code introduced by the other?

- Use mathematical symbols (∧, ∨, #{...} = k) instead of and()/or()/thresh()
for semantic policy Display output.
- Update fuzz regression test to compare liftability only
@febyeji febyeji force-pushed the semantic-policy-display branch from b796520 to 73ee818 Compare April 2, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should remove Display impl for semantic::Policy

2 participants