Add `SpendProver::encode_proof` and `OutputProver::encode_proof`
This commit is contained in:
parent
e6fa567332
commit
296f75954b
|
@ -9,7 +9,7 @@ use crate::{
|
|||
value::{NoteValue, ValueCommitTrapdoor, ValueCommitment},
|
||||
MerklePath,
|
||||
},
|
||||
transaction::components::{Amount, GROTH_PROOF_SIZE},
|
||||
transaction::components::{sapling::GrothProofBytes, Amount, GROTH_PROOF_SIZE},
|
||||
};
|
||||
|
||||
use super::{Diversifier, PaymentAddress, ProofGenerationKey, Rseed};
|
||||
|
@ -42,6 +42,11 @@ pub trait SpendProver {
|
|||
circuit: sapling::circuit::Spend,
|
||||
rng: &mut R,
|
||||
) -> Self::Proof;
|
||||
|
||||
/// Encodes the given Sapling [`SpendDescription`] proof, erasing its type.
|
||||
///
|
||||
/// [`SpendDescription`]: crate::transaction::components::SpendDescription
|
||||
fn encode_proof(proof: Self::Proof) -> GrothProofBytes;
|
||||
}
|
||||
|
||||
/// Interface for creating Sapling Output proofs.
|
||||
|
@ -68,6 +73,11 @@ pub trait OutputProver {
|
|||
circuit: sapling::circuit::Output,
|
||||
rng: &mut R,
|
||||
) -> Self::Proof;
|
||||
|
||||
/// Encodes the given Sapling [`OutputDescription`] proof, erasing its type.
|
||||
///
|
||||
/// [`OutputDescription`]: crate::transaction::components::OutputDescription
|
||||
fn encode_proof(proof: Self::Proof) -> GrothProofBytes;
|
||||
}
|
||||
|
||||
/// Interface for creating zero-knowledge proofs for shielded transactions.
|
||||
|
|
|
@ -11,7 +11,7 @@ use zcash_primitives::{
|
|||
value::{CommitmentSum, NoteValue, TrapdoorSum, ValueCommitTrapdoor, ValueCommitment},
|
||||
Diversifier, MerklePath, Note, PaymentAddress, ProofGenerationKey, Rseed,
|
||||
},
|
||||
transaction::components::Amount,
|
||||
transaction::components::{sapling::GrothProofBytes, Amount, GROTH_PROOF_SIZE},
|
||||
};
|
||||
|
||||
use crate::{OutputParameters, SpendParameters};
|
||||
|
@ -64,6 +64,14 @@ impl SpendProver for SpendParameters {
|
|||
fn create_proof<R: RngCore>(&self, circuit: Spend, rng: &mut R) -> Self::Proof {
|
||||
create_random_proof(circuit, &self.0, rng).expect("proving should not fail")
|
||||
}
|
||||
|
||||
fn encode_proof(proof: Self::Proof) -> GrothProofBytes {
|
||||
let mut zkproof = [0u8; GROTH_PROOF_SIZE];
|
||||
proof
|
||||
.write(&mut zkproof[..])
|
||||
.expect("should be able to serialize a proof");
|
||||
zkproof
|
||||
}
|
||||
}
|
||||
|
||||
impl OutputProver for OutputParameters {
|
||||
|
@ -94,6 +102,14 @@ impl OutputProver for OutputParameters {
|
|||
fn create_proof<R: RngCore>(&self, circuit: Output, rng: &mut R) -> Self::Proof {
|
||||
create_random_proof(circuit, &self.0, rng).expect("proving should not fail")
|
||||
}
|
||||
|
||||
fn encode_proof(proof: Self::Proof) -> GrothProofBytes {
|
||||
let mut zkproof = [0u8; GROTH_PROOF_SIZE];
|
||||
proof
|
||||
.write(&mut zkproof[..])
|
||||
.expect("should be able to serialize a proof");
|
||||
zkproof
|
||||
}
|
||||
}
|
||||
|
||||
/// A context object for creating the Sapling components of a Zcash transaction.
|
||||
|
|
Loading…
Reference in New Issue