diff --git a/seals/src/lib.rs b/seals/src/lib.rs index 69db428b..175c5db2 100644 --- a/seals/src/lib.rs +++ b/seals/src/lib.rs @@ -47,4 +47,4 @@ mod txout; mod secret; pub use secret::SecretSeal; -pub use txout::{Anchor, Noise, TxoSeal, TxoSealExt}; +pub use txout::{Anchor, AnchorError, Noise, TxoSeal, TxoSealExt}; diff --git a/seals/src/txout.rs b/seals/src/txout.rs index ba2a23da..a9c004e2 100644 --- a/seals/src/txout.rs +++ b/seals/src/txout.rs @@ -100,7 +100,9 @@ pub mod mmb { } } -/// Anchor is a set of data required for the client-side validation of a Bitcoin Txout single-use +/// Anchor is a client-side witness for the bitcoin txout seals. +/// +/// Anchor is a set of data required for the client-side validation of a bitcoin txout single-use /// seal, which can't be recovered from the transaction and other public information itself. #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] @@ -116,10 +118,17 @@ pub struct Anchor { pub mpc_proof: mpc::MerkleProof, pub dbc_proof: D, #[cfg_attr(feature = "serde", serde(skip))] - // TODO: This should become an option + // TODO: This should become an option once fallback proofs are ready pub fallback_proof: ReservedBytes<1>, } +impl Anchor { + // TODO: Change when the fallback proofs are ready + pub fn is_fallback(&self) -> bool { false } + // TODO: Change when the fallback proofs are ready + pub fn verify_fallback(&self) -> Result<(), AnchorError> { Ok(()) } +} + /// Proof data for verification of deterministic bitcoin commitment produced from anchor. pub struct Proof { pub mpc_commit: mpc::Commitment, @@ -170,14 +179,14 @@ impl SingleUseSeal for TxoSeal { fn is_included(&self, message: Self::Message, witness: &SealWitness) -> bool { match self.secondary { - TxoSealExt::Noise(_) => { + TxoSealExt::Noise(_) | TxoSealExt::Fallback(_) if !witness.client.is_fallback() => { witness.client.mmb_proof.verify(self.primary, message, &witness.published) - // TODO: && witness.client.fallback_proof.is_none() } TxoSealExt::Fallback(fallback) => { witness.client.mmb_proof.verify(fallback, message, &witness.published) - // TODO: && witness.client.fallback_proof.is_some() } + // If we are provided a fallback proof but no fallback seal were defined + TxoSealExt::Noise(_) => false, } } } @@ -196,13 +205,10 @@ impl PublishedWitness> for Tx { impl ClientSideWitness for Anchor { type Proof = Proof; type Seal = TxoSeal; - type Error = mpc::InvalidProof; + type Error = AnchorError; fn convolve_commit(&self, _: Bytes32) -> Result, Self::Error> { - // TODO: Verify fallback proof - // if let Some(_fallback_proof) = self.fallback_proof { - // } - + self.verify_fallback()?; let bundle_id = self.mmb_proof.commit_id(); let mpc_message = mpc::Message::from_byte_array(bundle_id.to_byte_array()); let mpc_commit = self.mpc_proof.convolve(self.mpc_protocol, mpc_message)?; @@ -212,3 +218,10 @@ impl ClientSideWitness for Anchor { }) } } + +#[derive(Copy, Clone, PartialEq, Eq, Hash, Error, Debug, Display, From)] +#[display(inner)] +pub enum AnchorError { + #[from] + Mpc(mpc::InvalidProof), +}