Repository navigation
canonicalize tap leaf hashes by policy - #122
yuval-block wants to merge 1 commit into
Conversation
TapLeafHashes is now either a List, which keeps the hashes as they were given, or a Set, which is the canonical form. Values are still equal when they hold the same hashes. Converting from psbt_v2 takes a Canonicalization policy: Global::from_v2, Input::from_v2 and Output::try_from_v2 take Preserve, which keeps values as they were given, or Canonicalize, which puts them into canonical form. From and TryFrom use Preserve. joinable_struct! makes each struct Canonicalizable by canonicalizing every field that has a MirroredField conversion, using that conversion's new canonicalize method. Joining equal origins keeps the left one only if both are represented the same way, and canonicalizes it otherwise, so that the join no longer depends on the order of its operands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26f620c to
be3ad35
Compare
e4468ab to
5cf8f49
Compare
range-diff for force push 26f620c0f5 → be3ad35641
|
range-diff for force push 26f620c0f5 → be3ad35641
|
|
Opened mainly to keep a record, this spawned out of a refactor but I'm not sure there is much value to doing this so i'm going to close and we can reopen if anyone sees value in it. IdempotentValue semantics seems enough for TapLeafHashes even though it is implied to have set semantics by BIP 371. I don't expect any wallets would need to union these by having partial knowledge of the tap tree that each contributes. That seems like an entirely theoretical consideration. This field should also be scrubbed out so not much of a privacy argument to make about canonicalization. The only other field to which such a policy might apply is BIP 353 DNSSEC proofs, and I think the same argument applies to it as well. |
Follow-up to #116, which stores tap leaf hashes as
TapLeafHashesand joins equal values by keeping the left one (IdempotentValue). This PR lets callers choose whether to canonicalize on parse, and makes the join independent of operand order. Nothing in the UnorderedPsbt chain depends on it.TapLeafHashesbecomesList(Vec<TapLeafHash>), which keeps the hashes as given, orSet(BTreeSet<TapLeafHash>), the canonical form. Equality is still set equality.Canonicalizabletrait, and aCanonicalizationpolicy chosen by type:Preserve(the default) keeps values as given, andCanonicalizecanonicalizes them on conversion.Global::from_v2::<P>,Input::from_v2::<P>andOutput::try_from_v2::<P>take the policy, andFrom/TryFromusePreserve.joinable_struct!makes each structCanonicalizable, canonicalizing every field that has aMirroredFieldconversion through that conversion's newcanonicalizemethod. The code is written once for both policies.Base is
own-psbt-structs(#116). Retarget to main once #116 merges.🤖 Generated with Claude Code