Skip to content

Commit

Permalink
Main working (#77)
Browse files Browse the repository at this point in the history
* Simple proof working
* Fixing constraints flag. Main is passing with 20 instances

Co-authored-by: RogerTaule <[email protected]>
  • Loading branch information
xavi-pinsach and RogerTaule authored Sep 11, 2024
1 parent 367e45c commit f0d8474
Show file tree
Hide file tree
Showing 37 changed files with 446 additions and 388 deletions.
199 changes: 98 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ opt-level = 3

[workspace.dependencies]
proofman-common = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch ="develop" }
proofman-setup = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch ="develop" }
proofman-hints = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch ="develop" }
proofman-macros = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch ="develop" }
proofman-util = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch ="develop" }
proofman = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch ="develop" }
#Local development
# proofman-common = { path = "../pil2-proofman/common" }
# proofman-setup = { path = "../pil2-proofman/setup" }
# proofman-hints = { path = "../pil2-proofman/hints" }
# proofman-macros = { path = "../pil2-proofman/macros" }
# proofman-util = { path = "../pil2-proofman/util" }
# proofman = { path = "../pil2-proofman/proofman" }

Expand Down
2 changes: 2 additions & 0 deletions core/src/zisk_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub enum ZiskOperationType {
Keccak,
}

