Skip to content

Commit

Permalink
chore: test parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed Feb 9, 2024
1 parent c62c5bd commit 94a4442
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 10 deletions.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 3 additions & 3 deletions bin/operator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ fn main() {
use near_light_clientx::SyncCircuit;
SyncCircuit::<NETWORK>::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::<PROOF_AMT, PROOF_BATCH_SIZE, NETWORK>::entrypoint();
Expand Down
1 change: 0 additions & 1 deletion circuits/plonky2x/input.bin

This file was deleted.

2 changes: 1 addition & 1 deletion circuits/plonky2x/src/circuits/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl<const NETWORK: usize> Circuit for SyncCircuit<NETWORK> {
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::<CryptoHashVariable>(synced_hash);
}
Expand All @@ -60,6 +59,7 @@ impl<const NETWORK: usize> Circuit for SyncCircuit<NETWORK> {
plonky2::plonk::config::AlgebraicHasher<L::Field>,
{
registry.register_async_hint::<FetchNextHeaderInputs>();
registry.register_async_hint::<FetchHeaderInputs>();
registry.register_hint::<EncodeInner>();
registry.register_hint::<BuildEndorsement>();
registry.register_hint::<HashBpsInputs>();
Expand Down
14 changes: 13 additions & 1 deletion circuits/plonky2x/src/circuits/verify.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -78,6 +78,18 @@ impl<const N: usize, const B: usize, const NETWORK: usize> Circuit

// We hash in verify
registry.register_hint::<EncodeInner>();

let dynamic_id = MapReduceDynamicGenerator::<L, (), (), (), Self, 1, D>::id();

registry.register_simple::<MapReduceDynamicGenerator<
L,
(),
ArrayVariable<ProofInputVariable, N>,
ProofMapReduceVariable<N>,
Self,
B,
D,
>>(dynamic_id);
}
}

Expand Down
42 changes: 40 additions & 2 deletions circuits/plonky2x/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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::*,
Expand Down Expand Up @@ -33,8 +35,44 @@ pub fn builder_suite<F, WriteInputs, Assertions>(
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::<DefaultParameters, 2>::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::<DefaultParameters, 2>::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);
Expand Down
4 changes: 2 additions & 2 deletions succinct.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 94a4442

Please sign in to comment.