From 14b490b3f25cd7fc116d741de9aa28b37080908e Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 31 Oct 2023 15:54:13 +0100 Subject: [PATCH] test: make sure we fail on tapret commitment if no commitment was created --- dbc/src/tapret/tx.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/dbc/src/tapret/tx.rs b/dbc/src/tapret/tx.rs index 207d4d6f..1c01e262 100644 --- a/dbc/src/tapret/tx.rs +++ b/dbc/src/tapret/tx.rs @@ -83,3 +83,40 @@ impl ConvolveCommit for Tx { Err(TapretError::NoTaprootOutput) } } + +#[cfg(test)] +mod test { + use std::str::FromStr; + + use amplify::hex::FromHex; + use amplify::Bytes32; + use bc::InternalPk; + use commit_verify::mpc::Commitment; + use secp256k1::{ffi, XOnlyPublicKey}; + + use super::*; + use crate::tapret::TapretPathProof; + + #[test] + fn no_commitment() { + let tx = Tx::from_str( + "020000000001027763e2a0ad25d45b63a19c33491b67c5037e72709121290bac5481a5d5d0c9330100000000ffffffff7763e2a0ad25d45b63a19c33491b67c5037e72709121290bac5481a5d5d0c9330400000000ffffffff02026e010000000000225120455dfcc062ef80609b007377f127e4abdb5cb0052158af1fab7aa628c34563f1d508000000000000225120a2788d4208ec6b4b600aef4c13075cf1d47bda0299ed1e6eedce4e7a90fb2a2c0141150df5377a34deded048dc01bff3d4f5f31d8a89fe2fbf1d0295993c1f899b3cefd1a63900ea6346b78edd476524c08ae094ff417bfa525b585ee66ebc26bb9e010141d959f21b498d90c2ff9f5b0bf3aee9158527501162eab2e3d56371714877a97df80caab15e366855aa56443b7d081c234a4ce4d6414815a874624cbe46b643370100000000" + ).unwrap(); + + let internal_pk: XOnlyPublicKey = unsafe { + ffi::XOnlyPublicKey::from_array_unchecked(<[u8; 64]>::from_hex( + "cb5271aa59fc637e29d034ec75363ca241fda5d3939684603b469b185be7e50f18ec6fd539e7dc1fd5fb4cf046d2cef5028a5ca0cdb09a252683e6a6eb2ad61d", + ).unwrap()).into() + }; + let proof = TapretProof { + path_proof: TapretPathProof { + partner_node: None, + nonce: 0, + }, + internal_pk: InternalPk::from(internal_pk), + }; + + let msg = Commitment::from(Bytes32::zero()); + assert!(!ConvolveCommitProof::<_, Tx, _>::verify(&proof, &msg, &tx).unwrap()) + } +}