From 689ac7a848b25b55af3866464cd26a586bd1fa76 Mon Sep 17 00:00:00 2001 From: dndll Date: Fri, 9 Feb 2024 11:49:40 +0000 Subject: [PATCH] chore: test parameters --- Makefile | 17 ++++++++++ bin/operator/src/main.rs | 6 ++-- circuits/plonky2x/input.bin | 1 - circuits/plonky2x/src/circuits/sync.rs | 1 - circuits/plonky2x/src/circuits/verify.rs | 14 +++++++- circuits/plonky2x/src/test_utils.rs | 42 ++++++++++++++++++++++-- succinct.json | 4 +-- 7 files changed, 75 insertions(+), 10 deletions(-) delete mode 100644 circuits/plonky2x/input.bin diff --git a/Makefile b/Makefile index 7de0c96..da531fb 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,20 @@ IMAGE_TAG?=0.0.1 docker: DOCKER_BUILDKIT=1 docker build --progress=plain -t $(TAG_PREFIX)/light-client:$(IMAGE_TAG) . + +BUILDCIRCUIT := cargo build --release --bin +MVCIRCUIT := mv -f target/release + +build-sync-circuit: + $(BUILDCIRCUIT) sync --features=sync + $(MVCIRCUIT)/sync build/ + RUST_LOG=debug ./build/sync build +.PHONY: build-sync-circuit + +# TODO: build various parameters of NUM:BATCH, e.g 1024x64 2x1, 128x4, etc +build-verify-circuit: + $(BUILDCIRCUIT) verify --features=verify + $(MVCIRCUIT)/verify build/ + RUST_LOG=debug ./build/verify build +.PHONY: build-verify-circuit + diff --git a/bin/operator/src/main.rs b/bin/operator/src/main.rs index 1caa739..8f73b8b 100644 --- a/bin/operator/src/main.rs +++ b/bin/operator/src/main.rs @@ -17,11 +17,11 @@ fn main() { use near_light_clientx::SyncCircuit; SyncCircuit::::entrypoint(); } else if #[cfg(feature = "verify")] { - const PROOF_AMT: usize = 64; - const PROOF_BATCH_SIZE: usize = 4; + const PROOF_AMT: usize = 2; + const PROOF_BATCH_SIZE: usize = 1; assert!(PROOF_AMT % PROOF_BATCH_SIZE == 0); - assert!(PROOF_AMT / PROOF_BATCH_SIZE.is_power_of_two()); + assert!((PROOF_AMT / PROOF_BATCH_SIZE).is_power_of_two()); use near_light_clientx::VerifyCircuit; VerifyCircuit::::entrypoint(); diff --git a/circuits/plonky2x/input.bin b/circuits/plonky2x/input.bin deleted file mode 100644 index a26284a..0000000 --- a/circuits/plonky2x/input.bin +++ /dev/null @@ -1 +0,0 @@ -0x44cf18d28ab7b9f7f5adb3cf3fd6d8a2a4f93f8fdad01a9e86ae4b5b2b17836fba9c6629085351fbea47cdc2851d8f76c940dcba41702fb91a4b832857734ce8000000000937d838dce68dd6fb22e016c8405dfbfdc90f4a9cef98e5fb3c7afc0e1f46a2b5e11022daf909af5b24b30011f952baccbdab560b1e16bd2d16efabb9f2ee3ffee398fad05d5c913e8db18af4d1fda9f2a18595ac481a324b9f94b02abc18595a39ad365fb163b24a02808b1fe26cd012313376d914a7e58017c722062aba155f9a078117aa90ce2853e1558ec8ea8e1910a48364bfb4faf1085779ad3f4311ff5b7af12c8f20a0ad34a56928328499c4518899bcc03deb1eb9b8247f88c65d6c0cf8cd4b46cf5bce18a0e2 \ No newline at end of file diff --git a/circuits/plonky2x/src/circuits/sync.rs b/circuits/plonky2x/src/circuits/sync.rs index 1d45e80..0df1431 100644 --- a/circuits/plonky2x/src/circuits/sync.rs +++ b/circuits/plonky2x/src/circuits/sync.rs @@ -49,7 +49,6 @@ impl Circuit for SyncCircuit { b.watch(&bps_hash, "calculate_bps_hash"); let synced = b.sync(&head, &bps, &next_block); - b.watch(&synced.new_head, "new_head"); let synced_hash = synced.new_head.hash(b); b.evm_write::(synced_hash); } diff --git a/circuits/plonky2x/src/circuits/verify.rs b/circuits/plonky2x/src/circuits/verify.rs index c715938..d4edd99 100644 --- a/circuits/plonky2x/src/circuits/verify.rs +++ b/circuits/plonky2x/src/circuits/verify.rs @@ -1,7 +1,7 @@ use near_light_client_protocol::prelude::Itertools; pub use plonky2x::{self, backend::circuit::Circuit, prelude::*}; use plonky2x::{ - frontend::hint::simple::hint::Hint, + frontend::{hint::simple::hint::Hint, mapreduce::generator::MapReduceDynamicGenerator}, prelude::plonky2::plonk::config::{AlgebraicHasher, GenericConfig}, }; use serde::{Deserialize, Serialize}; @@ -78,6 +78,18 @@ impl Circuit // We hash in verify registry.register_hint::(); + + let dynamic_id = MapReduceDynamicGenerator::::id(); + + registry.register_simple::, + ProofMapReduceVariable, + Self, + B, + D, + >>(dynamic_id); } } diff --git a/circuits/plonky2x/src/test_utils.rs b/circuits/plonky2x/src/test_utils.rs index 30f30cc..bdb1d30 100644 --- a/circuits/plonky2x/src/test_utils.rs +++ b/circuits/plonky2x/src/test_utils.rs @@ -1,6 +1,8 @@ +use std::fs; pub use std::str::FromStr; pub use near_primitives::hash::CryptoHash; +use plonky2x::backend::function::{BytesRequestData, ProofRequest}; pub use plonky2x::{ backend::circuit::{PublicInput, PublicOutput}, prelude::*, @@ -33,8 +35,44 @@ pub fn builder_suite( let mut inputs = circuit.input(); writer(&mut inputs); - if let PublicInput::Bytes(bytes) = &mut inputs { - std::fs::write("input.bin", hex!(bytes)).unwrap(); + match &inputs { + PublicInput::Bytes(bytes) => { + let req = ProofRequest::::Bytes( + plonky2x::backend::function::ProofRequestBase { + release_id: "todo".to_string(), + parent_id: None, + files: None, + data: BytesRequestData { + input: bytes.clone(), + }, + }, + ); + fs::write( + "../../fixtures/input.bytes", + serde_json::to_string(&req).unwrap(), + ) + .unwrap(); + } + PublicInput::Elements(elements) => { + println!("Writing input.elements.json"); + let req = ProofRequest::::Elements( + plonky2x::backend::function::ProofRequestBase { + release_id: "todo".to_string(), + parent_id: None, + files: None, + data: plonky2x::backend::function::ElementsRequestData { + circuit_id: "todo".to_string(), + input: elements.clone(), + }, + }, + ); + fs::write( + "../../fixtures/input.elements.json", + serde_json::to_string(&req).unwrap(), + ) + .unwrap(); + } + _ => {} } let (proof, output) = circuit.prove(&inputs); diff --git a/succinct.json b/succinct.json index 105efea..15389d1 100644 --- a/succinct.json +++ b/succinct.json @@ -4,7 +4,7 @@ "name": "sync", "framework": "plonky2x", "baseDir": ".", - "buildCommand": "cargo build --release --bin sync --features=sync && mv target/release/sync build/ && RUST_LOG=debug ./build/sync build", + "buildCommand": "make build-sync-circuit", "proveCommand": "RUST_LOG=debug ./build/sync prove input.json", "requiredArtifacts": [ "sync" @@ -14,7 +14,7 @@ "name": "verify", "framework": "plonky2x", "baseDir": ".", - "buildCommand": "cargo build --release --bin verify --features=verify && mv target/release/verify build/ && RUST_LOG=debug ./build/verify build", + "buildCommand": "make build-verify-circuit", "proveCommand": "RUST_LOG=debug ./build/verify prove input.json", "requiredArtifacts": [ "verify"