This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prover_state.rs
97 lines (85 loc) · 3.29 KB
/
prover_state.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
//! This module defines the `ProverState`, that contains all pre-processed
//! circuits necessary to handle arbitrary transaction proving and proof
//! aggregation to generate succinct block proofs attesting validity of an
//! entire EVM-based chain.
use std::ops::Range;
use log::info;
use paste::paste;
use plonky2_evm::{all_stark::AllStark, config::StarkConfig};
use crate::types::AllRecursiveCircuits;
/// Plonky2 proving state. Note that this is generally going to be massive in
/// terms of memory and has a long spin-up time,
pub struct ProverState {
/// The set of pre-processed circuits to recursively prove transactions.
pub state: AllRecursiveCircuits,
}
/// Builder for the prover state.
#[derive(Debug)]
pub struct ProverStateBuilder {
arithmetic_circuit_size: Range<usize>,
byte_packing_circuit_size: Range<usize>,
cpu_circuit_size: Range<usize>,
keccak_circuit_size: Range<usize>,
keccak_sponge_circuit_size: Range<usize>,
logic_circuit_size: Range<usize>,
memory_circuit_size: Range<usize>,
}
impl Default for ProverStateBuilder {
fn default() -> Self {
// These ranges are somewhat arbitrary, but should be enough for testing
// purposes against most transactions.
// Some heavy contract deployments may require bumping these ranges though.
Self {
arithmetic_circuit_size: 16..20,
byte_packing_circuit_size: 10..20,
cpu_circuit_size: 12..22,
keccak_circuit_size: 14..17,
keccak_sponge_circuit_size: 9..14,
logic_circuit_size: 12..16,
memory_circuit_size: 17..25,
}
}
}
macro_rules! define_set_circuit_size_method {
($name:ident) => {
paste! {
/// Specifies a range of degrees to be supported for this STARK
/// table's associated recursive circuits.
pub fn [<set_ $name _circuit_size>](mut self, size: Range<usize>) -> Self {
self.[<$name _circuit_size>] = size;
self
}
}
};
}
impl ProverStateBuilder {
define_set_circuit_size_method!(arithmetic);
define_set_circuit_size_method!(byte_packing);
define_set_circuit_size_method!(cpu);
define_set_circuit_size_method!(keccak);
define_set_circuit_size_method!(keccak_sponge);
define_set_circuit_size_method!(logic);
define_set_circuit_size_method!(memory);
// TODO: Consider adding async version?
/// Instantiate the prover state from the builder. Note that this is a very
/// expensive call!
pub fn build(self) -> ProverState {
info!("Initializing Plonky2 aggregation prover state (This may take a while)...");
// ... Yeah I don't understand the mysterious ranges either :)
let state = AllRecursiveCircuits::new(
&AllStark::default(),
&[
self.arithmetic_circuit_size,
self.byte_packing_circuit_size,
self.cpu_circuit_size,
self.keccak_circuit_size,
self.keccak_sponge_circuit_size,
self.logic_circuit_size,
self.memory_circuit_size,
],
&StarkConfig::standard_fast_config(),
);
info!("Finished initializing Plonky2 aggregation prover state!");
ProverState { state }
}
}