pub trait EmbedCommitVerify<Msg> where
    Self: Eq + Sized,
    Msg: CommitEncode
{ type Proof: EmbedCommitProof<Msg, Self>; type Protocol: EmbedCommitProtocol; type CommitError: Error; fn embed_commit(
        &mut self,
        msg: &Msg,
        protocol: &Self::Protocol
    ) -> Result<Self::Proof, Self::CommitError>; fn verify(
        self,
        msg: &Msg,
        proof: Self::Proof,
        protocol: &Self::Protocol
    ) -> Result<bool, Self::CommitError> { ... } }
Expand description

Trait for embed-commit-verify scheme, where some data structure (named container) may commit to existing message (producing commitment data structure and a proof) in such way that the original message can’t be restored from the commitment, however the fact of the commitment may be deterministically verified when the message and the proof are revealed.

To use embed-commit-verify scheme one needs to implement this trait for a data structure providing context for a specific commitment protocol, and provide it (through associated types) with the used container, message, proof and commitment types.

Operations with embed-commit-verify scheme may be represented in form of EmbedCommit: (Container, Message) -> (Container*, Proof) (see Self::embed_commit and Verify: (Container*, Message, Proof) -> bool (see Self::verify).

This trait is heavily used in deterministic bitcoin commitments

Required Associated Types

The proof of the commitment produced as a result of EmbedCommitVerify::embed_commit procedure. This proof is later used for verification.

Context / configuration type for commitment scheme protocol used for this container type.

Error type that may be reported during `EmbedCommitVerify::embed_commit`` procedure.

Required Methods

Creates a commitment to a message and embeds it into the provided container (self) by mutating it and returning commitment proof.

Implementations must error with a dedicated error type enumerating commitment procedure mistakes.

Provided Methods

Verifies commitment with commitment proof against the message.

Default implementation reconstructs original container with the EmbedCommitProof::original_container method and repeats Self::embed_commit procedure checking that the resulting proof and commitment matches the provided self and proof.

Errors if the provided commitment can’t be created, i.e. the Self::embed_commit procedure for the original container, restored from the proof and current container, can’t be performed. This means that the verification has failed and the commitment and proof are invalid. The function returns error in this case (ano not simply false) since this usually means the software error in managing container and proof data, or selection of a different commitment protocol parameters comparing to the ones used during commitment creation. In all these cases we’d like to provide devs with more information for debugging.

The proper way of using the function in a well-debugged software should be if commitment.verify(...).expect("proof managing system") { .. } and not if commitment.verify(...).unwrap_or(false) { .. }.

Implementors