Skip to content

Commit

Permalink
Updating zisk with latest proofman changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Oct 23, 2024
1 parent b89ec09 commit bc37009
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 41 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion book/getting_started/quickstart_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Run this whenever the `.pilout` file changes:
Run this whenever the `.pilout` file changes:

```bash
node --max-old-space-size=65536 ../pil2-proofman-js/src/main_setup.js -a pil/zisk.pilout -b build -t ../pil2-stark/build/bctree
node --max-old-space-size=65536 ../pil2-proofman-js/src/main_setup.js -a pil/zisk.pilout -b build -t ../pil2-proofman/pil2-stark/build/bctree
```

### Compile Witness Computation library (`libzisk_witness.so`)
Expand Down
5 changes: 4 additions & 1 deletion state-machines/arith/src/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ pub struct ArithSM {
arith32_sm: Arc<Arith32SM>,
arith64_sm: Arc<Arith64SM>,
arith3264_sm: Arc<Arith3264SM>,

sctx: Arc<SetupCtx>,
}

impl ArithSM {
pub fn new<F>(wcm: Arc<WitnessManager<F>>) -> Arc<Self> {
pub fn new<F>(wcm: Arc<WitnessManager<F>>, sctx: Arc<SetupCtx>) -> Arc<Self> {
let arith32_sm = Arith32SM::new(wcm.clone());
let arith64_sm = Arith64SM::new(wcm.clone());
let arith3264_sm = Arith3264SM::new(wcm.clone());
Expand All @@ -45,6 +47,7 @@ impl ArithSM {
arith32_sm,
arith64_sm,
arith3264_sm,
sctx,
};
let arith_sm = Arc::new(arith_sm);

Expand Down
11 changes: 9 additions & 2 deletions state-machines/binary/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{BinaryBasicSM, BinaryBasicTableSM, BinaryExtensionSM, BinaryExtensio
use p3_field::PrimeField;
use pil_std_lib::Std;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::SetupCtx;
use rayon::Scope;
use sm_common::{OpResult, Provable, ThreadController};
use zisk_core::ZiskRequiredOperation;
Expand All @@ -33,27 +34,32 @@ pub struct BinarySM<F: PrimeField> {
// Secondary State machines
binary_basic_sm: Arc<BinaryBasicSM<F>>,
binary_extension_sm: Arc<BinaryExtensionSM<F>>,

sctx: Arc<SetupCtx>,
}

impl<F: PrimeField> BinarySM<F> {
pub fn new(wcm: Arc<WitnessManager<F>>, std: Arc<Std<F>>) -> Arc<Self> {
pub fn new(wcm: Arc<WitnessManager<F>>, std: Arc<Std<F>>, sctx: Arc<SetupCtx>) -> Arc<Self> {
let binary_basic_table_sm =
BinaryBasicTableSM::new(wcm.clone(), BINARY_TABLE_AIRGROUP_ID, BINARY_TABLE_AIR_IDS);
BinaryBasicTableSM::new(wcm.clone(), sctx.clone(), BINARY_TABLE_AIRGROUP_ID, BINARY_TABLE_AIR_IDS);
let binary_basic_sm = BinaryBasicSM::new(
wcm.clone(),
sctx.clone(),
binary_basic_table_sm,
BINARY_AIRGROUP_ID,
BINARY_AIR_IDS,
);

let binary_extension_table_sm = BinaryExtensionTableSM::new(
wcm.clone(),
sctx.clone(),
BINARY_EXTENSION_TABLE_AIRGROUP_ID,
BINARY_EXTENSION_TABLE_AIR_IDS,
);
let binary_extension_sm = BinaryExtensionSM::new(
wcm.clone(),
std,
sctx.clone(),
binary_extension_table_sm,
BINARY_EXTENSION_AIRGROUP_ID,
BINARY_EXTENSION_AIR_IDS,
Expand All @@ -66,6 +72,7 @@ impl<F: PrimeField> BinarySM<F> {
inputs_extension: Mutex::new(Vec::new()),
binary_basic_sm,
binary_extension_sm,
sctx,
};
let binary_sm = Arc::new(binary_sm);

Expand Down
11 changes: 9 additions & 2 deletions state-machines/binary/src/binary_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::{
use log::info;
use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::AirInstance;
use proofman_common::{AirInstance, SetupCtx};
use proofman_util::{timer_start_trace, timer_stop_and_log_trace};
use rayon::Scope;
use sm_common::{create_prover_buffer, OpResult, Provable, ThreadController};
Expand All @@ -30,6 +30,8 @@ pub struct BinaryBasicSM<F> {

// Secondary State machines
binary_basic_table_sm: Arc<BinaryBasicTableSM<F>>,

sctx: Arc<SetupCtx>,
}

#[derive(Debug)]
Expand All @@ -42,12 +44,14 @@ impl<F: Field> BinaryBasicSM<F> {

pub fn new(
wcm: Arc<WitnessManager<F>>,
sctx: Arc<SetupCtx>,
binary_basic_table_sm: Arc<BinaryBasicTableSM<F>>,
airgroup_id: usize,
air_ids: &[usize],
) -> Arc<Self> {
let binary_basic = Self {
wcm: wcm.clone(),
sctx,
registered_predecessors: AtomicU32::new(0),
threads_controller: Arc::new(ThreadController::new()),
inputs: Mutex::new(Vec::new()),
Expand Down Expand Up @@ -736,7 +740,7 @@ impl<F: Field> BinaryBasicSM<F> {
}
}

impl<F: Send + Sync> WitnessComponent<F> for BinaryBasicSM<F> {}
impl<F: Field + Send + Sync> WitnessComponent<F> for BinaryBasicSM<F> {}

impl<F: Field> Provable<ZiskRequiredOperation, OpResult> for BinaryBasicSM<F> {
fn prove(&self, operations: &[ZiskRequiredOperation], drain: bool, scope: &Scope) {
Expand All @@ -755,6 +759,8 @@ impl<F: Field> Provable<ZiskRequiredOperation, OpResult> for BinaryBasicSM<F> {
self.threads_controller.add_working_thread();
let thread_controller = self.threads_controller.clone();

let sctx = self.sctx.clone();

scope.spawn(move |scope| {
let (mut prover_buffer, offset) = create_prover_buffer(
wcm.get_ectx(),
Expand All @@ -773,6 +779,7 @@ impl<F: Field> Provable<ZiskRequiredOperation, OpResult> for BinaryBasicSM<F> {
);

let air_instance = AirInstance::new(

Check failure on line 781 in state-machines/binary/src/binary_basic.rs

View workflow job for this annotation

GitHub Actions / Test on x86_64

this function takes 4 arguments but 5 arguments were supplied
sctx,
BINARY_AIRGROUP_ID,
BINARY_AIR_IDS[0],
None,
Expand Down
7 changes: 5 additions & 2 deletions state-machines/binary/src/binary_basic_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::{
use log::info;
use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::AirInstance;
use proofman_common::{AirInstance, SetupCtx};
use rayon::{prelude::*, Scope};
use sm_common::create_prover_buffer;
use zisk_core::{zisk_ops::ZiskOp, P2_16, P2_17, P2_18, P2_19, P2_8};
Expand Down Expand Up @@ -34,6 +34,7 @@ pub enum BinaryBasicTableOp {

pub struct BinaryBasicTableSM<F> {
wcm: Arc<WitnessManager<F>>,
sctx: Arc<SetupCtx>,

// Count of registered predecessors
registered_predecessors: AtomicU32,
Expand All @@ -51,11 +52,12 @@ pub enum BasicTableSMErr {
impl<F: Field> BinaryBasicTableSM<F> {
const MY_NAME: &'static str = "BinaryT ";

pub fn new(wcm: Arc<WitnessManager<F>>, airgroup_id: usize, air_ids: &[usize]) -> Arc<Self> {
pub fn new(wcm: Arc<WitnessManager<F>>, sctx: Arc<SetupCtx>, airgroup_id: usize, air_ids: &[usize]) -> Arc<Self> {
let air = wcm.get_pctx().pilout.get_air(BINARY_TABLE_AIRGROUP_ID, BINARY_TABLE_AIR_IDS[0]);

let binary_basic_table = Self {
wcm: wcm.clone(),
sctx,
registered_predecessors: AtomicU32::new(0),
num_rows: air.num_rows(),
multiplicity: Mutex::new(vec![0; air.num_rows()]),
Expand Down Expand Up @@ -94,6 +96,7 @@ impl<F: Field> BinaryBasicTableSM<F> {
);

let air_instance = AirInstance::new(

Check failure on line 98 in state-machines/binary/src/binary_basic_table.rs

View workflow job for this annotation

GitHub Actions / Test on x86_64

this function takes 4 arguments but 5 arguments were supplied
self.sctx.clone(),
BINARY_TABLE_AIRGROUP_ID,
BINARY_TABLE_AIR_IDS[0],
None,
Expand Down
10 changes: 9 additions & 1 deletion state-machines/binary/src/binary_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use num_bigint::BigInt;
use p3_field::PrimeField;
use pil_std_lib::Std;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::AirInstance;
use proofman_common::{AirInstance, SetupCtx};
use proofman_util::{timer_start_debug, timer_stop_and_log_debug};
use rayon::Scope;
use sm_common::{create_prover_buffer, OpResult, Provable, ThreadController};
Expand All @@ -39,6 +39,9 @@ pub struct BinaryExtensionSM<F: PrimeField> {
// STD
std: Arc<Std<F>>,

// SetupCtx
sctx: Arc<SetupCtx>,

// Count of registered predecessors
registered_predecessors: AtomicU32,

Expand All @@ -63,13 +66,15 @@ impl<F: PrimeField> BinaryExtensionSM<F> {
pub fn new(
wcm: Arc<WitnessManager<F>>,
std: Arc<Std<F>>,
sctx: Arc<SetupCtx>,
binary_extension_table_sm: Arc<BinaryExtensionTableSM<F>>,
airgroup_id: usize,
air_ids: &[usize],
) -> Arc<Self> {
let binary_extension_sm = Self {
wcm: wcm.clone(),
std: std.clone(),
sctx: sctx.clone(),
registered_predecessors: AtomicU32::new(0),
threads_controller: Arc::new(ThreadController::new()),
inputs: Mutex::new(Vec::new()),
Expand Down Expand Up @@ -495,6 +500,8 @@ impl<F: PrimeField> Provable<ZiskRequiredOperation, OpResult> for BinaryExtensio

let std = self.std.clone();

let sctx = self.sctx.clone();

scope.spawn(move |scope| {
let (mut prover_buffer, offset) = create_prover_buffer(
wcm.get_ectx(),
Expand All @@ -514,6 +521,7 @@ impl<F: PrimeField> Provable<ZiskRequiredOperation, OpResult> for BinaryExtensio
);

let air_instance = AirInstance::new(

Check failure on line 523 in state-machines/binary/src/binary_extension.rs

View workflow job for this annotation

GitHub Actions / Test on x86_64

this function takes 4 arguments but 5 arguments were supplied
sctx,
BINARY_EXTENSION_AIRGROUP_ID,
BINARY_EXTENSION_AIR_IDS[0],
None,
Expand Down
Loading

0 comments on commit bc37009

Please sign in to comment.