Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zisk New Arch #185

Draft
wants to merge 67 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f258ec2
wip
xavi-pinsach Nov 20, 2024
65c2ee2
wip
xavi-pinsach Nov 20, 2024
0d9bc09
wip
xavi-pinsach Nov 29, 2024
9f6e25c
wip
xavi-pinsach Dec 3, 2024
b90ed6d
wip
xavi-pinsach Dec 3, 2024
efe6b8a
wip cleaning
xavi-pinsach Dec 3, 2024
306ba74
clean code
xavi-pinsach Dec 3, 2024
2381971
clean code
xavi-pinsach Dec 3, 2024
5a2ec46
activate code in rom_sm.rs
xavi-pinsach Dec 4, 2024
45cb180
wip rom-merkle
xavi-pinsach Dec 4, 2024
8023f90
update pils to use std_constants.pil
xavi-pinsach Dec 4, 2024
0b33f3c
Move registers from memory to context
fractasy Dec 4, 2024
f1089a6
remove emu_slice and ZiskRequired
xavi-pinsach Dec 5, 2024
973180b
remove emu_slice from lib.rs
xavi-pinsach Dec 5, 2024
a2ecc6e
clippy
xavi-pinsach Dec 5, 2024
2bfb8ec
remove generics in ExecutionCtx and SetupCtx in arith sm
xavi-pinsach Dec 5, 2024
3f460e1
remove create_prover_buffer
xavi-pinsach Dec 5, 2024
320aa1c
remove generics in ExecutionCtx and SetupCtx in freq_ops, mem and qui…
xavi-pinsach Dec 5, 2024
d5a459e
wip in binaries
xavi-pinsach Dec 5, 2024
f5c9834
wip in rom
xavi-pinsach Dec 5, 2024
b43c761
refactor witness computation main
xavi-pinsach Dec 5, 2024
ed8d702
clippy
xavi-pinsach Dec 5, 2024
bf2da5f
clippy
xavi-pinsach Dec 5, 2024
04c782f
Record and playback using memory reads, in Emulator
fractasy Dec 5, 2024
e790c89
main, binaries.* and rom verifying constraints
xavi-pinsach Dec 6, 2024
33d10f7
fix when +1 binaries
xavi-pinsach Dec 7, 2024
f329e91
remove debug code
xavi-pinsach Dec 7, 2024
f48e8eb
std working
xavi-pinsach Dec 9, 2024
892f0d5
Checkpoint as Option
xavi-pinsach Dec 9, 2024
65422a1
remove unnecessary impl WitnessComponent
xavi-pinsach Dec 9, 2024
ee06924
Emu source_x_mem_reads_generate & consume
fractasy Dec 9, 2024
fedc4ec
Merge from instruction_observer
fractasy Dec 9, 2024
77f1026
Fixes from integration
fractasy Dec 9, 2024
e13d2c0
Define STEPS_TO_MEM_READS_RATIO_IN_BITS
fractasy Dec 9, 2024
081b4f6
Fix cargo fmt
fractasy Dec 9, 2024
130f0c5
Fix 1 cargo clippy error
fractasy Dec 9, 2024
661e871
adapted to pil2-proofman feature/minor_clean pil2-proofman PR#132
xavi-pinsach Dec 10, 2024
0c4fdea
Merge remote-tracking branch 'origin/feature/registers_state' into in…
xavi-pinsach Dec 10, 2024
4deb551
fix Cargo.toml
xavi-pinsach Dec 10, 2024
cda84c4
Merge remote-tracking branch 'origin/develop' into instruction-observer
xavi-pinsach Dec 10, 2024
d74bc1b
adapted arith to new arch
xavi-pinsach Dec 10, 2024
950c8a0
fix typo
xavi-pinsach Dec 10, 2024
34edf96
fix typo
xavi-pinsach Dec 10, 2024
d1a56a1
clean arith code
xavi-pinsach Dec 10, 2024
84eba2b
remove dead code
xavi-pinsach Dec 10, 2024
ab723ff
refactor tables
xavi-pinsach Dec 10, 2024
bd953a6
remove freq-ops and quick-ops boilerplate code
xavi-pinsach Dec 10, 2024
03fe194
clean code
xavi-pinsach Dec 10, 2024
c32ace9
simplify dctx
xavi-pinsach Dec 10, 2024
753025c
metrics proxy filtering by opcode while executing
xavi-pinsach Dec 11, 2024
241cde9
Merge remote-tracking branch 'origin/develop' into instruction-observer
xavi-pinsach Dec 11, 2024
6d2ab60
add regular counters
xavi-pinsach Dec 11, 2024
36543d9
change Instance functions names: expand -> collect & prove -> comput…
xavi-pinsach Dec 11, 2024
f634636
align with proofman
xavi-pinsach Dec 11, 2024
b33e490
added dummy counter
xavi-pinsach Dec 11, 2024
d69d2bd
simplify inputs collectors
xavi-pinsach Dec 12, 2024
c985df4
simplifying
xavi-pinsach Dec 12, 2024
fc74053
change InstanceObserver name to InputsCollector
xavi-pinsach Dec 12, 2024
8f1caea
minor fixes
xavi-pinsach Dec 12, 2024
1864999
refactor tables
xavi-pinsach Dec 12, 2024
d148325
cargo update
xavi-pinsach Dec 12, 2024
2efb983
Removing execution ctx
RogerTaule Dec 13, 2024
567b607
Removing setupctx from execute
RogerTaule Dec 13, 2024
d65c344
align with last commits in pil2-proofman
xavi-pinsach Dec 14, 2024
e160cbb
minor fix change Arc<Vec<...>> -> &[...]
xavi-pinsach Dec 16, 2024
2098c65
Integrating pil2-proofman latest changes
RogerTaule Dec 16, 2024
92a2e39
Adding cust-commits to instruction observer (#189)
RogerTaule Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
474 changes: 239 additions & 235 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[workspace]
members = [
"cli",
"cli", "common",
"core",
"emulator",
"emulator", "executor",
"pil",
"riscv",
"rom-merkle",
"state-machines/arith",
"state-machines/binary",
"state-machines/common",
"state-machines/freq-ops",
"state-machines/main",
"state-machines/mem",
"state-machines/rom",
"state-machines/std",
"witness-computation",
"ziskos/entrypoint",
]
Expand All @@ -26,19 +26,17 @@ opt-level = 3
opt-level = 3

[workspace.dependencies]
proofman-common = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.10" }
proofman-macros = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.10" }
proofman-util = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.10" }
proofman = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.10" }
pil-std-lib = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.10" }
stark = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.10" }
proofman-common = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/minor_clean" }
proofman-macros = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/minor_clean" }
proofman-util = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/minor_clean" }
pil-std-lib = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/minor_clean" }
witness = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/minor_clean" }
# Local development
# proofman-common = { path = "../pil2-proofman/common" }
# proofman-macros = { path = "../pil2-proofman/macros" }
# proofman-util = { path = "../pil2-proofman/util" }
# proofman = { path = "../pil2-proofman/proofman" }
# pil-std-lib = { path = "../pil2-proofman/pil2-components/lib/std/rs" }
# stark = { path = "../pil2-proofman/provers/stark" }
# witness = { path = "../pil2-proofman/witness" }

p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "c3d754ef77b9fce585b46b972af751fe6e7a9803" }
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion book/getting_started/quickstart_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Run this whenever the `.pilout` file changes:
### Generate Setup Data
Run this whenever the `.pilout` file changes:

```bash
```bash[]
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
```

Expand Down
7 changes: 7 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "zisk-common"
version = "0.1.0"
edition = "2021"

[dependencies]
zisk-core = { path = "../core" }
5 changes: 5 additions & 0 deletions common/src/inst_observer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use zisk_core::{InstContext, ZiskInst};

pub trait InstObserver {
fn on_instruction(&mut self, inst: &ZiskInst, inst_ctx: &InstContext) -> bool;
}
3 changes: 3 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod inst_observer;

pub use inst_observer::*;
2 changes: 2 additions & 0 deletions core/src/inst_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct InstContext {

/// End flag, set to true only by the last instruction to execute
pub end: bool,
pub regs: [u64; 32],
}

/// RisK instruction context implementation
Expand All @@ -50,6 +51,7 @@ impl InstContext {
pc: ROM_ENTRY,
step: 0,
end: false,
regs: [0; 32],
}
}

Expand Down
21 changes: 20 additions & 1 deletion core/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
//! * The third RW memory region going from `AVAILABLE_MEM_ADDR` onwards can be used during the
//! program execution a general purpose memory.

use crate::{REG_FIRST, REG_LAST};

/// Fist input data memory address
pub const INPUT_ADDR: u64 = 0x90000000;
/// Maximum size of the input data
Expand Down Expand Up @@ -203,7 +205,9 @@ impl Mem {
/// address and width
#[inline(always)]
pub fn read(&self, addr: u64, width: u64) -> u64 {
// First try to read from the write section
debug_assert!(!Mem::address_is_register(addr));

// First try to read in the write section
if (addr >= self.write_section.start) && (addr <= (self.write_section.end - width)) {
// Calculate the read position
let read_position: usize = (addr - self.write_section.start) as usize;
Expand Down Expand Up @@ -265,6 +269,8 @@ impl Mem {
/// Write a u64 value to the memory write section, based on the provided address and width
#[inline(always)]
pub fn write(&mut self, addr: u64, val: u64, width: u64) {
debug_assert!(!Mem::address_is_register(addr));

// Call write_silent to perform the real work
self.write_silent(addr, val, width);

Expand All @@ -277,6 +283,8 @@ impl Mem {
/// Write a u64 value to the memory write section, based on the provided address and width
#[inline(always)]
pub fn write_silent(&mut self, addr: u64, val: u64, width: u64) {
debug_assert!(!Mem::address_is_register(addr));

//println!("Mem::write() addr={:x}={} width={} value={:x}={}", addr, addr, width, val,
// val);

Expand Down Expand Up @@ -306,4 +314,15 @@ impl Mem {
_ => panic!("Mem::write_silent() invalid width={}", width),
}
}

#[inline(always)]
pub fn address_is_register(address: u64) -> bool {
((address & 0x7) == 0) && (REG_FIRST..=REG_LAST).contains(&address)
}

#[inline(always)]
pub fn address_to_register_index(address: u64) -> usize {
debug_assert!(Mem::address_is_register(address));
((address - REG_FIRST) >> 3) as usize
}
}
20 changes: 9 additions & 11 deletions core/src/zisk_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub const STORE_IND: u64 = 2;
/// Internal operations are proven as part of the main state machine itself, given their
/// simplicity. External operations (rest of types) are proven in their corresponding secondary
/// state machine.
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd)]
#[repr(u32)]
pub enum ZiskOperationType {
None,
Expand All @@ -73,11 +73,9 @@ pub enum ZiskOperationType {
PubOut,
}

/// Defines the length of the enumerated ZiskOperationType, required to build some structures to
/// store data splitted by operation type.
pub const ZISK_OPERATION_TYPE_VARIANTS: usize = 7;
pub const ZISK_OP_TYPE_COUNT: usize = 7;

/// Zisk instruction structure.
/// ZisK instruction definition
///
/// ZisK instructions are defined as a binary operation with 2 results: op(a, b) -> (c, flag)
/// a, b and c are u64 registers; flag is a boolean.
Expand Down Expand Up @@ -157,7 +155,7 @@ impl ZiskInst {
pub fn to_text(&self) -> String {
let mut s = String::new();
if self.paddr != 0 {
s += &(" paddr=".to_string() + &self.paddr.to_string());
s += &format!(" paddr=0x{:x}", self.paddr);
}
if self.store_ra {
s += &(" store_ra=".to_string() + &self.store_ra.to_string());
Expand All @@ -169,7 +167,7 @@ impl ZiskInst {
s += &format!(" store={}={}", self.store, store_to_str(self.store));
}
if self.store_offset != 0 {
s += &(" store_offset=".to_string() + &self.store_offset.to_string());
s += &format!(" store_offset=0x{:x}", self.store_offset);
}
if self.set_pc {
s += &(" set_pc=".to_string() + &self.set_pc.to_string());
Expand All @@ -192,19 +190,19 @@ impl ZiskInst {
s += &format!(" a_src={}={}", self.a_src, source_to_str(self.a_src));
}
if self.a_use_sp_imm1 != 0 {
s += &(" a_use_sp_imm1=".to_string() + &self.a_use_sp_imm1.to_string());
s += &format!(" a_use_sp_imm1=0x{:x}", self.a_use_sp_imm1);
}
if self.a_offset_imm0 != 0 {
s += &(" a_offset_imm0=".to_string() + &self.a_offset_imm0.to_string());
s += &format!(" a_offset_imm0=0x{:x}", self.a_offset_imm0);
}
if self.b_src != 0 {
s += &format!(" b_src={}={}", self.b_src, source_to_str(self.b_src));
}
if self.b_use_sp_imm1 != 0 {
s += &(" b_use_sp_imm1=".to_string() + &self.b_use_sp_imm1.to_string());
s += &format!(" b_use_sp_imm1=0x{:x}", self.b_use_sp_imm1);
}
if self.b_offset_imm0 != 0 {
s += &(" b_offset_imm0=".to_string() + &self.b_offset_imm0.to_string());
s += &format!(" b_offset_imm0=0x{:x}", self.b_offset_imm0);
}
if self.jmp_offset1 != 0 {
s += &(" jmp_offset1=".to_string() + &self.jmp_offset1.to_string());
Expand Down
22 changes: 0 additions & 22 deletions core/src/zisk_required_operation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Data required to prove the different Zisk operations

use std::collections::HashMap;

/// Required data to make an operation.
///
/// Stores the minimum information to reproduce an operation execution:
Expand All @@ -27,23 +25,3 @@ pub struct ZiskRequiredMemory {
pub width: u64,
pub value: u64,
}

/// Data required to get some operations proven by the secondary state machine
#[derive(Clone, Default)]
pub struct ZiskRequired {
pub arith: Vec<ZiskRequiredOperation>,
pub binary: Vec<ZiskRequiredOperation>,
pub binary_extension: Vec<ZiskRequiredOperation>,
pub memory: Vec<ZiskRequiredMemory>,
}

/// Histogram of the program counter values used during the program execution.
///
/// Each pc value has a u64 counter, associated to it via a hash map.
/// The counter is increased every time the corresponding instruction is executed.
#[derive(Clone, Default)]
pub struct ZiskPcHistogram {
pub map: HashMap<u64, u64>,
pub end_pc: u64,
pub steps: u64,
}
3 changes: 2 additions & 1 deletion emulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ path = "src/bin/ziskemu.rs"
zisk-core = { path = "../core" }
riscv = { path="../riscv" }
zisk-pil = { path="../pil" }
zisk-common = { path="../common" }
rayon = { workspace = true }

p3-field = { workspace=true }
clap = { version = "4.5.9", features = ["derive", "env"] }
sysinfo = "0.31.2"
sysinfo = "0.33"

[build-dependencies]
vergen = { version = "8", default-features = false, features = [
Expand Down
Loading