Skip to content

proprietary fields for unordered PSBT spec - #110

Draft
yuval-block wants to merge 2 commits into
unordered-psbtfrom
concurrent-psbt-fields
Draft

yuval-block wants to merge 2 commits into
unordered-psbtfrom
concurrent-psbt-fields

Conversation

@yuval-block

Copy link
Copy Markdown
Collaborator

No description provided.

@github-code-quality

github-code-quality Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

unordered-psbt 5f4ab3b concurrent-psbt-fiel... 78f9665 +/-
100% 100% 0%
View coverage of the 10 most impacted files.
File unordered-psbt 5f4ab3b concurrent-psbt-fiel... 78f9665 +/-
crates/concurre.../src/psbt/tx.rs 0% 100% +100%
crates/concurre...bt/keyed_set.rs 0% 100% +100%
crates/concurre.../psbt/global.rs 0% 100% +100%
crates/concurre...bt/input_set.rs 0% 100% +100%
crates/concurre...t/output_set.rs 0% 100% +100%
crates/concurre...c/psbt/input.rs 0% 100% +100%
crates/concurre...bt/conflicts.rs 0% 100% +100%
crates/concurre...lattice/lift.rs 0% 100% +100%
crates/concurre.../proprietary.rs 0% 100% +100%
crates/concurre...ce/conflicts.rs 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 16, 2026 23:43 UTC

@github-actions

