Adjust default parameters (#406)
- Update formula in `estimate_verif_num_gates` after the update in the recursive verification from https://github.com/0xPARC/pod2/pull/397 - Update the parameters to get better utilization of 2^16 rows - Update metrics report to be more compact
This commit is contained in:
parent
a24bbf7a3b
commit
e1f8a9ad8b
5 changed files with 70 additions and 16 deletions
|
|
@ -1506,7 +1506,7 @@ pub fn calculate_statements_hash_circuit(
|
||||||
statements: &[StatementTarget],
|
statements: &[StatementTarget],
|
||||||
) -> HashOutTarget {
|
) -> HashOutTarget {
|
||||||
assert!(statements.len() <= params.num_public_statements_hash);
|
assert!(statements.len() <= params.num_public_statements_hash);
|
||||||
let measure = measure_gates_begin!(builder, "CalculateId");
|
let measure = measure_gates_begin!(builder, "CalculateStsHash");
|
||||||
let statements_rev_flattened = statements.iter().rev().flat_map(|s| s.flatten());
|
let statements_rev_flattened = statements.iter().rev().flat_map(|s| s.flatten());
|
||||||
let mut none_st = mainpod::Statement::from(Statement::None);
|
let mut none_st = mainpod::Statement::from(Statement::None);
|
||||||
pad_statement(params, &mut none_st);
|
pad_statement(params, &mut none_st);
|
||||||
|
|
@ -1561,6 +1561,7 @@ fn build_custom_predicate_table_circuit(
|
||||||
let mut custom_predicate_table =
|
let mut custom_predicate_table =
|
||||||
Vec::with_capacity(params.max_custom_predicate_batches * params.max_custom_batch_size);
|
Vec::with_capacity(params.max_custom_predicate_batches * params.max_custom_batch_size);
|
||||||
for cpb in custom_predicate_batches {
|
for cpb in custom_predicate_batches {
|
||||||
|
let measure_cpb = measure_gates_begin!(builder, "CustomPredBatch");
|
||||||
let id = cpb.id(builder); // constrain the id
|
let id = cpb.id(builder); // constrain the id
|
||||||
for (index, cp) in cpb.predicates.iter().enumerate() {
|
for (index, cp) in cpb.predicates.iter().enumerate() {
|
||||||
let statements = cp
|
let statements = cp
|
||||||
|
|
@ -1582,6 +1583,7 @@ fn build_custom_predicate_table_circuit(
|
||||||
let in_query_hash = entry.hash(builder);
|
let in_query_hash = entry.hash(builder);
|
||||||
custom_predicate_table.push(in_query_hash);
|
custom_predicate_table.push(in_query_hash);
|
||||||
}
|
}
|
||||||
|
measure_gates_end!(builder, measure_cpb);
|
||||||
}
|
}
|
||||||
measure_gates_end!(builder, measure);
|
measure_gates_end!(builder, measure);
|
||||||
Ok(custom_predicate_table)
|
Ok(custom_predicate_table)
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,23 @@ impl Metrics {
|
||||||
pub fn print(&self) {
|
pub fn print(&self) {
|
||||||
println!("Gate count:");
|
println!("Gate count:");
|
||||||
let mut count = HashMap::new();
|
let mut count = HashMap::new();
|
||||||
|
let mut list = Vec::new();
|
||||||
for (name, num_gates) in &self.gates {
|
for (name, num_gates) in &self.gates {
|
||||||
let n = count.entry(name).or_insert(0);
|
let (n, gates) = count.entry(name).or_insert((0, 0));
|
||||||
*n += 1;
|
if *n == 0 {
|
||||||
println!("- {} [{}]: {}", name, *n, num_gates);
|
list.push(name);
|
||||||
}
|
}
|
||||||
|
*n += 1;
|
||||||
|
*gates += num_gates;
|
||||||
|
}
|
||||||
|
for name in list.iter().rev() {
|
||||||
|
let (n, total_gates) = count.get(name).expect("key inserted in previous loop");
|
||||||
|
let avg_gates: f64 = (*total_gates as f64) / (*n as f64);
|
||||||
|
println!("- {}: {} x {:.01} = {}", name, n, avg_gates, total_gates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn reset(&mut self) {
|
||||||
|
*self = Self::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,6 +94,15 @@ pub mod measure_macros {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! measure_gates_reset {
|
||||||
|
() => {{
|
||||||
|
use $crate::backends::plonky2::circuits::metrics::METRICS;
|
||||||
|
let mut metrics = METRICS.lock().unwrap();
|
||||||
|
metrics.reset();
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! measure_gates_print {
|
macro_rules! measure_gates_print {
|
||||||
() => {{
|
() => {{
|
||||||
|
|
@ -108,6 +129,11 @@ pub mod measure_macros {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! measure_gates_reset {
|
||||||
|
() => {};
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! measure_gates_print {
|
macro_rules! measure_gates_print {
|
||||||
() => {{
|
() => {{
|
||||||
|
|
|
||||||
|
|
@ -384,7 +384,7 @@ pub(crate) fn layout_statements(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public statements
|
// Public statements
|
||||||
assert!(inputs.public_statements.len() < params.max_public_statements);
|
assert!(inputs.public_statements.len() <= params.max_public_statements);
|
||||||
for i in 0..params.max_public_statements {
|
for i in 0..params.max_public_statements {
|
||||||
let mut st = inputs
|
let mut st = inputs
|
||||||
.public_statements
|
.public_statements
|
||||||
|
|
@ -859,6 +859,25 @@ pub mod tests {
|
||||||
Ok(pod.verify()?)
|
Ok(pod.verify()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `RUST_LOG=pod2::backends=debug cargo test --release --no-default-features --features=backend_plonky2,mem_cache,zk,metrics test_measure_main_pod -- --nocapture --ignored`
|
||||||
|
#[ignore]
|
||||||
|
#[test]
|
||||||
|
fn test_measure_main_pod() -> frontend::Result<()> {
|
||||||
|
env_logger::init();
|
||||||
|
let params = Params::default();
|
||||||
|
println!("{:#?}", params);
|
||||||
|
let vd_set = VDSet::new(params.max_depth_mt_vds, &[]).unwrap();
|
||||||
|
|
||||||
|
// Calculate rec common first to avoid duplicate metrics in `pod_builder.prove`
|
||||||
|
let _rec_common_circuit_data = cache_get_standard_rec_main_pod_common_circuit_data();
|
||||||
|
let pod_builder = MainPodBuilder::new(¶ms, &vd_set);
|
||||||
|
let prover = Prover {};
|
||||||
|
crate::measure_gates_reset!();
|
||||||
|
let _pod = pod_builder.prove(&prover)?;
|
||||||
|
crate::measure_gates_print!();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_main_tickets() -> frontend::Result<()> {
|
fn test_main_tickets() -> frontend::Result<()> {
|
||||||
let params = Params::default();
|
let params = Params::default();
|
||||||
|
|
|
||||||
|
|
@ -435,13 +435,13 @@ fn estimate_verif_num_gates(degree_bits: usize) -> usize {
|
||||||
{
|
{
|
||||||
// Formula obtained via linear regression using
|
// Formula obtained via linear regression using
|
||||||
// `test_measure_zk_recursion` results with `standard_recursion_zk_config`.
|
// `test_measure_zk_recursion` results with `standard_recursion_zk_config`.
|
||||||
num_gates = 244 * degree_bits + 1127;
|
num_gates = 243 * degree_bits + 1522;
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "zk"))]
|
#[cfg(not(feature = "zk"))]
|
||||||
{
|
{
|
||||||
// Formula obtained via linear regression using `test_measure_recursion`
|
// Formula obtained via linear regression using `test_measure_recursion`
|
||||||
// results with `standard_recursion_config`.
|
// results with `standard_recursion_config`.
|
||||||
num_gates = 236 * degree_bits + 1171;
|
num_gates = 236 * degree_bits + 1580;
|
||||||
}
|
}
|
||||||
// Add 2% for error because the results are not a clean line
|
// Add 2% for error because the results are not a clean line
|
||||||
num_gates * 102 / 100
|
num_gates * 102 / 100
|
||||||
|
|
@ -523,6 +523,11 @@ pub fn common_data_for_recursion<I: InnerCircuit>(
|
||||||
}
|
}
|
||||||
|
|
||||||
if total_num_gates < (1 << degree_bits) {
|
if total_num_gates < (1 << degree_bits) {
|
||||||
|
log::debug!(
|
||||||
|
"degree_bits = {}, free_gates = {}",
|
||||||
|
degree_bits,
|
||||||
|
(1 << degree_bits) - total_num_gates
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
degree_bits = log2_ceil(total_num_gates);
|
degree_bits = log2_ceil(total_num_gates);
|
||||||
|
|
@ -956,6 +961,7 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `cargo test --release --no-default-features --features=backend_plonky2,mem_cache,zk,metrics test_measure_recursion -- --nocapture --ignored`
|
||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_measure_recursion() {
|
fn test_measure_recursion() {
|
||||||
|
|
@ -1005,6 +1011,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `cargo test --release --no-default-features --features=backend_plonky2,mem_cache,zk,metrics test_measure_zk_recursion -- --nocapture --ignored`
|
||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_measure_zk_recursion() {
|
fn test_measure_zk_recursion() {
|
||||||
|
|
|
||||||
|
|
@ -778,23 +778,23 @@ impl Default for Params {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
max_input_pods: 2,
|
max_input_pods: 2,
|
||||||
max_input_pods_public_statements: 10,
|
max_input_pods_public_statements: 8,
|
||||||
max_statements: 40,
|
max_statements: 48,
|
||||||
max_public_statements: 10,
|
max_public_statements: 8,
|
||||||
num_public_statements_hash: 16,
|
num_public_statements_hash: 16,
|
||||||
max_statement_args: 5,
|
max_statement_args: 5,
|
||||||
max_operation_args: 5,
|
max_operation_args: 5,
|
||||||
max_custom_predicate_batches: 2,
|
max_custom_predicate_batches: 4,
|
||||||
max_custom_predicate_verifications: 5,
|
max_custom_predicate_verifications: 8,
|
||||||
max_custom_predicate_arity: 5,
|
max_custom_predicate_arity: 5,
|
||||||
max_custom_predicate_wildcards: 10,
|
max_custom_predicate_wildcards: 8,
|
||||||
max_custom_batch_size: 5, // TODO: Move down to 4?
|
max_custom_batch_size: 4,
|
||||||
max_merkle_proofs_containers: 16,
|
max_merkle_proofs_containers: 20,
|
||||||
max_merkle_tree_state_transition_proofs_containers: 5,
|
max_merkle_tree_state_transition_proofs_containers: 6,
|
||||||
max_depth_mt_containers: 32,
|
max_depth_mt_containers: 32,
|
||||||
max_depth_mt_vds: 6, // up to 64 (2^6) different pod circuits
|
max_depth_mt_vds: 6, // up to 64 (2^6) different pod circuits
|
||||||
max_public_key_of: 2,
|
max_public_key_of: 2,
|
||||||
max_signed_by: 3,
|
max_signed_by: 4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue