pub trait EmbedCommitVerify<Msg, Protocol>where
Self: Sized,
Protocol: CommitmentProtocol,{
type Proof: EmbedCommitProof<Msg, Self, Protocol>;
type CommitError: Error;
// Required method
fn embed_commit(
&mut self,
msg: &Msg,
) -> Result<Self::Proof, Self::CommitError>;
// Provided method
fn verify(
&self,
msg: &Msg,
proof: &Self::Proof,
) -> Result<(), EmbedVerifyError<Self::CommitError>>
where Self: VerifyEq,
Self::Proof: VerifyEq { ... }
}
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 acting as a container for a specific commitment under certain protocol, specified as generic parameter. The container type must specify as associated types 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.
§Protocol definition
Generic parameter Protocol
provides context & configuration for commitment
scheme protocol used for this container type.
Introduction of this generic allows to:
- implement trait for foreign data types;
- add multiple implementations under different commitment protocols to the
combination of the same message and container type (each of each will have
its own
Proof
type defined as an associated generic).
Usually represents a non-instantiable type, but may be a structure containing commitment protocol configuration or context objects.
// Uninstantiable type
pub enum Lnpbp6 {}
impl CommitmentProtocol for Lnpbp6 {}
// Protocol definition
pub enum Lnpbp1 {}
// ...
Required Associated Types§
Sourcetype Proof: EmbedCommitProof<Msg, Self, Protocol>
type Proof: EmbedCommitProof<Msg, Self, Protocol>
The proof of the commitment produced as a result of
Self::embed_commit
procedure. This proof is later used
for verification.
Sourcetype CommitError: Error
type CommitError: Error
Error type that may be reported during Self::embed_commit
procedure.
It may also be returned from Self::verify
(wrapped into
EmbedVerifyError
in case the proof data are invalid and the
commitment can’t be re-created.
Required Methods§
Sourcefn embed_commit(&mut self, msg: &Msg) -> Result<Self::Proof, Self::CommitError>
fn embed_commit(&mut self, msg: &Msg) -> Result<Self::Proof, Self::CommitError>
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§
Sourcefn verify(
&self,
msg: &Msg,
proof: &Self::Proof,
) -> Result<(), EmbedVerifyError<Self::CommitError>>
fn verify( &self, msg: &Msg, proof: &Self::Proof, ) -> Result<(), EmbedVerifyError<Self::CommitError>>
Verifies commitment with commitment proof against the message.
Default implementation reconstructs original container with the
EmbedCommitProof::restore_original_container
method and repeats
Self::embed_commit
procedure checking that the resulting proof and
commitment matches the provided self
and proof
.
§Errors
Errors if the commitment doesn’t pass the validation (see
EmbedVerifyError
variants for the cases when this may happen).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.