-
Notifications
You must be signed in to change notification settings - Fork 5
/
circuit_specific_setup_compiler.rs
105 lines (97 loc) · 3.41 KB
/
circuit_specific_setup_compiler.rs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use crate::compiler::IVLS;
use crate::ivls::data_structures::Commitment;
use crate::{
building_blocks::mt::MT,
gadgets::UInt64,
ivls::{
history::VerifiableHistory,
state::VerifiableState,
transition_function::{VerifiableTransitionFunction, VerifiableTransitionFunctionConfig},
},
ledger_system::transition_function::TransitionFunction,
Error, PhantomData,
};
use ark_pcd::PCD;
use ark_std::rand::{CryptoRng, RngCore};
/// compiler for circuit-specifict setup IVLS
pub struct CircuitSpecificSetupIVLSCompiler<VC: VerifiableTransitionFunctionConfig> {
vc_phantom: PhantomData<VC>,
}
/// public parameters for circuit-specific setup IVLS
pub struct CircuitSpecificSetupIVLSPP<VC: VerifiableTransitionFunctionConfig> {
/// Merkle tree public parameters
pub pp_mt: (
<VC::MTState as MT<
VC::F,
<VC::TF as TransitionFunction<VC::F>>::Addr,
<VC::TF as TransitionFunction<VC::F>>::AddrVar,
>>::PublicParameters,
<VC::MTHistory as MT<VC::F, u64, UInt64<VC::F>>>::PublicParameters,
),
/// digests for empty state and history
pub empty_digest: (
<VC::MTState as MT<
VC::F,
<VC::TF as TransitionFunction<VC::F>>::Addr,
<VC::TF as TransitionFunction<VC::F>>::AddrVar,
>>::Digest,
<VC::MTHistory as MT<VC::F, u64, UInt64<VC::F>>>::Digest,
),
}
impl<VC: VerifiableTransitionFunctionConfig> CircuitSpecificSetupIVLSCompiler<VC> {
/// IVLS.setup (circuit-specific)
pub fn circuit_specific_setup<R: RngCore + CryptoRng>(
rng: &mut R,
) -> Result<CircuitSpecificSetupIVLSPP<VC>, Error> {
let pp_mt = (
<VC::MTState as MT<
VC::F,
<VC::TF as TransitionFunction<VC::F>>::Addr,
<VC::TF as TransitionFunction<VC::F>>::AddrVar,
>>::setup(rng)?,
<VC::MTHistory as MT<VC::F, u64, UInt64<VC::F>>>::setup(rng)?,
);
let empty_tree_state =
VC::MTState::new::<<VC::TF as TransitionFunction<VC::F>>::Data>(&pp_mt.0)?;
let empty_tree_history = VC::MTHistory::new::<Commitment<VC>>(&pp_mt.1)?;
let empty_digest = (
VC::MTState::root(&pp_mt.0, &empty_tree_state)?,
VC::MTHistory::root(&pp_mt.1, &empty_tree_history)?,
);
Ok(CircuitSpecificSetupIVLSPP {
pp_mt,
empty_digest,
})
}
/// IVLS.make_sfh
pub fn make_sfh<R: RngCore + CryptoRng>(
pp: &CircuitSpecificSetupIVLSPP<VC>,
rng: &mut R,
) -> Result<IVLS<VC>, Error> {
let p = VerifiableTransitionFunction::<VC> {
pp_mt: pp.pp_mt.clone(),
empty_digest: pp.empty_digest.clone(),
ipk: None,
ivk: None,
};
let (ipk, ivk) = <VC::I as PCD<VC::F>>::circuit_specific_setup::<
VerifiableTransitionFunction<VC>,
R,
>(&p, rng)?;
Ok(IVLS::<VC> {
vf: VerifiableTransitionFunction::<VC> {
pp_mt: pp.pp_mt.clone(),
empty_digest: pp.empty_digest.clone(),
ipk: Some(ipk),
ivk: Some(ivk.clone()),
},
vs: VerifiableState::<VC> {
pp_mt: pp.pp_mt.clone(),
ivk,
},
vh: VerifiableHistory::<VC> {
pp_mt: pp.pp_mt.clone(),
},
})
}
}