Skip to content

Commit

Permalink
add proofvalue to enable/disable input_data memory (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkronos73 authored Dec 12, 2024
1 parent e5f11b2 commit 0c063e0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 34 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

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

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ opt-level = 3
opt-level = 3

[workspace.dependencies]
proofman-common = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.16" }
proofman-macros = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.16" }
proofman-util = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.16" }
proofman = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.16" }
pil-std-lib = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.16" }
stark = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", rev = "0.0.16" }
proofman-common = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "fix/starkpil-memcpy-airvalue-proofvalue" }
proofman-macros = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "fix/starkpil-memcpy-airvalue-proofvalue" }
proofman-util = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "fix/starkpil-memcpy-airvalue-proofvalue" }
proofman = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "fix/starkpil-memcpy-airvalue-proofvalue" }
pil-std-lib = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "fix/starkpil-memcpy-airvalue-proofvalue" }
stark = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "fix/starkpil-memcpy-airvalue-proofvalue" }
#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" }
#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" }

p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "c3d754ef77b9fce585b46b972af751fe6e7a9803" }
log = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions emulator/src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl<'a> Emu<'a> {
}
}

/// Set SP, if specified by the current instruction
// Set SP, if specified by the current instruction
// #[cfg(feature = "sp")]
// #[inline(always)]
// pub fn set_sp(&mut self, instruction: &ZiskInst) {
Expand All @@ -426,7 +426,7 @@ impl<'a> Emu<'a> {
// }
// }

/// Set PC, based on current PC, current flag and current instruction
// Set PC, based on current PC, current flag and current instruction
#[inline(always)]
pub fn set_pc(&mut self, instruction: &ZiskInst) {
if instruction.set_pc {
Expand Down
7 changes: 5 additions & 2 deletions pil/zisk.pil
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ require "arith/pil/arith.pil"

const int OPERATION_BUS_ID = 5000;

proofval enable_input_data;
enable_input_data * (1 - enable_input_data);

airgroup Zisk {
Main(N: 2**21, RC: 2, operation_bus_id: OPERATION_BUS_ID);
Rom(N: 2**22);

Mem(N: 2**21, RC: 2, base_address: 0xA000_0000);
Mem(N: 2**21, RC: 2, base_address: 0x8000_0000, immutable: 1) alias RomData;
Mem(N: 2**21, RC: 2, base_address: 0x9000_0000, free_input_mem: 1) alias InputData;
Mem(N: 2**21, RC: 2, base_address: 0x9000_0000, free_input_mem: 1, enable_flag: enable_input_data) alias InputData;

MemAlign(N: 2**21);
MemAlignRom(disable_fixed: 0);
// InputData(N: 2**21, RC: 2);

Arith(N: 2**21, operation_bus_id: OPERATION_BUS_ID);
ArithTable();
Expand Down
2 changes: 1 addition & 1 deletion state-machines/arith/pil/arith_table.pil
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "std_lookup.pil"

const int ARITH_TABLE_ID = 331;

airtemplate ArithTable(int N = 2**7, int generate_table = 1) {
airtemplate ArithTable(int N = 2**7, int generate_table = 0) {

// div m32 sa sb primary secondary opcodes na nb np nr sext(c)
// -----------------------------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions state-machines/mem/pil/mem.pil
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ const int MEMORY_MAX_DIFF = 2**24;
const int MAX_MEM_STEP_OFFSET = 2;
const int MAX_MEM_OPS_PER_MAIN_STEP = (MAX_MEM_STEP_OFFSET + 1) * 2;

airtemplate Mem(const int N = 2**21, const int id = MEMORY_ID, const int RC = 2, const int mem_bytes = 8, const int base_address = 0, const int mem_size = 0x800_0000, int immutable = 0, const int free_input_mem = 0) {
airtemplate Mem(const int N = 2**21, const int id = MEMORY_ID, const int RC = 2, const int mem_bytes = 8,
const int base_address = 0, const int mem_size = 0x800_0000, int immutable = 0,
const int free_input_mem = 0, const expr enable_flag = 1) {

col fixed SEGMENT_L1 = [1,0...];
const expr SEGMENT_LAST = SEGMENT_L1';

Expand Down Expand Up @@ -146,7 +149,8 @@ airtemplate Mem(const int N = 2**21, const int id = MEMORY_ID, const int RC = 2,
for (int i = 0; i < length(zeros); ++i) {
zeros[i] = 0;
}
direct_global_update_proves(MEMORY_CONT_ID, [ base_address, 0, internal_base_address, 0, ...zeros]);

direct_global_update_proves(MEMORY_CONT_ID, [ base_address, 0, internal_base_address, 0, ...zeros], sel: enable_flag);

// for security check that first address has correct value, to avoid add huge quantity of instances to "overflow" prime field.
range_check(colu: previous_segment_addr - internal_base_address + 1, min: 1, max: MEMORY_MAX_DIFF);
Expand Down
9 changes: 8 additions & 1 deletion state-machines/mem/src/input_data_sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ impl<F: PrimeField> InputDataSM<F> {
self.std.unregister_predecessor(pctx, None);
}
}

pub fn prove(&self, inputs: &[MemInput]) {
let wcm = self.wcm.clone();
let pctx = wcm.get_pctx();

if (inputs.is_empty()) {
pctx.set_proof_value("enable_input_data", F::zero());
return;
}

pctx.set_proof_value("enable_input_data", F::one());

let ectx = wcm.get_ectx();
let sctx = wcm.get_sctx();

Expand Down

0 comments on commit 0c063e0

Please sign in to comment.