Skip to content

Commit

Permalink
Ending the diff buses test
Browse files Browse the repository at this point in the history
  • Loading branch information
hecmas committed Dec 19, 2024
1 parent 346405d commit 9147369
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 17 deletions.
34 changes: 33 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ jobs:
run: |
sed -i 's/# *"pil2-components\/test\/std\/connection\/rs"/"pil2-components\/test\/std\/connection\/rs"/' ./Cargo.toml
- name: Modify Cargo.toml std diff_buses
run: |
sed -i 's/# *"pil2-components\/test\/std\/diff_buses\/rs"/"pil2-components\/test\/std\/diff_buses\/rs"/' ./Cargo.toml
- name: Modify Cargo.toml std direct_update
run: |
sed -i 's/# *"pil2-components\/test\/std\/direct_update\/rs"/"pil2-components\/test\/std\/direct_update\/rs"/' ./Cargo.toml
Expand Down Expand Up @@ -368,6 +372,22 @@ jobs:
run: |
cargo run --bin proofman-cli pil-helpers --pilout ./pil2-components/test/std/connection/build/build.pilout --path ./pil2-components/test/std/connection/rs/src -o
- name: Create dir build diff_buses
run: |
mkdir -p ./pil2-components/test/std/diff_buses/build/
- name: Compile PIL diff_buses
run: |
node pil2-compiler/src/pil.js ./pil2-components/test/std/diff_buses/diff_buses.pil -I ./pil2-components/lib/std/pil -o ./pil2-components/test/std/diff_buses/build/build.pilout
- name: Generate setup diff_buses
run: |
node pil2-proofman-js/src/main_setup.js -a ./pil2-components/test/std/diff_buses/build/build.pilout -b ./pil2-components/test/std/diff_buses/build -t pil2-stark/build/bctree
- name: Generate PIL Helpers diff_buses
run: |
cargo run --bin proofman-cli pil-helpers --pilout ./pil2-components/test/std/diff_buses/build/build.pilout --path ./pil2-components/test/std/diff_buses/rs/src -o
- name: Create dir build direct_update
run: |
mkdir -p ./pil2-components/test/std/direct_update/build/
Expand Down Expand Up @@ -455,13 +475,25 @@ jobs:
run: |
node pil2-proofman-js/src/main_verify -k ./pil2-components/test/std/connection/build/provingKey -p ./pil2-components/test/std/connection/build
- name: Verify constraints diff_buses
run: |
cargo run --bin proofman-cli verify-constraints --witness-lib ./target/debug/libdiff_buses.so --proving-key ./pil2-components/test/std/diff_buses/build/provingKey
- name: Generate proof diff_buses
run: |
cargo run --bin proofman-cli prove --witness-lib ./target/debug/libdiff_buses.so --proving-key ./pil2-components/test/std/diff_buses/build/provingKey --output-dir ./pil2-components/test/std/diff_buses/build
- name: Verify proof diff_buses
run: |
node pil2-proofman-js/src/main_verify -k ./pil2-components/test/std/diff_buses/build/provingKey -p ./pil2-components/test/std/diff_buses/build
- name: Verify constraints direct_update
run: |
cargo run --bin proofman-cli verify-constraints --witness-lib ./target/debug/libdirect_update.so --proving-key ./pil2-components/test/std/direct_update/build/provingKey
- name: Generate proof direct_update
run: |
cargo run --bin proofman-cli prove --witness-lib ./target/debug/libdirect_update.so --proving-key ./pil2-components/test/std/direct_update/build/provingKey --output-dir ./pil2-components/test/std/connection/build
cargo run --bin proofman-cli prove --witness-lib ./target/debug/libdirect_update.so --proving-key ./pil2-components/test/std/direct_update/build/provingKey --output-dir ./pil2-components/test/std/direct_update/build
- name: Verify proof direct_update
run: |
Expand Down
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ members = [
"transcript",
"util",
"pil2-components/lib/std/rs",
#"pil2-components/test/std/direct_update/rs",
#"pil2-components/test/std/range_check/rs",
#"pil2-components/test/std/lookup/rs",
#"pil2-components/test/std/connection/rs",
#"pil2-components/test/std/permutation/rs",
#"pil2-components/test/simple/rs",
# "pil2-components/test/std/direct_update/rs",
# "pil2-components/test/std/diff_buses/rs",
# "pil2-components/test/std/range_check/rs",
# "pil2-components/test/std/lookup/rs",
# "pil2-components/test/std/connection/rs",
# "pil2-components/test/std/permutation/rs",
# "pil2-components/test/simple/rs",
# whoever re-enables this, it has to work out of
# the box with `cargo check --workspace` or CI will
# break and dev experience will be bad since repo
Expand Down
32 changes: 25 additions & 7 deletions pil2-components/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ mkdir -p ./pil2-components/test/std/connection/build/ \
--output-dir ./pil2-components/test/std/connection/build/proofs \
&& node ../pil2-proofman-js/src/main_verify -k ./pil2-components/test/std/connection/build/provingKey -p ./pil2-components/test/std/connection/build/proofs

------------------------------------
Diff Buses

mkdir -p ./pil2-components/test/std/diff_buses/build/ \
&& rm -rf pil2-components/test/diff_buses/build/proofs/ \
&& node ../pil2-compiler/src/pil.js ./pil2-components/test/std/diff_buses/diff_buses.pil \
-I ./pil2-components/lib/std/pil \
-o ./pil2-components/test/std/diff_buses/build/diff_buses.pilout \
&& node ../pil2-proofman-js/src/main_setup.js \
-a ./pil2-components/test/std/diff_buses/build/diff_buses.pilout \
-b ./pil2-components/test/std/diff_buses/build \
-t ./pil2-stark/build/bctree \
&& cargo run --bin proofman-cli pil-helpers \
--pilout ./pil2-components/test/std/diff_buses/build/diff_buses.pilout \
--path ./pil2-components/test/std/diff_buses/rs/src -o \
&& cargo build \
&& cargo run --bin proofman-cli verify-constraints \
--witness-lib ./target/debug/libdiff_buses.so \
--proving-key ./pil2-components/test/std/diff_buses/build/provingKey \
&& cargo run --bin proofman-cli prove \
--witness-lib ./target/debug/libdiff_buses.so \
--proving-key ./pil2-components/test/std/diff_buses/build/provingKey \
--output-dir ./pil2-components/test/std/diff_buses/build/proofs \
&& node ../pil2-proofman-js/src/main_verify -k ./pil2-components/test/std/diff_buses/build/provingKey -p ./pil2-components/test/std/diff_buses/build/proofs

------------------------------------
Direct Updates

Expand Down Expand Up @@ -155,9 +180,6 @@ SPECIAL

mkdir -p ./pil2-components/test/std/special/build/ \
&& rm -rf pil2-components/test/special/build/proofs/ \
&& node ../pil2-compiler/src/pil.js ./pil2-components/test/std/special/diff_buses.pil \
-I ./pil2-components/lib/std/pil \
-o ./pil2-components/test/std/special/build/diff_buses.pilout \
&& node ../pil2-compiler/src/pil.js ./pil2-components/test/std/special/expr_optimizations.pil \
-I ./pil2-components/lib/std/pil \
-o ./pil2-components/test/std/special/build/expr_optimizations.pilout \
Expand All @@ -167,10 +189,6 @@ mkdir -p ./pil2-components/test/std/special/build/ \
&& node ../pil2-compiler/src/pil.js ./pil2-components/test/std/special/table.pil \
-I ./pil2-components/lib/std/pil \
-o ./pil2-components/test/std/special/build/table.pilout \
&& node ../pil2-proofman-js/src/main_setup.js \
-a ./pil2-components/test/std/special/build/diff_buses.pilout \
-b ./pil2-components/test/std/special/build \
-t ./pil2-stark/build/bctree \
&& node ../pil2-proofman-js/src/main_setup.js \
-a ./pil2-components/test/std/special/build/expr_optimizations.pilout \
-b ./pil2-components/test/std/special/build \
Expand Down
2 changes: 1 addition & 1 deletion pil2-components/test/std/diff_buses/diff_buses.pil
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ airtemplate BothBuses(const int N = 2**4) {
airgroup Buses {
ProdBus();
SumBus();
// BothBuses();
BothBuses();
}
74 changes: 74 additions & 0 deletions pil2-components/test/std/diff_buses/rs/src/both_buses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use std::sync::Arc;

use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx};

use p3_field::PrimeField;
use rand::{distributions::Standard, prelude::Distribution, Rng};

use crate::{BothBusesTrace, BUSES_AIRGROUP_ID, BOTH_BUSES_AIR_IDS};

pub struct BothBuses<F: PrimeField> {
_phantom: std::marker::PhantomData<F>,
}

impl<F: PrimeField> BothBuses<F>
where
Standard: Distribution<F>,
{
const MY_NAME: &'static str = "BothBuses";

pub fn new(wcm: Arc<WitnessManager<F>>) -> Arc<Self> {
let both_buses = Arc::new(Self { _phantom: std::marker::PhantomData });

wcm.register_component(both_buses.clone(), Some(BUSES_AIRGROUP_ID), Some(BOTH_BUSES_AIR_IDS));

both_buses
}

pub fn execute(&self, pctx: Arc<ProofCtx<F>>, ectx: Arc<ExecutionCtx>, sctx: Arc<SetupCtx>) {
let num_rows = pctx.global_info.airs[BUSES_AIRGROUP_ID][BOTH_BUSES_AIR_IDS[0]].num_rows;
let trace = BothBusesTrace::new(num_rows);

let air_instance =
AirInstance::new(sctx.clone(), BUSES_AIRGROUP_ID, BOTH_BUSES_AIR_IDS[0], None, trace.buffer.unwrap());
let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(BUSES_AIRGROUP_ID, BOTH_BUSES_AIR_IDS[0], 1);
if is_myne {
pctx.air_instance_repo.add_air_instance(air_instance, Some(gid));
}
}
}

impl<F: PrimeField> WitnessComponent<F> for BothBuses<F>
where
Standard: Distribution<F>,
{
fn calculate_witness(
&self,
stage: u32,
air_instance_id: Option<usize>,
pctx: Arc<ProofCtx<F>>,
_ectx: Arc<ExecutionCtx>,
_sctx: Arc<SetupCtx>,
) {
let mut rng = rand::thread_rng();
log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "BothBuses", stage);

if stage == 1 {
let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap();
let air_instance = &mut air_instances_vec[air_instance_id.unwrap()];
let buffer = &mut air_instance.trace;
let num_rows = pctx.pilout.get_air(BUSES_AIRGROUP_ID, BOTH_BUSES_AIR_IDS[0]).num_rows();

let mut trace = BothBusesTrace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap();

for i in 0..num_rows {
trace[i].a = F::from_canonical_u64(rng.gen_range(0..=(1 << 63) - 1));
trace[i].b = trace[i].a;

trace[i].c = F::from_canonical_usize(i);
trace[i].d = trace[i].c;
}
}
}
}
8 changes: 6 additions & 2 deletions pil2-components/test/std/diff_buses/rs/src/diff_buses_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ use p3_field::PrimeField;
use p3_goldilocks::Goldilocks;
use rand::{distributions::Standard, prelude::Distribution};

