Skip to content

Commit

Permalink
seals: reserve place for fallback proofs
Browse files Browse the repository at this point in the history
Signed-off-by: Dr Maxim Orlovsky <[email protected]>
  • Loading branch information
dr-orlovsky committed Nov 18, 2024
1 parent 5f23087 commit e80d084
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion seals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
33 changes: 23 additions & 10 deletions seals/src/txout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Check warning on line 108 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L108

Added line #L108 was not covered by tests
Expand All @@ -116,10 +118,17 @@ pub struct Anchor<D: dbc::Proof> {
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<D: dbc::Proof> Anchor<D> {
// TODO: Change when the fallback proofs are ready
pub fn is_fallback(&self) -> bool { false }

Check warning on line 127 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L127

Added line #L127 was not covered by tests
// TODO: Change when the fallback proofs are ready
pub fn verify_fallback(&self) -> Result<(), AnchorError> { Ok(()) }

Check warning on line 129 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L129

Added line #L129 was not covered by tests
}

/// Proof data for verification of deterministic bitcoin commitment produced from anchor.
pub struct Proof<D: dbc::Proof> {
pub mpc_commit: mpc::Commitment,
Expand Down Expand Up @@ -170,14 +179,14 @@ impl<D: dbc::Proof> SingleUseSeal for TxoSeal<D> {

fn is_included(&self, message: Self::Message, witness: &SealWitness<Self>) -> 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)

Check warning on line 183 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L180-L183

Added lines #L180 - L183 were not covered by tests
// TODO: && witness.client.fallback_proof.is_none()
}
TxoSealExt::Fallback(fallback) => {
witness.client.mmb_proof.verify(fallback, message, &witness.published)

Check warning on line 186 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L185-L186

Added lines #L185 - L186 were not covered by tests
// TODO: && witness.client.fallback_proof.is_some()
}
// If we are provided a fallback proof but no fallback seal were defined
TxoSealExt::Noise(_) => false,

Check warning on line 189 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L189

Added line #L189 was not covered by tests
}
}

Check warning on line 191 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L191

Added line #L191 was not covered by tests
}
Expand All @@ -196,13 +205,10 @@ impl<D: dbc::Proof> PublishedWitness<TxoSeal<D>> for Tx {
impl<D: dbc::Proof> ClientSideWitness for Anchor<D> {
type Proof = Proof<D>;
type Seal = TxoSeal<D>;
type Error = mpc::InvalidProof;
type Error = AnchorError;

fn convolve_commit(&self, _: Bytes32) -> Result<Proof<D>, 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)?;
Expand All @@ -212,3 +218,10 @@ impl<D: dbc::Proof> ClientSideWitness for Anchor<D> {
})
}

Check warning on line 219 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L210-L219

Added lines #L210 - L219 were not covered by tests
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Error, Debug, Display, From)]
#[display(inner)]
pub enum AnchorError {
#[from]
Mpc(mpc::InvalidProof),
}

0 comments on commit e80d084

Please sign in to comment.