1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::commitment_scheme::kzg10::{CommitKey, OpeningKey};
use crate::constraint_system::StandardComposer;
use crate::proof_system::widget::VerifierKey;
use crate::proof_system::Proof;
use dusk_bls12_381::Scalar;
use failure::Error;
use merlin::Transcript;
#[allow(missing_debug_implementations)]
pub struct Verifier {
pub verifier_key: Option<VerifierKey>,
pub(crate) cs: StandardComposer,
pub preprocessed_transcript: Transcript,
}
impl Default for Verifier {
fn default() -> Verifier {
Verifier::new(b"plonk")
}
}
impl Verifier {
pub fn new(label: &'static [u8]) -> Verifier {
Verifier {
verifier_key: None,
cs: StandardComposer::new(),
preprocessed_transcript: Transcript::new(label),
}
}
pub fn circuit_size(&self) -> usize {
self.cs.circuit_size()
}
pub fn mut_cs(&mut self) -> &mut StandardComposer {
&mut self.cs
}
pub fn preprocess(&mut self, commit_key: &CommitKey) -> Result<(), Error> {
let vk = self
.cs
.preprocess_verifier(commit_key, &mut self.preprocessed_transcript)?;
self.verifier_key = Some(vk);
Ok(())
}
pub fn key_transcript(&mut self, label: &'static [u8], message: &[u8]) {
self.preprocessed_transcript.append_message(label, message);
}
pub fn verify(
&self,
proof: &Proof,
opening_key: &OpeningKey,
public_inputs: &[Scalar],
) -> Result<(), Error> {
let mut cloned_transcript = self.preprocessed_transcript.clone();
let verifier_key = self.verifier_key.as_ref().unwrap();
proof.verify(
verifier_key,
&mut cloned_transcript,
opening_key,
public_inputs,
)
}
}