Skip to content

Commit

Permalink
better batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
jtguibas committed Sep 20, 2023
1 parent 656b3bc commit ea73b88
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion plonky2x/examples/mapreduce.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ethers::types::U64;
use itertools::Itertools;
use jemallocator::Jemalloc;
use log::debug;
use plonky2::plonk::config::{AlgebraicHasher, GenericConfig};
use plonky2x::backend::circuit::{Circuit, PlonkParameters};
use plonky2x::backend::function::VerifiableFunction;
Expand All @@ -17,7 +18,7 @@ static GLOBAL: Jemalloc = Jemalloc;
const BLOCK_ROOT: &str = "0x4f1dd351f11a8350212b534b3fca619a2a95ad8d9c16129201be4a6d73698adb";

/// The number of balances to fetch.
const NB_BALANCES: usize = 8192;
const NB_BALANCES: usize = 131072;

/// The batch size for fetching balances and computing the local balance roots.
const BATCH_SIZE: usize = 2048;
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Circuit for MapReduceCircuit {
while leafs.len() != 1 {
let mut tmp = Vec::new();
for i in 0..leafs.len() / 2 {
debug!("calling sha256 pair w/ curta");
tmp.push(builder.curta_sha256_pair(leafs[i*2], leafs[i*2+1]));
}
leafs = tmp;
Expand Down
2 changes: 2 additions & 0 deletions plonky2x/src/frontend/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use backtrace::Backtrace;
use ethers::providers::{Http, Middleware, Provider};
use ethers::types::U256;
use itertools::Itertools;
use log::debug;
use plonky2::iop::generator::SimpleGenerator;
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::plonk::circuit_builder::CircuitBuilder as CircuitAPI;
Expand Down Expand Up @@ -114,6 +115,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
/// Build the circuit.
pub fn build(mut self) -> CircuitBuild<L, D> {
if !self.sha256_requests.is_empty() {
debug!("curta constraining sha256");
self.curta_constrain_sha256();
}

Expand Down
3 changes: 3 additions & 0 deletions plonky2x/src/frontend/hash/sha/sha256_curta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use curta::chip::hash::sha::sha256::builder_gadget::{SHA256Builder, SHA256Builde
use curta::chip::hash::sha::sha256::generator::SHA256HintGenerator;
use curta::math::field::Field;
use itertools::Itertools;
use log::debug;
use plonky2::iop::target::Target;

use crate::backend::circuit::PlonkParameters;
Expand Down Expand Up @@ -207,6 +208,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
let mut nb_chunks = 0;
let mut curr_rq = 0;
let mut num_rqs = self.sha256_requests.len();
debug!("num_rqs: {}", num_rqs);

let zero = self.constant::<ByteVariable>(0u8);
let zero_chunk = [zero; 1];
Expand Down Expand Up @@ -253,6 +255,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
(0..nb_chunks / 1024)
.map(|_| self.api.init_sha256())
.collect_vec();
debug!("allocated {} curta sha256 gadgets", gadgets.len());

let mut rq_idx = 0;
for i in 0..gadgets.len() {
Expand Down
2 changes: 1 addition & 1 deletion succinct.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"preset": "plonky2",
"build_command": "rm -rf ./build && mkdir build && rustup override set nightly && RUST_LOG=debug cargo run --release --example mapreduce build && cp ./target/release/examples/mapreduce ./build/mapreduce",
"build_command": "rm -rf ./build && mkdir build && rustup override set nightly && RUSTFLAGS=-Ctarget-cpu=native RUST_LOG=debug cargo run --release --example mapreduce build && cp ./target/release/examples/mapreduce ./build/mapreduce",
"prove_command": "./build/mapreduce prove --input-json input.json"
}

0 comments on commit ea73b88

Please sign in to comment.