From aea349921e668af44c28c13ae111087293f729f9 Mon Sep 17 00:00:00 2001 From: John Guibas Date: Tue, 9 Jan 2024 10:08:52 -0800 Subject: [PATCH 1/3] fix: mapreduce build path --- plonky2x/core/src/backend/function/mod.rs | 5 ++- plonky2x/core/src/backend/prover/env.rs | 6 ++- plonky2x/core/src/frontend/uint/uint512.rs | 44 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/plonky2x/core/src/backend/function/mod.rs b/plonky2x/core/src/backend/function/mod.rs index 5e3f4e977..7a97d3024 100644 --- a/plonky2x/core/src/backend/function/mod.rs +++ b/plonky2x/core/src/backend/function/mod.rs @@ -4,7 +4,7 @@ pub mod result; use std::fs::File; use std::io::{BufReader, Write}; -use std::{fs, path}; +use std::{env, fs, path}; use clap::Parser; use log::info; @@ -140,6 +140,9 @@ impl Plonky2xFunction for C { AlgebraicHasher, OuterParameters::Config: Serialize, { + // Setup enviroment variables. + env::set_var("BUILD_DIR", args.build_dir); + // If the request is of type bytes and the wrapper path is not empty, then we need to // start the gnark wrapper process. let gnark_wrapper_process = if let ProofRequest::Bytes(_) = request { diff --git a/plonky2x/core/src/backend/prover/env.rs b/plonky2x/core/src/backend/prover/env.rs index 894937bb8..c290b1fcb 100644 --- a/plonky2x/core/src/backend/prover/env.rs +++ b/plonky2x/core/src/backend/prover/env.rs @@ -32,7 +32,8 @@ impl EnvProver { } else { let gate_serializer = S::gate_registry::(); let generator_serializer = S::generator_registry::(); - let circuit_path = format!("./build/{}.circuit", circuit_id); + let build_dir = env::var("BUILD_DIR").unwrap_or_else(|_| "./build".to_string()); + let circuit_path = format!("{}/{}.circuit", build_dir, circuit_id); let circuit = CircuitBuild::::load(&circuit_path, &gate_serializer, &generator_serializer) .unwrap(); @@ -55,7 +56,8 @@ impl EnvProver { } else { let gate_serializer = S::gate_registry::(); let generator_serializer = S::generator_registry::(); - let circuit_path = format!("./build/{}.circuit", circuit_id); + let build_dir = env::var("BUILD_DIR").unwrap_or_else(|_| "./build".to_string()); + let circuit_path = format!("{}/{}.circuit", build_dir, circuit_id); let circuit = CircuitBuild::::load(&circuit_path, &gate_serializer, &generator_serializer) .unwrap(); diff --git a/plonky2x/core/src/frontend/uint/uint512.rs b/plonky2x/core/src/frontend/uint/uint512.rs index b1bd843ab..0589f7461 100644 --- a/plonky2x/core/src/frontend/uint/uint512.rs +++ b/plonky2x/core/src/frontend/uint/uint512.rs @@ -44,3 +44,47 @@ impl Uint<16> for U512 { make_uint32_n!(U512Variable, U512, 16); make_uint32_n_tests!(U512Variable, U512, 16); + +mod tests2 { + + use ethers::types::U512; + + use super::*; + use crate::backend::circuit::DefaultParameters; + use crate::frontend::uint::Uint; + use crate::prelude::*; + + type L = DefaultParameters; + + #[test] + fn failing_test_mul() { + const D: usize = 2; + + let _ = env_logger::builder().is_test(true).try_init(); + + let a = >::from_u32_limbs([ + 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, + 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, + 1693531657, 1693531657, + ]); + let b = >::from_u32_limbs([ + 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, + 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, + 3656660001, 3656660001, + ]); + + let mut builder = CircuitBuilder::::new(); + + let a = U512Variable::constant(&mut builder, a); + let b = U512Variable::constant(&mut builder, b); + let result = builder.mul(a, b); + + builder.watch(&result, "result"); + + let circuit = builder.build(); + let pw = PartialWitness::new(); + + let proof = circuit.data.prove(pw).unwrap(); + circuit.data.verify(proof).unwrap(); + } +} From 53815eeca2dfa6bc843d899151f3ee73268a9a14 Mon Sep 17 00:00:00 2001 From: John Guibas Date: Tue, 9 Jan 2024 10:09:26 -0800 Subject: [PATCH 2/3] fix: mapreduce build path --- plonky2x/core/src/backend/function/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plonky2x/core/src/backend/function/mod.rs b/plonky2x/core/src/backend/function/mod.rs index 7a97d3024..337a3feab 100644 --- a/plonky2x/core/src/backend/function/mod.rs +++ b/plonky2x/core/src/backend/function/mod.rs @@ -141,7 +141,7 @@ impl Plonky2xFunction for C { OuterParameters::Config: Serialize, { // Setup enviroment variables. - env::set_var("BUILD_DIR", args.build_dir); + env::set_var("BUILD_DIR", args.build_dir.clone()); // If the request is of type bytes and the wrapper path is not empty, then we need to // start the gnark wrapper process. From bbd4cf1fa2b0d3411dc5599f40e4cd8bd9ef5006 Mon Sep 17 00:00:00 2001 From: John Guibas Date: Tue, 9 Jan 2024 10:10:28 -0800 Subject: [PATCH 3/3] remove diff --- plonky2x/core/src/frontend/uint/uint512.rs | 44 ---------------------- 1 file changed, 44 deletions(-) diff --git a/plonky2x/core/src/frontend/uint/uint512.rs b/plonky2x/core/src/frontend/uint/uint512.rs index 0589f7461..b1bd843ab 100644 --- a/plonky2x/core/src/frontend/uint/uint512.rs +++ b/plonky2x/core/src/frontend/uint/uint512.rs @@ -44,47 +44,3 @@ impl Uint<16> for U512 { make_uint32_n!(U512Variable, U512, 16); make_uint32_n_tests!(U512Variable, U512, 16); - -mod tests2 { - - use ethers::types::U512; - - use super::*; - use crate::backend::circuit::DefaultParameters; - use crate::frontend::uint::Uint; - use crate::prelude::*; - - type L = DefaultParameters; - - #[test] - fn failing_test_mul() { - const D: usize = 2; - - let _ = env_logger::builder().is_test(true).try_init(); - - let a = >::from_u32_limbs([ - 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, - 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, 1693531657, - 1693531657, 1693531657, - ]); - let b = >::from_u32_limbs([ - 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, - 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, 3656660001, - 3656660001, 3656660001, - ]); - - let mut builder = CircuitBuilder::::new(); - - let a = U512Variable::constant(&mut builder, a); - let b = U512Variable::constant(&mut builder, b); - let result = builder.mul(a, b); - - builder.watch(&result, "result"); - - let circuit = builder.build(); - let pw = PartialWitness::new(); - - let proof = circuit.data.prove(pw).unwrap(); - circuit.data.verify(proof).unwrap(); - } -}