use crate::{Pilout, ProdBus, SumBus};
use crate::{Pilout, ProdBus, BothBuses, SumBus};

pub struct DiffBusesWitness<F: PrimeField> {
pub wcm: Option<Arc<WitnessManager<F>>>,
pub prod_bus: Option<Arc<ProdBus<F>>>,
pub sum_bus: Option<Arc<SumBus<F>>>,
pub both_buses: Option<Arc<BothBuses<F>>>,
pub std_lib: Option<Arc<Std<F>>>,
}

Expand All @@ -31,7 +32,7 @@ where
Standard: Distribution<F>,
{
pub fn new() -> Self {
DiffBusesWitness { wcm: None, prod_bus: None, sum_bus: None, std_lib: None }
DiffBusesWitness { wcm: None, prod_bus: None, sum_bus: None, both_buses: None, std_lib: None }
}

pub fn initialize(&mut self, pctx: Arc<ProofCtx<F>>, ectx: Arc<ExecutionCtx>, sctx: Arc<SetupCtx>) {
Expand All @@ -40,10 +41,12 @@ where
let std_lib = Std::new(wcm.clone());
let prod_bus = ProdBus::new(wcm.clone());
let sum_bus = SumBus::new(wcm.clone());
let both_buses = BothBuses::new(wcm.clone());

self.wcm = Some(wcm);
self.prod_bus = Some(prod_bus);
self.sum_bus = Some(sum_bus);
self.both_buses = Some(both_buses);
self.std_lib = Some(std_lib);
}
}
Expand All @@ -66,6 +69,7 @@ where
// Execute those components that need to be executed
self.prod_bus.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone());
self.sum_bus.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone());
self.both_buses.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone());
}

fn calculate_witness(&mut self, stage: u32, pctx: Arc<ProofCtx<F>>, ectx: Arc<ExecutionCtx>, sctx: Arc<SetupCtx>) {
Expand Down
2 changes: 2 additions & 0 deletions pil2-components/test/std/diff_buses/rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod prod_bus;
mod sum_bus;
mod both_buses;
mod diff_buses_lib;
mod pil_helpers;

pub use prod_bus::*;
pub use sum_bus::*;
pub use both_buses::*;
pub use diff_buses_lib::*;
pub use pil_helpers::*;

0 comments on commit 9147369

Please sign in to comment.