/// ZisK instruction definition
///
/// ZisK instruction defined as a binary operation with 2 results: op(a, b) -> (c, flag)
/// a and b are loaded from the respective sources specified in the instruction
/// c is stored according to the destination specified in the instruction
Expand Down
5 changes: 3 additions & 2 deletions emulator/src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ impl<'a> Emu<'a> {
trace_step: &EmuTraceStep,
emu_slice: &mut EmuSlice<F>,
) {
let previous_pc = self.ctx.inst_ctx.pc;
let last_c = self.ctx.inst_ctx.c;
let instruction = self.rom.get_instruction(self.ctx.inst_ctx.pc);
self.source_a_slice(instruction, trace_step.a, &mut emu_slice.required);
Expand Down Expand Up @@ -612,7 +613,7 @@ impl<'a> Emu<'a> {
F::from_canonical_u64((last_c >> 32) & 0xFFFFFFFF),
],
flag: F::from_bool(self.ctx.inst_ctx.flag),
pc: F::from_canonical_u64(self.ctx.inst_ctx.pc),
pc: F::from_canonical_u64(previous_pc),
a_src_imm: F::from_bool(instruction.a_src == SRC_IMM),
a_src_mem: F::from_bool(instruction.a_src == SRC_MEM),
a_offset_imm0: F::from_canonical_u64(instruction.a_offset_imm0),
Expand Down Expand Up @@ -648,7 +649,7 @@ impl<'a> Emu<'a> {
jmp_offset1: F::from_canonical_u64(instruction.jmp_offset1 as u64),
jmp_offset2: F::from_canonical_u64(instruction.jmp_offset2 as u64),
main_segment: F::from_canonical_u64(0),
main_first_segment: F::from_bool(true),
main_first_segment: F::from_bool(false),
main_last_segment: F::from_bool(false),
end: F::from_bool(self.ctx.inst_ctx.end),
m32: F::from_bool(instruction.m32),
Expand Down
1 change: 1 addition & 0 deletions pil/fork_0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ edition = "2021"

[dependencies]
proofman-common = { workspace = true }
proofman-macros = { workspace = true }
proofman = { workspace = true }
25 changes: 13 additions & 12 deletions pil/fork_0/pil/zisk.pil
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
require "constants.pil"
require "std_permutation.pil"
require "main/pil/main.pil"
require "binary/pil/binary.pil"
require "binary/pil/binary_table.pil"
require "binary/pil/binary_extension.pil"
require "binary/pil/binary_extension_table.pil"
// require "std_permutation.pil"
require "../../../state-machines/main/pil/main.pil"
// require "binary/pil/binary.pil"
// require "binary/pil/binary_table.pil"
// require "binary/pil/binary_extension.pil"
// require "binary/pil/binary_extension_table.pil"

const int OPERATION_BUS_ID = 5000;
airgroup Main {
Main(N: 2**21, RC: 2, operation_bus_id: OPERATION_BUS_ID);
}

airgroup Binary {
Binary(N: 2**21, operation_bus_id: OPERATION_BUS_ID);
}
// airgroup Binary {
// Binary(N: 2**21, operation_bus_id: OPERATION_BUS_ID);
// }

/*
airgroup BinaryTable {
BinaryTable(N: 2**21);
}
*/

airgroup BinaryExtension {
BinaryExtension(N: 2**21, operation_bus_id: OPERATION_BUS_ID);
}
// airgroup BinaryExtension {
// BinaryExtension(N: 2**21, operation_bus_id: OPERATION_BUS_ID);
// }

/*
airgroup BinaryExtensionTable {
BinaryExtensionTable(N: 2**21);
Expand Down
Binary file modified pil/fork_0/pil/zisk.pilout
Binary file not shown.
18 changes: 1 addition & 17 deletions pil/fork_0/src/pil_helpers/pilout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,20 @@ pub const PILOUT_HASH: &[u8] = b"Zisk-hash";

pub const MAIN_SUBPROOF_ID: &[usize] = &[0];

pub const BINARY_SUBPROOF_ID: &[usize] = &[1];

pub const BINARY_EXTENSION_SUBPROOF_ID: &[usize] = &[2];

//AIR CONSTANTS

pub const MAIN_AIR_IDS: &[usize] = &[0];

pub const BINARY_AIR_IDS: &[usize] = &[0];

pub const BINARY_EXTENSION_AIR_IDS: &[usize] = &[0];

pub struct Pilout;

impl Pilout {
pub fn pilout() -> WitnessPilout {
let mut pilout = WitnessPilout::new("Zisk", 2, PILOUT_HASH.to_vec());
let mut pilout = WitnessPilout::new("Zisk", 1, PILOUT_HASH.to_vec());

let air_group = pilout.add_air_group(Some("Main"));

air_group.add_air(Some("Main"), 2097152);

let air_group = pilout.add_air_group(Some("Binary"));

air_group.add_air(Some("Binary"), 2097152);

let air_group = pilout.add_air_group(Some("BinaryExtension"));

air_group.add_air(Some("BinaryExtension"), 2097152);

pilout
}
}
3 changes: 2 additions & 1 deletion pil/fork_0/src/pil_helpers/traces.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// WARNING: This file has been autogenerated from the PILOUT file.
// Manual modifications are not recommended and may be overwritten.
use proofman_common::trace;
use proofman_common as common;
pub use proofman_macros::trace;

trace!(Main0Row, Main0Trace<F> {
main_first_segment: F, main_last_segment: F, main_segment: F, a: [F; 2], b: [F; 2], c: [F; 2], last_c: [F; 2], flag: F, pc: F, a_src_imm: F, a_src_mem: F, a_offset_imm0: F, sp: F, a_src_sp: F, a_use_sp_imm1: F, a_src_step: F, b_src_imm: F, b_src_mem: F, b_offset_imm0: F, b_use_sp_imm1: F, b_src_ind: F, ind_width: F, is_external_op: F, op: F, store_ra: F, store_mem: F, store_ind: F, store_offset: F, set_pc: F, store_use_sp: F, set_sp: F, inc_sp: F, jmp_offset1: F, jmp_offset2: F, end: F, m32: F,
Expand Down
2 changes: 2 additions & 0 deletions riscv/src/riscv_inst.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// RISC-V instruction definition
///
/// Contains RISCV instruction data, split by functionality
/// RISC-V comprises of a base user-level 32-bit integer instruction set. Called RV32I, it includes
/// 47 instructions, which can be grouped into six types: R-type: register-register
Expand Down
2 changes: 1 addition & 1 deletion state-machines/arith/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ zisk-core = { path = "../../core" }
sm-common = { path = "../common" }

proofman-common = { workspace = true }
proofman-setup = { workspace = true }
proofman-macros = { workspace = true }
proofman = { workspace = true }

log = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions state-machines/arith/src/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::sync::{

use crate::{Arith3264SM, Arith32SM, Arith64SM};
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{ExecutionCtx, ProofCtx};
use proofman_setup::SetupCtx;
use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx};
use rayon::Scope;
use sm_common::{OpResult, Provable, ThreadController};
use zisk_core::{opcode_execute, ZiskRequiredOperation};
Expand Down Expand Up @@ -49,7 +48,7 @@ impl ArithSM {
};
let arith_sm = Arc::new(arith_sm);

wcm.register_component(arith_sm.clone(), None);
wcm.register_component(arith_sm.clone(), None, None);

arith_sm.arith32_sm.register_predecessor();
arith_sm.arith64_sm.register_predecessor();
Expand Down
7 changes: 3 additions & 4 deletions state-machines/arith/src/arith_32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::sync::{
};

use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{ExecutionCtx, ProofCtx};
use proofman_setup::SetupCtx;
use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx};
use rayon::Scope;
use sm_common::{OpResult, Provable};
use zisk_core::{opcode_execute, ZiskRequiredOperation};
Expand All @@ -21,12 +20,12 @@ pub struct Arith32SM {
}

impl Arith32SM {
pub fn new<F>(wcm: &mut WitnessManager<F>, air_ids: &[usize]) -> Arc<Self> {
pub fn new<F>(wcm: &mut WitnessManager<F>, airgroup_id: usize, air_ids: &[usize]) -> Arc<Self> {
let arith32_sm =
Self { registered_predecessors: AtomicU32::new(0), inputs: Mutex::new(Vec::new()) };
let arith32_sm = Arc::new(arith32_sm);

wcm.register_component(arith32_sm.clone(), Some(air_ids));
wcm.register_component(arith32_sm.clone(), Some(airgroup_id), Some(air_ids));

arith32_sm
}
Expand Down
7 changes: 3 additions & 4 deletions state-machines/arith/src/arith_3264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::sync::{
};

use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{ExecutionCtx, ProofCtx};
use proofman_setup::SetupCtx;
use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx};
use rayon::Scope;
use sm_common::{OpResult, Provable};
use zisk_core::{opcode_execute, ZiskRequiredOperation};
Expand All @@ -21,12 +20,12 @@ pub struct Arith3264SM {
}

impl Arith3264SM {
pub fn new<F>(wcm: &mut WitnessManager<F>, air_ids: &[usize]) -> Arc<Self> {
pub fn new<F>(wcm: &mut WitnessManager<F>, airgroup_id: usize, air_ids: &[usize]) -> Arc<Self> {
let arith3264_sm =
Self { registered_predecessors: AtomicU32::new(0), inputs: Mutex::new(Vec::new()) };
let arith3264_sm = Arc::new(arith3264_sm);

wcm.register_component(arith3264_sm.clone(), Some(air_ids));
wcm.register_component(arith3264_sm.clone(), Some(airgroup_id), Some(air_ids));

arith3264_sm
}
Expand Down
7 changes: 3 additions & 4 deletions state-machines/arith/src/arith_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::sync::{
};

use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{ExecutionCtx, ProofCtx};
use proofman_setup::SetupCtx;
use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx};
use rayon::Scope;
use sm_common::{OpResult, Provable};
use zisk_core::{opcode_execute, ZiskRequiredOperation};
Expand All @@ -21,12 +20,12 @@ pub struct Arith64SM {
}

impl Arith64SM {
pub fn new<F>(wcm: &mut WitnessManager<F>, air_ids: &[usize]) -> Arc<Self> {
pub fn new<F>(wcm: &mut WitnessManager<F>, airgroup_id: usize, air_ids: &[usize]) -> Arc<Self> {
let arith64_sm =
Self { registered_predecessors: AtomicU32::new(0), inputs: Mutex::new(Vec::new()) };
let arith64_sm = Arc::new(arith64_sm);

wcm.register_component(arith64_sm.clone(), Some(air_ids));
wcm.register_component(arith64_sm.clone(), Some(airgroup_id), Some(air_ids));

arith64_sm
}
Expand Down
3 changes: 2 additions & 1 deletion state-machines/arith/src/arith_traces.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use proofman_common::trace;
use proofman_common as common;
pub use proofman_macros::trace;

trace!(Arith320Row, Arith320Trace<F> { fake: F });
trace!(Arith640Row, Arith640Trace<F> { fake: F });
Expand Down
2 changes: 1 addition & 1 deletion state-machines/binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sm-common = { path = "../common" }

p3-field = { workspace=true }
proofman-common = { workspace = true }
proofman-setup = { workspace = true }
proofman-macros = { workspace = true }
proofman = { workspace = true }

log = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions state-machines/binary/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::sync::{

use crate::{BinaryBasicSM, BinaryExtensionSM};
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{ExecutionCtx, ProofCtx};
use proofman_setup::SetupCtx;
use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx};
use rayon::Scope;
use sm_common::{OpResult, Provable, ThreadController};
use zisk_core::{opcode_execute, ZiskRequiredOperation};
Expand Down Expand Up @@ -46,7 +45,7 @@ impl BinarySM {
};
let binary_sm = Arc::new(binary_sm);

wcm.register_component(binary_sm.clone(), None);
wcm.register_component(binary_sm.clone(), None, None);

binary_sm.binary_basic_sm.register_predecessor();
binary_sm.binary_extension_sm.register_predecessor();
Expand Down
Loading

0 comments on commit f0d8474

Please sign in to comment.