Copy link
Copy Markdown
range-diff for force push fc9b919e82 → 86a484d169 November 14, 2026 04:13 UTC: 1 modified; 1 commit; base 9fc81964d9 → 91f0f2bc9d (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 9fc8196..fc9b919 91f0f2b..86a484d

1:  fc9b919e82 +379 -0 4f ! 1:  86a484d169 +379 -0 4f proprietary fields for unordered PSBT spec
1: fc9b919e82 ! 1: 86a484d169 proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +
 +impl std::error::Error for InvalidSortSeed {}
 +
-+/// Subtype for `PSBT_GLOBAL_SORT_DETERMINISTIC`.
++/// Subtype for `PSBT_GLOBAL_SORT_KEY_DERIVATION`.
 +///
 +/// `0x01` = sort keys derived from seed (explicit keys MUST NOT be set).
 +/// `0x00` = explicit sort keys required.
-+pub const PSBT_GLOBAL_SORT_DETERMINISTIC_SUBTYPE: u8 = 0x12;
++pub const PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE: u8 = 0x12;
 +
 +fn proprietary_key(subtype: u8) -> raw::ProprietaryKey {
 +    raw::ProprietaryKey {
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +    fn sort_seed(&self) -> Option<&[u8]>;
 +    /// Set the sort seed.
 +    fn set_sort_seed(&mut self, seed: SortSeed);
-+    /// Get the `PSBT_GLOBAL_SORT_DETERMINISTIC` value, if set.
-+    fn sort_deterministic(&self) -> Option<u8>;
-+    /// Set `PSBT_GLOBAL_SORT_DETERMINISTIC`.
-+    fn set_sort_deterministic(&mut self, mode: u8);
++    /// Get the `PSBT_GLOBAL_SORT_KEY_DERIVATION` value, if set.
++    fn sort_key_derivation(&self) -> Option<u8>;
++    /// Set `PSBT_GLOBAL_SORT_KEY_DERIVATION`.
++    fn set_sort_key_derivation(&mut self, mode: u8);
 +    /// Set `PSBT_GLOBAL_TX_UNORDERED` to `0x03`.
 +    fn set_unordered(&mut self);
 +    /// Clear `PSBT_GLOBAL_TX_UNORDERED` (remove the field).
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +            .insert(proprietary_key(PSBT_GLOBAL_SORT_SEED_SUBTYPE), seed.0);
 +    }
 +
-+    fn sort_deterministic(&self) -> Option<u8> {
++    fn sort_key_derivation(&self) -> Option<u8> {
 +        self.proprietaries
-+            .get(&proprietary_key(PSBT_GLOBAL_SORT_DETERMINISTIC_SUBTYPE))
++            .get(&proprietary_key(PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE))
 +            .and_then(|v| v.first().copied())
 +    }
 +
-+    fn set_sort_deterministic(&mut self, mode: u8) {
++    fn set_sort_key_derivation(&mut self, mode: u8) {
 +        self.proprietaries.insert(
-+            proprietary_key(PSBT_GLOBAL_SORT_DETERMINISTIC_SUBTYPE),
++            proprietary_key(PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE),
 +            vec![mode],
 +        );
 +    }
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +            let mut global = Global::default();
 +            global.set_unordered();
 +            global.set_sort_seed(SortSeed::try_from(vec![0xaa; 16]).unwrap());
-+            global.set_sort_deterministic(0x01);
++            global.set_sort_key_derivation(0x01);
 +            assert_eq!(global.proprietaries.get(&key(0x10)), Some(&vec![0x03]));
 +            assert_eq!(global.proprietaries.get(&key(0x11)), Some(&vec![0xaa; 16]));
 +            assert_eq!(global.proprietaries.get(&key(0x12)), Some(&vec![0x01]));
 +            assert!(global.is_unordered());
 +            assert_eq!(global.sort_seed(), Some([0xaa; 16].as_slice()));
-+            assert_eq!(global.sort_deterministic(), Some(0x01));
++            assert_eq!(global.sort_key_derivation(), Some(0x01));
 +
 +            global.clear_unordered();
 +            assert!(!global.proprietaries.contains_key(&key(0x10)));
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +                prop_assert!(sort_seed.as_bytes().len() >= SortSeed::MIN_LEN);
 +                global.set_unordered();
 +                global.set_sort_seed(sort_seed);
-+                global.set_sort_deterministic(mode);
++                global.set_sort_key_derivation(mode);
 +
 +                prop_assert!(global.is_unordered());
 +                prop_assert_eq!(global.sort_seed(), Some(seed.as_slice()));
-+                prop_assert_eq!(global.sort_deterministic(), Some(mode));
++                prop_assert_eq!(global.sort_key_derivation(), Some(mode));
 +                global.clear_unordered();
 +                prop_assert!(!global.is_unordered());
 +            }

@github-actions

Copy link
Copy Markdown
range-diff for force push fc9b919e82 → 86a484d169 November 14, 2026 04:13 UTC: 1 modified; 1 commit; base 9fc81964d9 → 91f0f2bc9d (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 9fc8196..fc9b919 91f0f2b..86a484d

1:  fc9b919e82 +379 -0 4f ! 1:  86a484d169 +379 -0 4f proprietary fields for unordered PSBT spec
1: fc9b919e82 ! 1: 86a484d169 proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +
 +impl std::error::Error for InvalidSortSeed {}
 +
-+/// Subtype for `PSBT_GLOBAL_SORT_DETERMINISTIC`.
++/// Subtype for `PSBT_GLOBAL_SORT_KEY_DERIVATION`.
 +///
 +/// `0x01` = sort keys derived from seed (explicit keys MUST NOT be set).
 +/// `0x00` = explicit sort keys required.
-+pub const PSBT_GLOBAL_SORT_DETERMINISTIC_SUBTYPE: u8 = 0x12;
++pub const PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE: u8 = 0x12;
 +
 +fn proprietary_key(subtype: u8) -> raw::ProprietaryKey {
 +    raw::ProprietaryKey {
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +    fn sort_seed(&self) -> Option<&[u8]>;
 +    /// Set the sort seed.
 +    fn set_sort_seed(&mut self, seed: SortSeed);
-+    /// Get the `PSBT_GLOBAL_SORT_DETERMINISTIC` value, if set.
-+    fn sort_deterministic(&self) -> Option<u8>;
-+    /// Set `PSBT_GLOBAL_SORT_DETERMINISTIC`.
-+    fn set_sort_deterministic(&mut self, mode: u8);
++    /// Get the `PSBT_GLOBAL_SORT_KEY_DERIVATION` value, if set.
++    fn sort_key_derivation(&self) -> Option<u8>;
++    /// Set `PSBT_GLOBAL_SORT_KEY_DERIVATION`.
++    fn set_sort_key_derivation(&mut self, mode: u8);
 +    /// Set `PSBT_GLOBAL_TX_UNORDERED` to `0x03`.
 +    fn set_unordered(&mut self);
 +    /// Clear `PSBT_GLOBAL_TX_UNORDERED` (remove the field).
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +            .insert(proprietary_key(PSBT_GLOBAL_SORT_SEED_SUBTYPE), seed.0);
 +    }
 +
-+    fn sort_deterministic(&self) -> Option<u8> {
++    fn sort_key_derivation(&self) -> Option<u8> {
 +        self.proprietaries
-+            .get(&proprietary_key(PSBT_GLOBAL_SORT_DETERMINISTIC_SUBTYPE))
++            .get(&proprietary_key(PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE))
 +            .and_then(|v| v.first().copied())
 +    }
 +
-+    fn set_sort_deterministic(&mut self, mode: u8) {
++    fn set_sort_key_derivation(&mut self, mode: u8) {
 +        self.proprietaries.insert(
-+            proprietary_key(PSBT_GLOBAL_SORT_DETERMINISTIC_SUBTYPE),
++            proprietary_key(PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE),
 +            vec![mode],
 +        );
 +    }
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +            let mut global = Global::default();
 +            global.set_unordered();
 +            global.set_sort_seed(SortSeed::try_from(vec![0xaa; 16]).unwrap());
-+            global.set_sort_deterministic(0x01);
++            global.set_sort_key_derivation(0x01);
 +            assert_eq!(global.proprietaries.get(&key(0x10)), Some(&vec![0x03]));
 +            assert_eq!(global.proprietaries.get(&key(0x11)), Some(&vec![0xaa; 16]));
 +            assert_eq!(global.proprietaries.get(&key(0x12)), Some(&vec![0x01]));
 +            assert!(global.is_unordered());
 +            assert_eq!(global.sort_seed(), Some([0xaa; 16].as_slice()));
-+            assert_eq!(global.sort_deterministic(), Some(0x01));
++            assert_eq!(global.sort_key_derivation(), Some(0x01));
 +
 +            global.clear_unordered();
 +            assert!(!global.proprietaries.contains_key(&key(0x10)));
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +                prop_assert!(sort_seed.as_bytes().len() >= SortSeed::MIN_LEN);
 +                global.set_unordered();
 +                global.set_sort_seed(sort_seed);
-+                global.set_sort_deterministic(mode);
++                global.set_sort_key_derivation(mode);
 +
 +                prop_assert!(global.is_unordered());
 +                prop_assert_eq!(global.sort_seed(), Some(seed.as_slice()));
-+                prop_assert_eq!(global.sort_deterministic(), Some(mode));
++                prop_assert_eq!(global.sort_key_derivation(), Some(mode));
 +                global.clear_unordered();
 +                prop_assert!(!global.is_unordered());
 +            }

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch 2 times, most recently from 28d455e to 65a91c6 Compare November 14, 2026 07:01
@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 65a91c6 to ae99e06 Compare November 14, 2026 07:07
@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from ae99e06 to 1227d3a Compare November 14, 2026 08:10
@github-actions

Copy link
Copy Markdown
range-diff for force push ae99e06508 → 1227d3a5e5 November 14, 2026 09:05 UTC: 1 modified, 1 unchanged; 2 commits; base 4ae22747a4 → f1d969e92a (diverged, 6 ahead and 6 behind)

reproduce: git range-diff 4ae2274..ae99e06 f1d969e..1227d3a

1:  3ca133945d   +0  -0 0f = 1:  b2421ac052   +0  -0 0f define own Global, Input and Output structs
2:  ae99e06508 +781 -49 7f ! 2:  1227d3a5e5 +852 -74 8f proprietary fields for unordered PSBT spec
2: ae99e06508 ! 2: 1227d3a5e5 proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
  
              #[test]
 
+ ## crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs ##
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+             $(
+                 $(#[$proprietary_meta:meta])* $proprietary_vis:vis
+                 $proprietary:ident : $P:ty = $Codec:ty
+-            ),* $(,)?
++            ),+ $(,)?
+         } $(,)?
+     ) => {
+         joinable_struct! {
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+             result: $Result,
+             fields: {
+                 $( $(#[$field_meta])* $vis $field: $T, )+
+-                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )*
++                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )+
+             }
+         }
+ 
+         impl $Source {
+             /// The mirrored fields of `v2`, with these proprietary fields.
+-            fn from_v2_fields(v2: $V2, $( $proprietary: $P ),*) -> Self {
++            fn from_v2_fields(v2: $V2, $( $proprietary: $P ),+) -> Self {
+                 Self {
+                     $( $field: v2.$field, )+
+-                    $( $proprietary, )*
++                    $( $proprietary, )+
+                 }
+             }
+ 
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+             ///
+             /// # Errors
+             /// Returns the first proprietary field that does not decode.
+-            fn decode_v2<E>(v2: $V2) -> Result<Self, E>
++            fn decode_v2<E>(mut v2: $V2) -> Result<Self, E>
+             where
+-                $( E: From<<$Codec as $crate::psbt::proprietary::ProprietaryField>::Error>, )*
++                $( E: From<<$Codec as $crate::psbt::proprietary::ProprietaryField>::Error>, )+
+             {
+-                joinable_struct!(@decode v2 [ $( $proprietary $Codec ),* ])
++                $(
++                    let $proprietary =
++                        <$Codec as $crate::psbt::proprietary::ProprietaryField>::decode(
++                            v2.proprietaries.remove(&$crate::psbt::proprietary::key(
++                                <$Codec as $crate::psbt::proprietary::ProprietaryField>::SUBTYPE,
++                            )),
++                        )?;
++                )+
++                Ok(Self::from_v2_fields(v2, $( $proprietary ),+))
+             }
+ 
+             /// Move the mirrored fields into `base`, and encode the proprietary
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+                         )
+                         .map(|value| (key, value)),
+                     );
+-                )*
++                )+
+                 base
+             }
+         }
+     };
+ 
+-    (@decode $v2:ident []) => {
+-        Ok(Self::from_v2_fields($v2))
+-    };
+-
+-    (@decode $v2:ident [ $( $proprietary:ident $Codec:ty ),+ ]) => {{
+-        let mut $v2 = $v2;
+-        $(
+-            let $proprietary =
+-                <$Codec as $crate::psbt::proprietary::ProprietaryField>::decode(
+-                    $v2.proprietaries.remove(&$crate::psbt::proprietary::key(
+-                        <$Codec as $crate::psbt::proprietary::ProprietaryField>::SUBTYPE,
+-                    )),
+-                )?;
+-        )+
+-        Ok(Self::from_v2_fields($v2, $( $proprietary ),+))
+-    }};
+-
+     (
+         $(#[$source_meta:meta])*
+         source: $Source:ident,
+
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::{TapLeafHash, TapTree};
  use bitcoin::{Amount, ScriptBuf};
@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
          }
  
          #[test]
+@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
+                         UnorderedPsbtError::DuplicateOutputUniqueId(UniqueId::new(value.clone())),
+                         String::new(),
+                     ),
++                    (
++                        UnorderedPsbtError::InvalidUnorderedFlag(value.clone()),
++                        format!("{value:02x?}"),
++                    ),
++                    (
++                        UnorderedPsbtError::InvalidSortKeyDerivation(value.clone()),
++                        format!("{value:02x?}"),
++                    ),
++                    (UnorderedPsbtError::SortSeedTooShort(len), len.to_string()),
++                    (UnorderedPsbtError::InputSortKeyTooLong(outpoint), outpoint.to_string()),
++                    (UnorderedPsbtError::OutputSortKeyTooLong(index), index.to_string()),
+                 ];
+                 let messages: Vec<_> = errors.iter().map(|(error, _)| error.to_string()).collect();
+                 for ((_, payload), message) in errors.iter().zip(&messages) {
+@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
+                 prop_assert_eq!(UnorderedPsbt::try_from_psbt(psbt).map(|u| u.outputs.len()), expected);
+             }
+ 
++            #[test]
++            fn try_from_psbt_bounds_sort_field_sizes(
++                seed_len in proptest::option::of(0usize..=24),
++                input_key_len in proptest::option::of(0usize..=40),
++                output_key_len in proptest::option::of(0usize..=40),
++            ) {
++                let field = |subtype| psbt_v2::raw::ProprietaryKey {
++                    prefix: crate::PROPRIETARY_PREFIX.to_vec(),
++                    subtype,
++                    key: vec![],
++                };
++                let mut input = psbt_v2::v2::Input::new(&OutPoint::null());
++                let mut output = v2_output_with_uid(vec![1]);
++                if let Some(len) = input_key_len {
++                    input
++                        .proprietaries
++                        .insert(field(crate::input::PSBT_IN_SORT_KEY_SUBTYPE), vec![0; len]);
++                }
++                if let Some(len) = output_key_len {
++                    output
++                        .proprietaries
++                        .insert(field(crate::output::PSBT_OUT_SORT_KEY_SUBTYPE), vec![0; len]);
++                }
++                let mut psbt = v2_psbt(vec![input], vec![output]);
++                if let Some(len) = seed_len {
++                    psbt.global.proprietaries.insert(
++                        field(crate::global::PSBT_GLOBAL_SORT_SEED_SUBTYPE),
++                        vec![0; len],
++                    );
++                }
++                let long = |len: Option<usize>| len.is_some_and(|len| len > SortKey::MAX_LEN);
++                let expected = match seed_len {
++                    Some(len) if len < SortSeed::MIN_LEN => {
++                        Err(UnorderedPsbtError::SortSeedTooShort(len))
++                    }
++                    _ if long(input_key_len) => {
++                        Err(UnorderedPsbtError::InputSortKeyTooLong(OutPoint::null()))
++                    }
++                    _ if long(output_key_len) => Err(UnorderedPsbtError::OutputSortKeyTooLong(0)),
++                    _ => Ok(()),
++                };
++                prop_assert_eq!(ResultUnorderedPsbt::try_from_psbt(psbt).map(|_| ()), expected);
++            }
++
+             #[test]
+             fn is_ok_try_unwrap_consistent(r in arb_result_unordered_psbt()) {
+                 if r.is_ok() {
 
  ## crates/concurrent-psbt/src/values.rs ##
 @@ crates/concurrent-psbt/src/values.rs: impl<T: IdempotentValue> PartialJoin for T {

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 1227d3a to 08c8dd4 Compare November 14, 2026 10:46
@github-actions

Copy link
Copy Markdown
range-diff for force push 1227d3a5e5 → 08c8dd432a November 14, 2026 10:46 UTC: 1 modified, 1 unchanged; 2 commits; base f1d969e92a → 5188d15888 (diverged, 8 ahead and 7 behind)

reproduce: git range-diff f1d969e..1227d3a 5188d15..08c8dd4

1:  b2421ac052   +0  -0 0f = 1:  e3a9ad0329   +0  -0 0f define own Global, Input and Output structs
2:  1227d3a5e5 +852 -74 8f ! 2:  08c8dd432a +905 -98 8f proprietary fields for unordered PSBT spec
2: 1227d3a5e5 ! 2: 08c8dd432a proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
      }
  }
  
--/// Drops the version and the input and output counts, which converting back
--/// derives.
+-/// Drops the version and the input and output counts.
 -impl From<psbt_v2::v2::Global> for Global {
 -    fn from(global: psbt_v2::v2::Global) -> Self {
 -        let Ok(global) = Self::decode_v2::<std::convert::Infallible>(global);
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +impl std::error::Error for InvalidGlobal {}
 +
 +/// Reads the sort fields out of the proprietary fields, and drops the version
-+/// and the input and output counts, which converting back derives.
++/// and the input and output counts.
 +///
 +/// # Errors
 +/// Returns the first malformed sort field, in the order of
@@ crates/concurrent-psbt/src/psbt/global.rs: impl Global {
 +    }
 +}
 +
-+/// Sort fields, which converting to and from BIP 370 keeps in proprietary
-+/// fields under [`PROPRIETARY_PREFIX`](crate::PROPRIETARY_PREFIX).
++/// Accessors for the sort fields. A BIP 370 global map stores them as
++/// proprietary fields under [`PROPRIETARY_PREFIX`](crate::PROPRIETARY_PREFIX).
 +impl Global {
 +    /// Return `true` if `PSBT_GLOBAL_TX_UNORDERED` is set.
 +    pub fn is_unordered(&self) -> bool {
@@ crates/concurrent-psbt/src/psbt/global.rs: impl Global {
  #[cfg(test)]
  #[cfg_attr(coverage_nightly, coverage(off))]
  mod tests {
-@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+     use super::*;
+     use crate::lattice::join::Join;
+ 
++    /// A BIP 370 global map with these proprietary fields, given by subtype.
++    fn v2_with_fields(fields: &[(u8, Vec<u8>)]) -> psbt_v2::v2::Global {
++        let mut v2 = psbt_v2::v2::Global::default();
++        for (subtype, value) in fields {
++            v2.proprietaries
++                .insert(crate::psbt::proprietary::key(*subtype), value.clone());
++        }
++        v2
++    }
++
+     #[cfg(feature = "unit-tests")]
      mod unit {
          use super::*;
  
-+        #[test]
+         #[test]
+-        fn join_different_versions_conflicts() {
+-            let mut a = Global::default();
+-            let mut b = Global::default();
+-            a.tx_version = transaction::Version::ONE;
+-            b.tx_version = transaction::Version::TWO;
+-            let joined = a.wrap().join(b.wrap());
+-            assert!(!joined.is_ok());
+-            assert!(joined.try_unwrap().is_err());
 +        fn sort_fields_are_encoded_under_the_crate_prefix() {
 +            let key = |subtype| raw::ProprietaryKey {
 +                prefix: b"concurrent-psbt".to_vec(),
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +        }
 +
 +        #[test]
-+        fn sort_seed_is_at_least_16_bytes() {
-+            assert_eq!(
-+                SortSeed::try_from(vec![0; 16]).map(|seed| seed.as_bytes().to_vec()),
-+                Ok(vec![0; 16])
-+            );
-+            let error = SortSeed::try_from(vec![0; 15]).unwrap_err();
-+            assert_eq!(error, InvalidSortSeed(vec![0; 15]));
-+            assert_eq!(error.to_string(), "sort seed is 15 bytes, fewer than 16");
++        fn malformed_sort_fields_display_their_value() {
++            let cases = [
++                (
++                    InvalidGlobal::UnorderedFlag(vec![1]),
++                    "PSBT_GLOBAL_TX_UNORDERED is [01], not 0x03",
++                ),
++                (
++                    InvalidGlobal::SortKeyDerivation(vec![2]),
++                    "PSBT_GLOBAL_SORT_KEY_DERIVATION is [02], not 0x00 or 0x01",
++                ),
++                (
++                    InvalidGlobal::SortSeed(InvalidSortSeed(vec![0; 15])),
++                    "sort seed is 15 bytes, fewer than 16",
++                ),
++            ];
++            for (error, message) in cases {
++                assert_eq!(error.to_string(), message);
++            }
 +        }
 +
++        #[test]
++        fn the_first_malformed_sort_field_is_reported() {
++            let unordered = (PSBT_GLOBAL_TX_UNORDERED_SUBTYPE, vec![1]);
++            let derivation = (PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE, vec![2]);
++            let seed = (PSBT_GLOBAL_SORT_SEED_SUBTYPE, vec![0; 15]);
++            assert_eq!(
++                Global::try_from(v2_with_fields(&[
++                    unordered,
++                    derivation.clone(),
++                    seed.clone()
++                ])),
++                Err(InvalidGlobal::UnorderedFlag(vec![1]))
++            );
++            assert_eq!(
++                Global::try_from(v2_with_fields(&[derivation, seed])),
++                Err(InvalidGlobal::SortKeyDerivation(vec![2]))
++            );
+         }
+ 
          #[test]
-         fn join_different_versions_conflicts() {
-             let mut a = Global::default();
+@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+         }
+ 
+         #[test]
+-        fn for_each_conflict_reports_the_conflicted_field() {
+-            let mut a = Global::default();
+-            let mut b = Global::default();
+-            a.tx_version = transaction::Version::ONE;
+-            b.tx_version = transaction::Version::TWO;
++        fn globals_with_different_tx_versions_conflict() {
++            let with_version = |tx_version| Global {
++                tx_version,
++                ..Global::default()
++            };
++            let joined = with_version(transaction::Version::ONE)
++                .wrap()
++                .join(with_version(transaction::Version::TWO).wrap());
+             let mut fields = Vec::new();
+-            a.wrap()
+-                .join(b.wrap())
+-                .for_each_conflict(|field, _, _| fields.push(field.to_owned()));
++            joined.for_each_conflict(|field, _, _| fields.push(field.to_owned()));
+             assert_eq!(fields, ["tx_version"]);
++            assert_eq!(joined.clone().try_unwrap(), Err(joined));
+         }
+     }
+ 
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
                  proptest::bool::ANY,
                  0u8..4,
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
          }
  
          fn arb_result_global() -> impl Strategy<Value = ResultGlobal> {
+@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+         proptest! {
+             #[test]
+             fn wrap_try_unwrap_roundtrip(a in arb_global()) {
+-                let wrapped = a.wrap();
+-                let unwrapped = wrapped.clone().try_unwrap().expect("freshly wrapped");
+-                prop_assert_eq!(unwrapped.wrap(), wrapped);
++                prop_assert_eq!(a.clone().wrap().try_unwrap(), Ok(a));
+             }
+ 
+             #[test]
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
                  let v2 = a.clone().into_v2(input_count, output_count);
                  prop_assert_eq!(v2.version, psbt_v2::Version::TWO);
                  prop_assert_eq!((v2.input_count, v2.output_count), (input_count, output_count));
 -                prop_assert_eq!(Global::from(v2), a);
 +                prop_assert_eq!(Global::try_from(v2), Ok(a));
-+            }
-+
-+            #[test]
+             }
+ 
+             #[test]
+-            fn is_ok_consistency(a in arb_result_global()) {
+-                if a.is_ok() {
+-                    prop_assert!(a.try_unwrap().is_ok());
+-                } else {
+-                    prop_assert!(a.try_unwrap().is_err());
 +            fn sort_fields_own_their_keys(
 +                a in arb_global(),
 +                raw in proptest::collection::vec(any::<u8>(), 0..=17),
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +                        .insert(crate::psbt::proprietary::key(subtype), raw.clone());
 +                }
 +                prop_assert_eq!(Global::try_from(shadowed.into_v2(0, 0)), Ok(a));
-             }
- 
-             #[test]
-@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
-                     prop_assert!(a.try_unwrap().is_err());
-                 }
-             }
++            }
 +
 +            #[test]
-+            fn try_from_reads_sort_fields(
-+                unordered in proptest::option::of(prop_oneof![
-+                    Just(vec![0x03]),
-+                    proptest::collection::vec(any::<u8>(), 0..=2),
-+                ]),
-+                derivation in proptest::option::of(proptest::collection::vec(0u8..=2, 0..=2)),
-+                seed in proptest::option::of(proptest::collection::vec(any::<u8>(), 14..=18)),
++            fn is_ok_iff_try_unwrap_succeeds(a in arb_result_global()) {
++                prop_assert_eq!(a.is_ok(), a.try_unwrap().is_ok());
++            }
++
++            #[test]
++            fn unordered_flag_is_0x03(
++                value in prop_oneof![Just(vec![0x03]), proptest::collection::vec(any::<u8>(), 0..=2)],
 +            ) {
-+                let mut v2 = psbt_v2::v2::Global::default();
-+                for (subtype, value) in [(0x10, &unordered), (0x12, &derivation), (0x11, &seed)] {
-+                    if let Some(value) = value {
-+                        v2.proprietaries.insert(crate::psbt::proprietary::key(subtype), value.clone());
++                let v2 = v2_with_fields(&[(PSBT_GLOBAL_TX_UNORDERED_SUBTYPE, value.clone())]);
++                match Global::try_from(v2) {
++                    Ok(global) => {
++                        prop_assert_eq!(value, [0x03]);
++                        prop_assert!(global.is_unordered());
 +                    }
-+                }
-+                let expected = match (&unordered, &derivation, &seed) {
-+                    (Some(value), _, _) if value != &[0x03] => {
-+                        Err(InvalidGlobal::UnorderedFlag(value.clone()))
-+                    }
-+                    (_, Some(value), _) if value != &[0x00] && value != &[0x01] => {
-+                        Err(InvalidGlobal::SortKeyDerivation(value.clone()))
++                    Err(error) => {
++                        let bytes = format!("{value:02x?}");
++                        prop_assert!(error.to_string().contains(&bytes));
++                        prop_assert_eq!(error, InvalidGlobal::UnorderedFlag(value));
 +                    }
-+                    (_, _, Some(seed)) if seed.len() < SortSeed::MIN_LEN => {
-+                        Err(InvalidGlobal::SortSeed(InvalidSortSeed(seed.clone())))
++                }
++            }
++
++            #[test]
++            fn sort_key_derivation_is_0x00_or_0x01(
++                value in proptest::collection::vec(0u8..=2, 0..=2),
++            ) {
++                let v2 = v2_with_fields(&[(PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE, value.clone())]);
++                let derivation = match value.as_slice() {
++                    [0x00] => SortKeyDerivation::Explicit,
++                    [0x01] => SortKeyDerivation::Derived,
++                    _ => {
++                        let error = Global::try_from(v2).unwrap_err();
++                        let bytes = format!("{value:02x?}");
++                        prop_assert!(error.to_string().contains(&bytes));
++                        prop_assert_eq!(error, InvalidGlobal::SortKeyDerivation(value));
++                        return Ok(());
 +                    }
-+                    _ => Ok(()),
 +                };
-+                match (Global::try_from(v2.clone()), expected) {
-+                    (Ok(global), Ok(())) => {
-+                        prop_assert_eq!(global.is_unordered(), unordered.is_some());
-+                        prop_assert_eq!(
-+                            global.sort_key_derivation().map(SortKeyDerivation::to_byte),
-+                            derivation.map(|value| value[0])
-+                        );
-+                        prop_assert_eq!(global.sort_seed(), seed.as_deref());
-+                        prop_assert_eq!(global.into_v2(0, 0), v2);
-+                    }
-+                    (Err(error), Err(expected)) => {
-+                        let field = match &expected {
-+                            InvalidGlobal::UnorderedFlag(_) => "PSBT_GLOBAL_TX_UNORDERED is",
-+                            InvalidGlobal::SortKeyDerivation(_) => "PSBT_GLOBAL_SORT_KEY_DERIVATION is",
-+                            InvalidGlobal::SortSeed(_) => "sort seed is",
-+                        };
-+                        prop_assert!(error.to_string().starts_with(field));
-+                        prop_assert_eq!(error, expected);
++                prop_assert_eq!(Global::try_from(v2).map(|g| g.sort_key_derivation()), Ok(Some(derivation)));
++            }
++
++            #[test]
++            fn sort_seed_is_at_least_16_bytes(seed in proptest::collection::vec(any::<u8>(), 0..=24)) {
++                let v2 = v2_with_fields(&[(PSBT_GLOBAL_SORT_SEED_SUBTYPE, seed.clone())]);
++                match Global::try_from(v2) {
++                    Ok(global) => {
++                        prop_assert!(seed.len() >= SortSeed::MIN_LEN);
++                        prop_assert_eq!(global.sort_seed(), Some(seed.as_slice()));
 +                    }
-+                    (actual, expected) => {
-+                        prop_assert!(false, "read {:?}, expected {:?}", actual, expected);
++                    Err(error) => {
++                        let length = format!("{} bytes", seed.len());
++                        prop_assert!(error.to_string().contains(&length));
++                        prop_assert_eq!(error, InvalidGlobal::SortSeed(InvalidSortSeed(seed)));
 +                    }
-+                }
-+            }
+                 }
+             }
          }
-     }
- }
 
  ## crates/concurrent-psbt/src/psbt/input.rs ##
-@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::{OutPoint, ScriptBuf, Sequence, Transaction, TxOut, Txid, Witness,
- use psbt_v2::PsbtSighashType;
- use psbt_v2::raw;
+@@ crates/concurrent-psbt/src/psbt/input.rs: use psbt_v2::raw;
+ 
+ use super::tap_leaf_hashes::{TapKeyOrigins, TapLeafHashes};
  
 +use super::proprietary::ProprietaryField;
 +
@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input)
  #[cfg_attr(coverage_nightly, coverage(off))]
  pub(crate) mod tests {
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
-     pub(crate) mod unit {
-         use super::*;
-         use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
-+
+             assert_eq!(joined.clone().try_unwrap(), Err(joined));
+         }
+ 
 +        #[test]
 +        fn sort_key_is_encoded_under_the_crate_prefix() {
 +            let key = psbt_v2::raw::ProprietaryKey {
@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
 +            assert_eq!(error.to_string(), "sort key is 33 bytes, more than 32");
 +        }
 +
-         use bitcoin::hashes::Hash;
-         use bitcoin::secp256k1::{Secp256k1, SecretKey};
- 
-@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
-             "tap_merkle_root",
-             "proprietaries",
-             "unknowns",
-+            "sort_key",
-         ];
- 
-         fn empty_conflict<T: PartialJoin>() -> JoinResult<T> {
-@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
-             result.tap_key_sig = Some(empty_conflict());
-             result.tap_internal_key = Some(empty_conflict());
-             result.tap_merkle_root = Some(empty_conflict());
-+            result.sort_key = Some(empty_conflict());
- 
-             let secret_key = SecretKey::from_slice(&[seed; 32]).expect("bounded nonzero seed");
-             let secp_public_key =
+         #[test]
+         fn v2_conversion_round_trips_a_populated_input() {
+             let mut input = make_input(1, 2);
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
                  (v2.previous_txid, v2.spent_output_index, v2.sequence),
                  (input.previous_txid, 2, Some(Sequence(3)))
@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
 +                    .insert(crate::psbt::proprietary::key(PSBT_IN_SORT_KEY_SUBTYPE), key.clone());
 +                let Ok(input) = Input::try_from(v2.clone()) else {
 +                    prop_assert!(key.len() > SortKey::MAX_LEN);
-+                    let error = InvalidSortKey(key.clone());
-+                    prop_assert!(error.to_string().contains("more than 32"));
-+                    prop_assert_eq!(Input::try_from(v2), Err(error));
++                    prop_assert_eq!(Input::try_from(v2), Err(InvalidSortKey(key)));
 +                    return Ok(());
 +                };
 +                prop_assert_eq!(input.sort_key(), Some(key.as_slice()));
 +                prop_assert_eq!(psbt_v2::v2::Input::from(input), v2);
 +            }
 +
-             // ── 1. wrap → try_unwrap roundtrip ──────────────────────────
              #[test]
-             fn wrap_try_unwrap_roundtrip_input(a in arb_input_with_fields()) {
+             fn wrap_try_unwrap_roundtrip(i in arb_input_with_fields()) {
+                 prop_assert_eq!(i.clone().wrap().try_unwrap(), Ok(i));
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
  
              #[test]
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 -            fn from_v2_fields(v2: $V2, $( $proprietary: $P ),*) -> Self {
 +            fn from_v2_fields(v2: $V2, $( $proprietary: $P ),+) -> Self {
                  Self {
-                     $( $field: v2.$field, )+
+                     $( $field: joinable_struct!(@from_v2 v2.$field $(, $Conversion)?), )+
 -                    $( $proprietary, )*
 +                    $( $proprietary, )+
                  }
              }
  
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             ///
              /// # Errors
-             /// Returns the first proprietary field that does not decode.
+             /// Returns the error of the first proprietary field that does not
+             /// decode.
 -            fn decode_v2<E>(v2: $V2) -> Result<Self, E>
 +            fn decode_v2<E>(mut v2: $V2) -> Result<Self, E>
              where
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
                  base
              }
          }
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+         <$Conversion as $crate::psbt::joinable_struct_macro::MirroredField>::into_v2($value)
      };
  
 -    (@decode $v2:ident []) => {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
          source: $Source:ident,
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
-@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::{TapLeafHash, TapTree};
+@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::TapTree;
  use bitcoin::{Amount, ScriptBuf};
  use psbt_v2::raw;
  
 +use super::input::{InvalidSortKey, SortKey, SortKeyField};
  use super::proprietary::ProprietaryField;
+ use super::tap_leaf_hashes::{TapKeyOrigins, TapLeafHashes};
  
- joinable_struct! {
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
      },
      proprietary: {
@@ crates/concurrent-psbt/src/psbt/output.rs: impl OutputUniqueIdExt for psbt_v2::v
  
  #[cfg(test)]
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-     mod unit {
-         use super::*;
-         use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
+             assert_eq!(fields, ["amount"]);
+             assert_eq!(joined.clone().try_unwrap(), Err(joined));
+         }
 +
 +        #[test]
 +        fn sort_key_is_encoded_under_the_crate_prefix() {
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +            assert_eq!(output.sort_key(), None);
 +            output.set_sort_key(SortKey::try_from(vec![0x42]).unwrap());
 +            assert_eq!(output.sort_key(), Some([0x42].as_slice()));
-+            let v2 = psbt_v2::v2::Output::from(output.clone());
++            let mut v2 = psbt_v2::v2::Output::from(output.clone());
 +            assert_eq!(v2.proprietaries.get(&key), Some(&vec![0x42]));
-+            assert_eq!(Output::try_from(v2), Ok(output));
++            assert_eq!(Output::try_from(v2.clone()), Ok(output));
++
++            v2.proprietaries.insert(key, vec![0; 33]);
++            let error = Output::try_from(v2).unwrap_err();
++            assert_eq!(
++                error.to_string(),
++                "output sort key is 33 bytes, more than 32"
++            );
 +        }
-         use bitcoin::secp256k1::{Secp256k1, SecretKey};
- 
-         const ALL_CONFLICT_FIELDS: &[&str] = &[
-@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-             "proprietaries",
-             "unknowns",
-             "unique_id",
-+            "sort_key",
-         ];
- 
-         fn empty_conflict<T: PartialJoin>() -> JoinResult<T> {
-@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-             result.witness_script = Some(empty_conflict());
-             result.tap_internal_key = Some(empty_conflict());
-             result.tap_tree = Some(empty_conflict());
-+            result.sort_key = Some(empty_conflict());
+     }
  
-             let secret_key = SecretKey::from_slice(&[seed; 32]).expect("bounded nonzero seed");
-             let secp_public_key =
+     #[cfg(feature = "prop-tests")]
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                  any::<u64>(),
                  proptest::option::of(proptest::collection::vec(0u8..255, 0..=8)),
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                  })
          }
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-                 }
+                 prop_assert_eq!(r.is_ok(), r.try_unwrap().is_ok());
              }
  
 +            #[test]
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +                    }
 +                    Err(error) => {
 +                        prop_assert!(key.len() > SortKey::MAX_LEN);
-+                        prop_assert!(error.to_string().starts_with("output sort key is"));
 +                        prop_assert_eq!(error, InvalidOutput::SortKeyTooLong(InvalidSortKey(key)));
 +                    }
 +                }
@@ crates/concurrent-psbt/src/psbt/proprietary.rs
          key: vec![],
      }
 @@ crates/concurrent-psbt/src/psbt/proprietary.rs: pub(crate) fn key(subtype: u8) -> raw::ProprietaryKey {
- /// The key and encoding belong to the codec rather than the field, so a field
- /// keeps its type and join when its key changes.
+ /// A field's key and encoding are defined by its codec, so changing them does
+ /// not change the field's type or join.
  pub(crate) trait ProprietaryField {
 -    /// The subtype of the field's key under [`PREFIX`].
 +    /// The subtype of the field's key under [`PROPRIETARY_PREFIX`].
@@ crates/concurrent-psbt/src/psbt/tx.rs: impl UnorderedPsbt {
      /// Returns a count mismatch if the declared input or output count is not
      /// the number of inputs or outputs, which only a `Psbt` assembled by hand
 -    /// can have. Otherwise returns the first input whose outpoint repeats,
--    /// then the first output that is missing a `PSBT_OUT_UNIQUE_ID` field, has
--    /// one longer than [`UniqueId::MAX_LEN`] bytes, or repeats one.
+-    /// then the first output whose `PSBT_OUT_UNIQUE_ID` is missing, empty or
+-    /// longer than [`UniqueId::MAX_LEN`] bytes, then the first unique ID that
+-    /// repeats.
 +    /// can have. Otherwise returns a malformed global sort field, then the
-+    /// first input with a sort key longer than [`SortKey::MAX_LEN`] bytes,
-+    /// then the first input whose outpoint repeats, then the first output that
-+    /// is missing a `PSBT_OUT_UNIQUE_ID` field, has one longer than
-+    /// [`UniqueId::MAX_LEN`] bytes or a sort key longer than
-+    /// [`SortKey::MAX_LEN`] bytes, or repeats a unique ID.
++    /// first input whose sort key is longer than [`SortKey::MAX_LEN`] bytes,
++    /// then the first input whose outpoint repeats, then the first output
++    /// whose `PSBT_OUT_UNIQUE_ID` is missing, empty or longer than
++    /// [`UniqueId::MAX_LEN`] bytes, or whose sort key is longer than
++    /// [`SortKey::MAX_LEN`] bytes, then the first unique ID that repeats.
      pub fn try_from_psbt(psbt: Psbt) -> Result<Self, UnorderedPsbtError> {
          let Psbt {
              global,
 @@ crates/concurrent-psbt/src/psbt/tx.rs: impl UnorderedPsbt {
+             });
+         }
  
-         // A set that is not modifiable is frozen, so it joins only with an
-         // identical set.
 -        let global = Global::from(global);
 -        let inputs = InputSet::try_from_inputs(inputs.into_iter().map(Input::from))?;
 +        let global = Global::try_from(global)?;
@@ crates/concurrent-psbt/src/psbt/tx.rs: impl UnorderedPsbt {
              inputs.freeze()
          } else {
 @@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
-                 duplicate_output.to_string(),
-                 "two outputs share a PSBT_OUT_UNIQUE_ID"
-             );
-+
-+            for (error, message) in [
+                     UnorderedPsbtError::DuplicateOutputUniqueId(UniqueId::new(vec![1])),
+                     "two outputs share a PSBT_OUT_UNIQUE_ID".to_string(),
+                 ),
 +                (
 +                    UnorderedPsbtError::InvalidUnorderedFlag(vec![1]),
-+                    "PSBT_GLOBAL_TX_UNORDERED is [01], not 0x03".to_owned(),
++                    "PSBT_GLOBAL_TX_UNORDERED is [01], not 0x03".to_string(),
 +                ),
 +                (
 +                    UnorderedPsbtError::InvalidSortKeyDerivation(vec![2]),
-+                    "PSBT_GLOBAL_SORT_KEY_DERIVATION is [02], not 0x00 or 0x01".to_owned(),
++                    "PSBT_GLOBAL_SORT_KEY_DERIVATION is [02], not 0x00 or 0x01".to_string(),
 +                ),
 +                (
 +                    UnorderedPsbtError::SortSeedTooShort(15),
-+                    "PSBT_GLOBAL_SORT_SEED is 15 bytes, fewer than 16".to_owned(),
++                    "PSBT_GLOBAL_SORT_SEED is 15 bytes, fewer than 16".to_string(),
 +                ),
 +                (
-+                    UnorderedPsbtError::InputSortKeyTooLong(OutPoint::null()),
++                    UnorderedPsbtError::InputSortKeyTooLong(outpoint(1)),
 +                    format!(
 +                        "sort key of the input spending {} is longer than 32 bytes",
-+                        OutPoint::null()
++                        outpoint(1)
 +                    ),
 +                ),
 +                (
 +                    UnorderedPsbtError::OutputSortKeyTooLong(1),
-+                    "sort key of output 1 is longer than 32 bytes".to_owned(),
++                    "sort key of output 1 is longer than 32 bytes".to_string(),
 +                ),
-+            ] {
-+                assert_eq!(error.to_string(), message);
-+            }
-+        }
-+
-+        #[test]
-+        fn try_from_psbt_rejects_malformed_sort_fields() {
+             ];
+             for (error, message) in cases {
+                 assert_eq!(error.to_string(), message);
+@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
+                 output.amount = Amount::from_sat(sat);
+                 output
+             };
 +            let field = |subtype| psbt_v2::raw::ProprietaryKey {
 +                prefix: crate::PROPRIETARY_PREFIX.to_vec(),
 +                subtype,
@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
 +                psbt.global.proprietaries.insert(field(subtype), value);
 +                psbt
 +            };
-+            let mut long_input_key = psbt_v2::v2::Input::new(&OutPoint::null());
++            let mut long_input_key = psbt_v2::v2::Input::new(&outpoint(1));
 +            long_input_key
 +                .proprietaries
 +                .insert(field(crate::input::PSBT_IN_SORT_KEY_SUBTYPE), vec![0; 33]);
@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
 +            long_output_key
 +                .proprietaries
 +                .insert(field(crate::output::PSBT_OUT_SORT_KEY_SUBTYPE), vec![0; 33]);
-+
-+            for (psbt, expected) in [
+             let cases = [
 +                (
 +                    with_global_field(crate::global::PSBT_GLOBAL_TX_UNORDERED_SUBTYPE, vec![1]),
 +                    UnorderedPsbtError::InvalidUnorderedFlag(vec![1]),
@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
 +                ),
 +                (
 +                    v2_psbt(vec![long_input_key], vec![]),
-+                    UnorderedPsbtError::InputSortKeyTooLong(OutPoint::null()),
++                    UnorderedPsbtError::InputSortKeyTooLong(outpoint(1)),
 +                ),
+                 (
+                     v2_psbt(vec![input_with_sequence(1), input_with_sequence(2)], vec![]),
+                     UnorderedPsbtError::DuplicateInput(outpoint(1)),
+@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
+                     v2_psbt(vec![], vec![v2_output_with_uid(vec![1; 33])]),
+                     UnorderedPsbtError::InvalidOutputUniqueId(0),
+                 ),
 +                (
 +                    v2_psbt(vec![], vec![v2_output_with_uid(vec![1]), long_output_key]),
 +                    UnorderedPsbtError::OutputSortKeyTooLong(1),
 +                ),
-+            ] {
-+                assert_eq!(UnorderedPsbt::try_from_psbt(psbt), Err(expected));
-+            }
-         }
- 
-         #[test]
+                 (
+                     v2_psbt(
+                         vec![],
 @@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
-                         UnorderedPsbtError::DuplicateOutputUniqueId(UniqueId::new(value.clone())),
-                         String::new(),
-                     ),
+                 prop_assert_eq!(joined.is_ok(), inputs_agree && outputs_agree);
+             }
+ 
++            #[test]
++            fn error_messages_are_distinct_and_name_the_offending_value(
++                index in any::<usize>(),
++                len in any::<usize>(),
++                value in proptest::collection::vec(any::<u8>(), 0..4),
++                vout in any::<u32>(),
++            ) {
++                let outpoint = OutPoint { vout, ..OutPoint::null() };
++                let bytes = format!("{value:02x?}");
++                let errors = [
 +                    (
-+                        UnorderedPsbtError::InvalidUnorderedFlag(value.clone()),
-+                        format!("{value:02x?}"),
++                        UnorderedPsbtError::InputCountMismatch { declared: len, found: index },
++                        Some(format!("{len} inputs but has {index}")),
 +                    ),
 +                    (
-+                        UnorderedPsbtError::InvalidSortKeyDerivation(value.clone()),
-+                        format!("{value:02x?}"),
++                        UnorderedPsbtError::OutputCountMismatch { declared: len, found: index },
++                        Some(format!("{len} outputs but has {index}")),
 +                    ),
-+                    (UnorderedPsbtError::SortSeedTooShort(len), len.to_string()),
-+                    (UnorderedPsbtError::InputSortKeyTooLong(outpoint), outpoint.to_string()),
-+                    (UnorderedPsbtError::OutputSortKeyTooLong(index), index.to_string()),
-                 ];
-                 let messages: Vec<_> = errors.iter().map(|(error, _)| error.to_string()).collect();
-                 for ((_, payload), message) in errors.iter().zip(&messages) {
-@@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {
-                 prop_assert_eq!(UnorderedPsbt::try_from_psbt(psbt).map(|u| u.outputs.len()), expected);
-             }
- 
++                    (UnorderedPsbtError::InvalidUnorderedFlag(value.clone()), Some(bytes.clone())),
++                    (UnorderedPsbtError::InvalidSortKeyDerivation(value.clone()), Some(bytes)),
++                    (UnorderedPsbtError::SortSeedTooShort(len), Some(len.to_string())),
++                    (UnorderedPsbtError::InputSortKeyTooLong(outpoint), Some(outpoint.to_string())),
++                    (UnorderedPsbtError::MissingOutputUniqueId(index), Some(index.to_string())),
++                    (UnorderedPsbtError::InvalidOutputUniqueId(index), Some(index.to_string())),
++                    (UnorderedPsbtError::OutputSortKeyTooLong(index), Some(index.to_string())),
++                    (UnorderedPsbtError::DuplicateInput(outpoint), Some(outpoint.to_string())),
++                    // The unique ID is opaque bytes, so the message leaves it out.
++                    (UnorderedPsbtError::DuplicateOutputUniqueId(UniqueId::new(value)), None),
++                ];
++                let messages: Vec<_> = errors.iter().map(|(error, _)| error.to_string()).collect();
++                for ((_, payload), message) in errors.iter().zip(&messages) {
++                    if let Some(payload) = payload {
++                        prop_assert!(message.contains(payload.as_str()), "{message:?} lacks {payload:?}");
++                    }
++                }
++                let distinct: std::collections::HashSet<_> = messages.iter().collect();
++                prop_assert_eq!(distinct.len(), messages.len());
++            }
++
 +            #[test]
-+            fn try_from_psbt_bounds_sort_field_sizes(
-+                seed_len in proptest::option::of(0usize..=24),
-+                input_key_len in proptest::option::of(0usize..=40),
-+                output_key_len in proptest::option::of(0usize..=40),
++            fn malformed_sort_fields_reject_the_psbt(
++                a in arb_unordered_psbt(),
++                key_len in (SortKey::MAX_LEN + 1)..=40,
++                seed_len in 0..SortSeed::MIN_LEN,
 +            ) {
 +                let field = |subtype| psbt_v2::raw::ProprietaryKey {
 +                    prefix: crate::PROPRIETARY_PREFIX.to_vec(),
 +                    subtype,
 +                    key: vec![],
 +                };
-+                let mut input = psbt_v2::v2::Input::new(&OutPoint::null());
-+                let mut output = v2_output_with_uid(vec![1]);
-+                if let Some(len) = input_key_len {
++                let mut psbt = a.into_psbt();
++                if let Some(input) = psbt.inputs.first_mut() {
 +                    input
 +                        .proprietaries
-+                        .insert(field(crate::input::PSBT_IN_SORT_KEY_SUBTYPE), vec![0; len]);
-+                }
-+                if let Some(len) = output_key_len {
-+                    output
-+                        .proprietaries
-+                        .insert(field(crate::output::PSBT_OUT_SORT_KEY_SUBTYPE), vec![0; len]);
-+                }
-+                let mut psbt = v2_psbt(vec![input], vec![output]);
-+                if let Some(len) = seed_len {
-+                    psbt.global.proprietaries.insert(
-+                        field(crate::global::PSBT_GLOBAL_SORT_SEED_SUBTYPE),
-+                        vec![0; len],
++                        .insert(field(crate::input::PSBT_IN_SORT_KEY_SUBTYPE), vec![0; key_len]);
++                    let outpoint = OutPoint {
++                        txid: input.previous_txid,
++                        vout: input.spent_output_index,
++                    };
++                    prop_assert_eq!(
++                        UnorderedPsbt::try_from_psbt(psbt.clone()),
++                        Err(UnorderedPsbtError::InputSortKeyTooLong(outpoint))
 +                    );
 +                }
-+                let long = |len: Option<usize>| len.is_some_and(|len| len > SortKey::MAX_LEN);
-+                let expected = match seed_len {
-+                    Some(len) if len < SortSeed::MIN_LEN => {
-+                        Err(UnorderedPsbtError::SortSeedTooShort(len))
-+                    }
-+                    _ if long(input_key_len) => {
-+                        Err(UnorderedPsbtError::InputSortKeyTooLong(OutPoint::null()))
-+                    }
-+                    _ if long(output_key_len) => Err(UnorderedPsbtError::OutputSortKeyTooLong(0)),
-+                    _ => Ok(()),
-+                };
-+                prop_assert_eq!(ResultUnorderedPsbt::try_from_psbt(psbt).map(|_| ()), expected);
++                // A malformed global field is reported before any input.
++                psbt.global
++                    .proprietaries
++                    .insert(field(crate::global::PSBT_GLOBAL_SORT_SEED_SUBTYPE), vec![0; seed_len]);
++                prop_assert_eq!(
++                    UnorderedPsbt::try_from_psbt(psbt),
++                    Err(UnorderedPsbtError::SortSeedTooShort(seed_len))
++                );
 +            }
 +
              #[test]
-             fn is_ok_try_unwrap_consistent(r in arb_result_unordered_psbt()) {
-                 if r.is_ok() {
+             fn try_from_psbt_rejects_the_first_invalid_unique_id(
+                 uid_lens in proptest::collection::vec(proptest::option::of(0usize..=34), 0..=4),
 
  ## crates/concurrent-psbt/src/values.rs ##
 @@ crates/concurrent-psbt/src/values.rs: impl<T: IdempotentValue> PartialJoin for T {

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 08c8dd4 to 1d68eb5 Compare November 14, 2026 12:21
@github-actions

Copy link
Copy Markdown
range-diff for force push 08c8dd432a → 1d68eb5c8c November 14, 2026 12:21 UTC: 2 unchanged; 2 commits; base 5188d15888 → 8951ddc9c0 (diverged, 6 ahead and 6 behind)

reproduce: git range-diff 5188d15..08c8dd4 8951ddc..1d68eb5

1:  e3a9ad0329   +0  -0 0f = 1:  0013a1b278   +0  -0 0f define own Global, Input and Output structs
2:  08c8dd432a +905 -98 8f = 2:  1d68eb5c8c +905 -98 8f proprietary fields for unordered PSBT spec

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 1d68eb5 to 6266702 Compare November 14, 2026 13:22
@github-actions

Copy link
Copy Markdown
range-diff for force push 1d68eb5c8c → 62667029b5 November 14, 2026 13:26 UTC: 2 unchanged; 2 commits; base 8951ddc9c0 → f3408597e4 (diverged, 7 ahead and 7 behind)

reproduce: git range-diff 8951ddc..1d68eb5 f340859..6266702

1:  0013a1b278   +0  -0 0f = 1:  d4d989e700   +0  -0 0f define own Global, Input and Output structs
2:  1d68eb5c8c +905 -98 8f = 2:  62667029b5 +905 -98 8f proprietary fields for unordered PSBT spec

@github-actions

Copy link
Copy Markdown
range-diff for force push 1d68eb5c8c → 62667029b5 November 14, 2026 13:41 UTC: 2 unchanged; 2 commits; base 8951ddc9c0 → f3408597e4 (diverged, 7 ahead and 7 behind)

reproduce: git range-diff 8951ddc..1d68eb5 f340859..6266702

1:  0013a1b278   +0  -0 0f = 1:  d4d989e700   +0  -0 0f define own Global, Input and Output structs
2:  1d68eb5c8c +905 -98 8f = 2:  62667029b5 +905 -98 8f proprietary fields for unordered PSBT spec

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortKeyDerivation {
/// `0x00`: every input and output needs an explicit sort key, and there is
/// no sort seed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit sort mode accepts and serializes a supplied seed

SortKeyDerivation::Explicit (0x00) documents that there is no sort seed, but Global::set_sort_seed/set_sort_key_derivation and Global::try_from accept a seed alongside it, and UnorderedPsbt::into_psbt serializes both.

oakagent · automated · 6266702

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 6266702 to d7bcb09 Compare November 14, 2026 19:00
@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 65c2579 to 80ea45d Compare November 14, 2026 23:45
@github-actions

Copy link
Copy Markdown
range-diff for force push 65c25793a5 → 80ea45da32 November 14, 2026 23:45 UTC: 1 modified, 1 unchanged; 2 commits; base ac405b3333 → a3a74d8ae5 (diverged, 5 ahead and 4 behind)

reproduce: git range-diff ac405b3..65c2579 a3a74d8..80ea45d

1:  ccc15638f5   +0  -0 0f = 1:  1faa38fcf4   +0  -0 0f define own Global, Input and Output structs
2:  65c25793a5 +907 -95 8f ! 2:  80ea45da32 +907 -95 8f proprietary fields for unordered PSBT spec
2: 65c25793a5 ! 2: 80ea45da32 proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
              result: $Result,
              fields: {
-                 $( $(#[$field_meta])* $vis $field: $T, )+
+                 $( $(#[$field_meta])* $field: $T, )+
 -                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )*
 +                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )+
              }
          }
  
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+ 
          impl $Source {
              /// The mirrored fields of `v2`, with these proprietary fields.
 -            fn from_v2_fields(v2: $V2, $( $proprietary: $P ),*) -> Self {
@@ crates/concurrent-psbt/src/psbt/tx.rs: impl UnorderedPsbt {
 +            })
 +            .collect::<Result<Vec<_>, _>>()?;
 +        let inputs = InputSet::try_from_inputs(inputs)?;
-         let inputs = if global.tx_modifiable_flags & INPUTS_MODIFIABLE == 0 {
+         let inputs = if global.tx_modifiable_flags() & INPUTS_MODIFIABLE == 0 {
              inputs.freeze()
          } else {
 @@ crates/concurrent-psbt/src/psbt/tx.rs: mod tests {

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 80ea45d to 00ec300 Compare November 15, 2026 02:13
@github-actions

Copy link
Copy Markdown
range-diff for force push 80ea45da32 → 00ec300c1b November 15, 2026 02:13 UTC: 1 modified, 1 unchanged; 2 commits; base a3a74d8ae5 → f75c6a9162 (diverged, 8 ahead and 8 behind)

reproduce: git range-diff a3a74d8..80ea45d f75c6a9..00ec300

1:  1faa38fcf4   +0  -0 0f = 1:  514abd3c4a   +0  -0 0f define own Global, Input and Output structs
2:  80ea45da32 +907 -95 8f ! 2:  00ec300c1b +907 -95 8f proprietary fields for unordered PSBT spec
2: 80ea45da32 ! 2: 00ec300c1b proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                  })
          }
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-                 prop_assert_eq!(r.is_ok(), r.try_unwrap().is_ok());
+                 prop_assert_eq!(o.redeem_script(), &redeem);
              }
  
 +            #[test]

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 00ec300 to 6dcdbc0 Compare November 15, 2026 23:52
@github-actions

Copy link
Copy Markdown
range-diff for force push 00ec300c1b → 6dcdbc01d9 November 15, 2026 23:52 UTC: 2 unchanged; 2 commits; base f75c6a9162 → 35bf83523d (diverged, 8 ahead and 8 behind)

reproduce: git range-diff f75c6a9..00ec300 35bf835..6dcdbc0

1:  514abd3c4a   +0  -0 0f = 1:  9a7f0fe874   +0  -0 0f define own Global, Input and Output structs
2:  00ec300c1b +907 -95 8f = 2:  6dcdbc01d9 +907 -95 8f proprietary fields for unordered PSBT spec

@github-actions

Copy link
Copy Markdown
range-diff for force push 00ec300c1b → 6dcdbc01d9 November 15, 2026 23:55 UTC: 2 unchanged; 2 commits; base f75c6a9162 → 35bf83523d (diverged, 8 ahead and 8 behind)

reproduce: git range-diff f75c6a9..00ec300 35bf835..6dcdbc0

1:  514abd3c4a   +0  -0 0f = 1:  9a7f0fe874   +0  -0 0f define own Global, Input and Output structs
2:  00ec300c1b +907 -95 8f = 2:  6dcdbc01d9 +907 -95 8f proprietary fields for unordered PSBT spec

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 6dcdbc0 to 1f4cc5b Compare November 16, 2026 00:16
@github-actions

Copy link
Copy Markdown
range-diff for force push 6dcdbc01d9 → 1f4cc5b213 November 16, 2026 00:16 UTC: 2 unchanged; 2 commits; base 35bf83523d → d7528fc86f (diverged, 5 ahead and 5 behind)

reproduce: git range-diff 35bf835..6dcdbc0 d7528fc..1f4cc5b

1:  9a7f0fe874   +0  -0 0f = 1:  e94b5896b8   +0  -0 0f define own Global, Input and Output structs
2:  6dcdbc01d9 +907 -95 8f = 2:  1f4cc5b213 +907 -95 8f proprietary fields for unordered PSBT spec

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 1f4cc5b to c42d27a Compare November 16, 2026 03:22
@github-actions

Copy link
Copy Markdown
range-diff for force push 1f4cc5b213 → c42d27aab8 November 16, 2026 03:22 UTC: 1 modified, 1 unchanged; 2 commits; base d7528fc86f → 7fe9c87e5c (diverged, 8 ahead and 8 behind)

reproduce: git range-diff d7528fc..1f4cc5b 7fe9c87..c42d27a

1:  e94b5896b8   +0  -0 0f = 1:  53adbf4311   +0  -0 0f define own Global, Input and Output structs
2:  1f4cc5b213 +907 -95 8f ! 2:  c42d27aab8 +985 -93 9f proprietary fields for unordered PSBT spec
2: 1f4cc5b213 ! 2: c42d27aab8 proprietary fields for unordered PSBT spec
@@ Commit message
     proprietary fields for unordered PSBT spec
 
  ## crates/concurrent-psbt/src/lib.rs ##
-@@ crates/concurrent-psbt/src/lib.rs: pub use psbt::global;
- pub use psbt::input;
- pub use psbt::output;
- pub use psbt::tx;
+@@ crates/concurrent-psbt/src/lib.rs: pub use psbt::conflicts;
+ pub use lattice::lift::{Lift, ResultWrapped};
+ 
+ pub use lattice::conflicts::Conflicts;
 +
 +/// Proprietary field prefix for all concurrent-psbt extensions.
 +///
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +    },
  }
  
+ record_conflicts! {
+@@ crates/concurrent-psbt/src/psbt/global.rs: record_conflicts! {
+     Xpub => xpubs[Xpub]: KeySource,
+     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+     Unknown => unknowns[raw::Key]: Vec<u8>,
++    Unordered => unordered: bool,
++    SortKeyDerivation => sort_key_derivation: SortKeyDerivation,
++    SortSeed => sort_seed: SortSeed,
+     }
+ }
+ 
  impl Default for Global {
      fn default() -> Self {
 -        Self::from_v2_fields(psbt_v2::v2::Global::default())
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
          }
  
          #[test]
--        fn for_each_conflict_reports_the_conflicted_field() {
+-        fn conflicts_identify_the_field() {
 -            let mut a = Global::default();
 -            let mut b = Global::default();
 -            a.tx_version = transaction::Version::ONE;
 -            b.tx_version = transaction::Version::TWO;
+-            let joined = a.wrap().join(b.wrap());
 +        fn globals_with_different_tx_versions_conflict() {
 +            let with_version = |tx_version| Global {
 +                tx_version,
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +            let joined = with_version(transaction::Version::ONE)
 +                .wrap()
 +                .join(with_version(transaction::Version::TWO).wrap());
-             let mut fields = Vec::new();
--            a.wrap()
--                .join(b.wrap())
--                .for_each_conflict(|field, _, _| fields.push(field.to_owned()));
-+            joined.for_each_conflict(|field, _, _| fields.push(field.to_owned()));
-             assert_eq!(fields, ["tx_version"]);
+             assert_eq!(
+                 joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
+                 [GlobalField::TxVersion]
+             );
 +            assert_eq!(joined.clone().try_unwrap(), Err(joined));
          }
      }
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
                  prop_assert_eq!((v2.input_count, v2.output_count), (input_count, output_count));
 -                prop_assert_eq!(Global::from(v2), a);
 +                prop_assert_eq!(Global::try_from(v2), Ok(a));
-+            }
-+
-+            #[test]
+             }
+ 
+             #[test]
+-            fn is_ok_consistency(a in arb_result_global()) {
 +            fn sort_fields_own_their_keys(
 +                a in arb_global(),
 +                raw in proptest::collection::vec(any::<u8>(), 0..=17),
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +
 +            #[test]
 +            fn is_ok_iff_try_unwrap_succeeds(a in arb_result_global()) {
+                 prop_assert_eq!(a.conflicts().next().is_none(), a.is_ok());
+-                if a.is_ok() {
+-                    prop_assert!(a.try_unwrap().is_ok());
+-                } else {
+-                    prop_assert!(a.try_unwrap().is_err());
 +                prop_assert_eq!(a.is_ok(), a.try_unwrap().is_ok());
 +            }
 +
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +                    }
 +                };
 +                prop_assert_eq!(Global::try_from(v2).map(|g| g.sort_key_derivation()), Ok(Some(derivation)));
-             }
- 
-             #[test]
--            fn is_ok_consistency(a in arb_result_global()) {
--                if a.is_ok() {
--                    prop_assert!(a.try_unwrap().is_ok());
--                } else {
--                    prop_assert!(a.try_unwrap().is_err());
++            }
++
++            #[test]
 +            fn sort_seed_is_at_least_16_bytes(seed in proptest::collection::vec(any::<u8>(), 0..=24)) {
 +                let v2 = v2_with_fields(&[(PSBT_GLOBAL_SORT_SEED_SUBTYPE, seed.clone())]);
 +                match Global::try_from(v2) {
@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
 +    },
  }
  
+ record_conflicts! {
+@@ crates/concurrent-psbt/src/psbt/input.rs: record_conflicts! {
+     TapMerkleRoot => tap_merkle_root: TapNodeHash,
+     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+     Unknown => unknowns[raw::Key]: Vec<u8>,
++    SortKey => sort_key: SortKey,
+     }
+ }
+ 
  impl Input {
      /// Create an input spending `outpoint`, with every other field unset.
      pub fn new(outpoint: &OutPoint) -> Self {
@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input)
  #[cfg_attr(coverage_nightly, coverage(off))]
  pub(crate) mod tests {
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
-             }
+             assert_eq!(values.into_iter().next(), input.proprietaries.get(key));
          }
  
 +        #[test]
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
      },
  }
  
+@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
+     TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
+     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+     Unknown => unknowns[raw::Key]: Vec<u8>,
++    SortKey => sort_key: SortKey,
+     UniqueId => unique_id: UniqueId,
+     }
+ }
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl Output {
                  ..psbt_v2::v2::Output::default()
              },
@@ crates/concurrent-psbt/src/psbt/proprietary.rs: pub(crate) fn key(subtype: u8) -
      type Value;
 
  ## crates/concurrent-psbt/src/psbt/tx.rs ##
-@@ crates/concurrent-psbt/src/psbt/tx.rs: use psbt_v2::v2::Psbt;
- 
- use crate::lattice::join::Join;
+@@ crates/concurrent-psbt/src/psbt/tx.rs: use crate::lattice::join::Join;
+ use crate::{Conflicts, Lift, ResultWrapped};
  
+ use super::conflicts::PsbtConflict;
 -use super::global::{Global, ResultGlobal};
 -use super::input::{DuplicateInput, Input, InputSet, ResultInputSet};
 +use super::global::{Global, InvalidGlobal, ResultGlobal, SortSeed};
@@ crates/concurrent-psbt/src/values.rs: impl<T: IdempotentValue> PartialJoin for T
  impl IdempotentValue for u8 {}
  impl IdempotentValue for u32 {}
  impl IdempotentValue for usize {}
+
+ ## crates/concurrent-psbt/tests/conflicts.rs ##
+@@ crates/concurrent-psbt/tests/conflicts.rs: fn public_iterators_compose_through_nested_containers() {
+     );
+     assert!(conflicts.next().is_none());
+ }
++
++#[test]
++#[cfg_attr(coverage_nightly, coverage(off))]
++fn proprietary_sort_fields_keep_their_typed_paths() {
++    use concurrent_psbt::global::{Global, SortKeyDerivation, SortSeed};
++    use concurrent_psbt::input::{InputConflict, InputField, SortKey};
++    use concurrent_psbt::output::OutputField;
++
++    let mut global = Global::default();
++    global.set_sort_seed(SortSeed::try_from(vec![1; 16]).unwrap());
++    global.set_sort_key_derivation(SortKeyDerivation::Explicit);
++    let mut other = global.clone();
++    other.set_unordered();
++    other.set_sort_seed(SortSeed::try_from(vec![2; 16]).unwrap());
++    other.set_sort_key_derivation(SortKeyDerivation::Derived);
++    let joined = global.wrap().join(other.wrap());
++    assert_eq!(
++        joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
++        [
++            GlobalField::Unordered,
++            GlobalField::SortKeyDerivation,
++            GlobalField::SortSeed
++        ]
++    );
++
++    let outpoint = OutPoint::null();
++    let mut input = Input::new(&outpoint);
++    input.set_sort_key(SortKey::try_from(vec![1]).unwrap());
++    let mut other = input.clone();
++    other.set_sort_key(SortKey::try_from(vec![2]).unwrap());
++    let joined = InputSet::try_from_inputs([input])
++        .unwrap()
++        .wrap()
++        .join(InputSet::try_from_inputs([other]).unwrap().wrap());
++    let conflict = joined.conflicts().next().unwrap();
++    assert_eq!(
++        conflict.path(),
++        ConflictPath::Input {
++            outpoint: &outpoint,
++            field: InputField::SortKey
++        }
++    );
++    let PsbtConflict::Input {
++        conflict: InputConflict::SortKey { values },
++        ..
++    } = conflict
++    else {
++        panic!("input sort key conflict");
++    };
++    assert_eq!(
++        values
++            .into_iter()
++            .map(SortKey::as_bytes)
++            .collect::<Vec<_>>(),
++        [vec![1], vec![2]]
++    );
++
++    let id = UniqueId::try_from(vec![3]).unwrap();
++    let mut output = Output::new(id.clone(), Amount::from_sat(100), ScriptBuf::new());
++    output.set_sort_key(SortKey::try_from(vec![4]).unwrap());
++    let mut other = output.clone();
++    other.set_sort_key(SortKey::try_from(vec![5]).unwrap());
++    let joined = OutputSet::try_from_outputs([output])
++        .unwrap()
++        .wrap()
++        .join(OutputSet::try_from_outputs([other]).unwrap().wrap());
++    assert_eq!(
++        joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
++        [ConflictPath::Output {
++            id: &id,
++            field: OutputField::SortKey
++        }]
++    );
++}

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from c42d27a to cf4c10e Compare November 16, 2026 04:27
@github-actions

Copy link
Copy Markdown
range-diff for force push c42d27aab8 → cf4c10eb8b November 16, 2026 04:30 UTC: 1 modified, 1 unchanged; 2 commits; base 7fe9c87e5c → 5fa5b95986 (diverged, 8 ahead and 8 behind)

reproduce: git range-diff 7fe9c87..c42d27a 5fa5b95..cf4c10e

1:  53adbf4311   +0  -0 0f = 1:  f9005e0427   +0  -0 0f define own Global, Input and Output structs
2:  c42d27aab8 +985 -93 9f ! 2:  cf4c10eb8b +980 -93 9f proprietary fields for unordered PSBT spec
2: c42d27aab8 ! 2: cf4c10eb8b proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::transaction;
      /// The global fields of a PSBT.
      ///
 @@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
+         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 -    proprietary: {},
 +    proprietary: {
-+        pub(crate) unordered: bool = TxUnorderedField,
-+        pub(crate) sort_key_derivation: Option<SortKeyDerivation> = SortKeyDerivationField,
-+        pub(crate) sort_seed: Option<SortSeed> = SortSeedField,
++        pub(crate) unordered: bool = TxUnorderedField => Unordered,
++        pub(crate) sort_key_derivation: Option<SortKeyDerivation> = SortKeyDerivationField => SortKeyDerivation(SortKeyDerivation),
++        pub(crate) sort_seed: Option<SortSeed> = SortSeedField => SortSeed(SortSeed),
 +    },
  }
  
- record_conflicts! {
-@@ crates/concurrent-psbt/src/psbt/global.rs: record_conflicts! {
-     Xpub => xpubs[Xpub]: KeySource,
-     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-     Unknown => unknowns[raw::Key]: Vec<u8>,
-+    Unordered => unordered: bool,
-+    SortKeyDerivation => sort_key_derivation: SortKeyDerivation,
-+    SortSeed => sort_seed: SortSeed,
-     }
- }
- 
  impl Default for Global {
      fn default() -> Self {
 -        Self::from_v2_fields(psbt_v2::v2::Global::default())
@@ crates/concurrent-psbt/src/psbt/input.rs: use psbt_v2::raw;
      /// A PSBT input, mirroring the BIP 370 per-input map.
      source: Input,
 @@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
+         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 -    proprietary: {},
 +    proprietary: {
-+        pub(crate) sort_key: Option<SortKey> = SortKeyField<PSBT_IN_SORT_KEY_SUBTYPE>,
++        pub(crate) sort_key: Option<SortKey> = SortKeyField<PSBT_IN_SORT_KEY_SUBTYPE> => SortKey(SortKey),
 +    },
  }
  
- record_conflicts! {
-@@ crates/concurrent-psbt/src/psbt/input.rs: record_conflicts! {
-     TapMerkleRoot => tap_merkle_root: TapNodeHash,
-     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-     Unknown => unknowns[raw::Key]: Vec<u8>,
-+    SortKey => sort_key: SortKey,
-     }
- }
- 
  impl Input {
      /// Create an input spending `outpoint`, with every other field unset.
      pub fn new(outpoint: &OutPoint) -> Self {
@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
 
  ## crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs ##
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             $(
                  $(#[$proprietary_meta:meta])* $proprietary_vis:vis
                  $proprietary:ident : $P:ty = $Codec:ty
+                 => $ProprietaryVariant:ident $( [ $ProprietaryKey:ty ] )? $( ( $ProprietaryValue:ty ) )?
 -            ),* $(,)?
 +            ),+ $(,)?
          } $(,)?
      ) => {
          joinable_struct! {
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             result: $Result,
+             conflicts: $Conflict, $Field,
              fields: {
-                 $( $(#[$field_meta])* $field: $T, )+
--                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )*
-+                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )+
+                 $( $(#[$field_meta])* $field: $T => $Variant $( [ $Key ] )? $( ( $Value ) )?, )+
+-                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P => $ProprietaryVariant $( [ $ProprietaryKey ] )? $( ( $ProprietaryValue ) )?, )*
++                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P => $ProprietaryVariant $( [ $ProprietaryKey ] )? $( ( $ProprietaryValue ) )?, )+
              }
          }
  
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::TapTree;
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
      },
      proprietary: {
-         unique_id: UniqueId = UniqueIdField,
-+        pub(crate) sort_key: Option<SortKey> = SortKeyField<PSBT_OUT_SORT_KEY_SUBTYPE>,
+         unique_id: UniqueId = UniqueIdField => UniqueId,
++        pub(crate) sort_key: Option<SortKey> = SortKeyField<PSBT_OUT_SORT_KEY_SUBTYPE> => SortKey(SortKey),
      },
  }
  
-@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
-     TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
-     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-     Unknown => unknowns[raw::Key]: Vec<u8>,
-+    SortKey => sort_key: SortKey,
-     UniqueId => unique_id: UniqueId,
-     }
- }
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl Output {
                  ..psbt_v2::v2::Output::default()
              },

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from cf4c10e to 59080f8 Compare November 16, 2026 04:58
@github-actions

Copy link
Copy Markdown
range-diff for force push cf4c10eb8b → 59080f841c November 16, 2026 06:07 UTC: 1 modified, 1 unchanged; 2 commits; base 5fa5b95986 → e4f34a0d4a (diverged, 8 ahead and 8 behind)

reproduce: git range-diff 5fa5b95..cf4c10e e4f34a0..59080f8

1:  f9005e0427   +0  -0 0f = 1:  efeb20007b   +0  -0 0f define own Global, Input and Output structs
2:  cf4c10eb8b +980 -93 9f ! 2:  59080f841c +980 -93 9f proprietary fields for unordered PSBT spec
2: cf4c10eb8b ! 2: 59080f841c proprietary fields for unordered PSBT spec
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
          }
 
  ## crates/concurrent-psbt/src/psbt/input.rs ##
-@@ crates/concurrent-psbt/src/psbt/input.rs: use psbt_v2::raw;
- 
- use super::tap_leaf_hashes::{TapKeyOrigins, TapLeafHashes};
+@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::{OutPoint, ScriptBuf, Sequence, Transaction, TxOut, Txid, Witness,
+ use psbt_v2::PsbtSighashType;
+ use psbt_v2::raw;
  
 +use super::proprietary::ProprietaryField;
 +
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 -            fn from_v2_fields(v2: $V2, $( $proprietary: $P ),*) -> Self {
 +            fn from_v2_fields(v2: $V2, $( $proprietary: $P ),+) -> Self {
                  Self {
-                     $( $field: joinable_struct!(@from_v2 v2.$field $(, $Conversion)?), )+
+                     $( $field: v2.$field, )+
 -                    $( $proprietary, )*
 +                    $( $proprietary, )+
                  }
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
                  base
              }
          }
-@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-         <$Conversion as $crate::psbt::joinable_struct_macro::MirroredField>::into_v2($value)
      };
  
 -    (@decode $v2:ident []) => {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::TapTree;
- use bitcoin::{Amount, ScriptBuf};
+ use bitcoin::{Amount, ScriptBuf, TapLeafHash};
  use psbt_v2::raw;
  
 +use super::input::{InvalidSortKey, SortKey, SortKeyField};
  use super::proprietary::ProprietaryField;
- use super::tap_leaf_hashes::{TapKeyOrigins, TapLeafHashes};
- 
+ joinable_struct! {
+     /// A PSBT output, mirroring the BIP 370 per-output map, identified by its
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
      },
      proprietary: {

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from 59080f8 to a4a0760 Compare November 16, 2026 18:18
@github-actions

Copy link
Copy Markdown
range-diff for force push 59080f841c → a4a076085e November 16, 2026 18:18 UTC: 2 unchanged; 2 commits; base e4f34a0d4a → c74ab8412a (diverged, 4 ahead and 4 behind)

reproduce: git range-diff e4f34a0..59080f8 c74ab84..a4a0760

1:  efeb20007b   +0  -0 0f = 1:  6177c36dba   +0  -0 0f define own Global, Input and Output structs
2:  59080f841c +980 -93 9f = 2:  a4a076085e +980 -93 9f proprietary fields for unordered PSBT spec

@yuval-block
yuval-block force-pushed the concurrent-psbt-fields branch from a4a0760 to 78f9665 Compare November 16, 2026 23:42
@github-actions

Copy link
Copy Markdown
range-diff for force push a4a076085e → 78f9665f79 November 16, 2026 23:42 UTC: 2 unchanged; 2 commits; base c74ab8412a → 2527d0f2ef (diverged, 5 ahead and 5 behind)

reproduce: git range-diff c74ab84..a4a0760 2527d0f..78f9665

1:  6177c36dba   +0  -0 0f = 1:  25e909bbd0   +0  -0 0f define own Global, Input and Output structs
2:  a4a076085e +980 -93 9f = 2:  78f9665f79 +980 -93 9f proprietary fields for unordered PSBT spec

///
/// `0x01` = sort keys derived from seed (explicit keys MUST NOT be set).
/// `0x00` = explicit sort keys required.
pub const PSBT_GLOBAL_SORT_KEY_DERIVATION_SUBTYPE: u8 = 0x12;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec field name differs from code

The spec names this global field PSBT_GLOBAL_SORT_DETERMINISTIC; the new public constant, accessors, and error messages call it PSBT_GLOBAL_SORT_KEY_DERIVATION, so an implementer following the spec looks for a different field name and a rejected PSBT's error names a field absent from the spec.

PSBT_GLOBAL_SORT_DETERMINISTIC = TBD

— fungi-protocol/docs@f2806d9 · docs/psbt-concurrent.md#L38

oakagent · automated · 78f9665

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.

3 participants