BIP-375: update validation to match sorting outputs with same scan key

Fix output script validation for silent payment output ordering when multiple 
outputs share the same scan key (labeled addresses of one recipient).
This commit is contained in:
macgyver13 committed 2026-11-04 18:26:44 -05:00
1 parent 434a4d2659
commit d31236854b
1 file changed
+10 -7
+10 -7
View File
@@ -233,7 +233,7 @@ def validate_dleq_proof(
) -> Tuple[bool, str]:
"""
Verify a DLEQ proof for silent payments
Checks:
- ECDH share and DLEQ proof lengths
- Verify DLEQ proof correctness
@@ -323,15 +323,18 @@ def validate_output_scripts(psbt: PSBT) -> Tuple[bool, str]:
output_index = struct.unpack("<I", output_index_bytes)[0]
outpoints.append(COutPoint(txid_int, output_index))
# Silent payment codes sorted lexicographically, ties broken by output index
sp_outputs = [
(output_map[PSBT_OUT_SP_V0_INFO], output_idx, output_map)
for output_idx, output_map in enumerate(psbt.o)
if PSBT_OUT_SP_V0_INFO in output_map
]
sp_outputs.sort(key=lambda entry: (entry[0], entry[1]))
# Track k values per scan key
scan_key_k_values = {}
# Validate each SP output
for output_idx, output_map in enumerate(psbt.o):
if PSBT_OUT_SP_V0_INFO not in output_map:
continue # Skip non-SP outputs
sp_info = output_map[PSBT_OUT_SP_V0_INFO]
for sp_info, output_idx, output_map in sp_outputs:
scan_pubkey_bytes = sp_info[:33]
spend_pubkey_bytes = sp_info[33:]