Skip to content

Commit

Permalink
Merge pull request #68 from 0xPolygonHermez/feature/only-main-prove
Browse files Browse the repository at this point in the history
main alone state machine prove
  • Loading branch information
zkronos73 authored Aug 30, 2024
2 parents 1585d54 + 2255971 commit a572071
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 319 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/*.tar.gz
/riscof
/riscof
/build
68 changes: 34 additions & 34 deletions core/src/zisk_opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,32 @@ impl<'de> Deserialize<'de> for ZiskOperator {
match value {
0x00 => Ok(ZiskOperator::Flag),
0x01 => Ok(ZiskOperator::CopyB),
0x02 => Ok(ZiskOperator::SignExtendB),
0x03 => Ok(ZiskOperator::SignExtendH),
0x04 => Ok(ZiskOperator::SignExtendW),
0x10 => Ok(ZiskOperator::Add),
0x14 => Ok(ZiskOperator::AddW),
0x20 => Ok(ZiskOperator::Sub),
0x24 => Ok(ZiskOperator::SubW),
0x30 => Ok(ZiskOperator::Sll),
0x34 => Ok(ZiskOperator::SllW),
0x40 => Ok(ZiskOperator::Sra),
0x41 => Ok(ZiskOperator::Srl),
0x44 => Ok(ZiskOperator::SraW),
0x45 => Ok(ZiskOperator::SrlW),
0x50 => Ok(ZiskOperator::Eq),
0x54 => Ok(ZiskOperator::EqW),
0x60 => Ok(ZiskOperator::Ltu),
0x61 => Ok(ZiskOperator::Lt),
0x64 => Ok(ZiskOperator::LtuW),
0x65 => Ok(ZiskOperator::LtW),
0x70 => Ok(ZiskOperator::Leu),
0x71 => Ok(ZiskOperator::Le),
0x74 => Ok(ZiskOperator::LeuW),
0x75 => Ok(ZiskOperator::LeW),
0x80 => Ok(ZiskOperator::And),
0x90 => Ok(ZiskOperator::Or),
0xa0 => Ok(ZiskOperator::Xor),
0x24 => Ok(ZiskOperator::SignExtendB),
0x25 => Ok(ZiskOperator::SignExtendH),
0x26 => Ok(ZiskOperator::SignExtendW),
0x02 => Ok(ZiskOperator::Add),
0x12 => Ok(ZiskOperator::AddW),
0x03 => Ok(ZiskOperator::Sub),
0x13 => Ok(ZiskOperator::SubW),
0x0d => Ok(ZiskOperator::Sll),
0x1d => Ok(ZiskOperator::SllW),
0x0f => Ok(ZiskOperator::Sra),
0x0e => Ok(ZiskOperator::Srl),
0x1f => Ok(ZiskOperator::SraW),
0x1e => Ok(ZiskOperator::SrlW),
0x08 => Ok(ZiskOperator::Eq),
0x18 => Ok(ZiskOperator::EqW),
0x04 => Ok(ZiskOperator::Ltu),
0x05 => Ok(ZiskOperator::Lt),
0x14 => Ok(ZiskOperator::LtuW),
0x15 => Ok(ZiskOperator::LtW),
0x06 => Ok(ZiskOperator::Leu),
0x07 => Ok(ZiskOperator::Le),
0x16 => Ok(ZiskOperator::LeuW),
0x17 => Ok(ZiskOperator::LeW),
0x20 => Ok(ZiskOperator::And),
0x21 => Ok(ZiskOperator::Or),
0x22 => Ok(ZiskOperator::Xor),
0xb0 => Ok(ZiskOperator::Mulu),
0xb1 => Ok(ZiskOperator::Mul),
0xb5 => Ok(ZiskOperator::MulW),
Expand All @@ -104,14 +104,14 @@ impl<'de> Deserialize<'de> for ZiskOperator {
0xc9 => Ok(ZiskOperator::Rem),
0xcc => Ok(ZiskOperator::RemuW),
0xcd => Ok(ZiskOperator::RemW),
0xd0 => Ok(ZiskOperator::Minu),
0xd1 => Ok(ZiskOperator::Min),
0xd4 => Ok(ZiskOperator::MinuW),
0xd5 => Ok(ZiskOperator::MinW),
0xe0 => Ok(ZiskOperator::Maxu),
0xe1 => Ok(ZiskOperator::Max),
0xe4 => Ok(ZiskOperator::MaxuW),
0xe5 => Ok(ZiskOperator::MaxW),
0x09 => Ok(ZiskOperator::Minu),
0x0a => Ok(ZiskOperator::Min),
0x19 => Ok(ZiskOperator::MinuW),
0x1a => Ok(ZiskOperator::MinW),
0x0b => Ok(ZiskOperator::Maxu),
0x0c => Ok(ZiskOperator::Max),
0x1b => Ok(ZiskOperator::MaxuW),
0x1c => Ok(ZiskOperator::MaxW),
_ => Err(de::Error::custom(format!("Unknown ZiskOperator code: {}", value))),
}
}
Expand Down
340 changes: 170 additions & 170 deletions core/src/zisk_operations.rs

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions emulator/src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,22 @@ impl<'a> Emu<'a> {

// Build and store the full trace
let full_trace_step = EmuFullTraceStep {
a: [F::from_canonical_u64(self.ctx.a)],
b: [F::from_canonical_u64(self.ctx.b)],
c: [F::from_canonical_u64(self.ctx.c)],
last_c: [F::from_canonical_u64(last_c)],
a: [
F::from_canonical_u64(self.ctx.a & 0xFFFFFFFF),
F::from_canonical_u64((self.ctx.a << 32) & 0xFFFFFFFF),
],
b: [
F::from_canonical_u64(self.ctx.b & 0xFFFFFFFF),
F::from_canonical_u64((self.ctx.b << 32) & 0xFFFFFFFF),
],
c: [
F::from_canonical_u64(self.ctx.c & 0xFFFFFFFF),
F::from_canonical_u64((self.ctx.c << 32) & 0xFFFFFFFF),
],
last_c: [
F::from_canonical_u64(last_c & 0xFFFFFFFF),
F::from_canonical_u64((last_c << 32) & 0xFFFFFFFF),
],
flag: F::from_bool(self.ctx.flag),
pc: F::from_canonical_u64(self.ctx.pc),
a_src_imm: F::from_bool(instruction.a_src == SRC_IMM),
Expand Down Expand Up @@ -612,6 +624,11 @@ impl<'a> Emu<'a> {
inc_sp: F::from_bool(false),
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_last_segment: F::from_bool(false),
end: F::from_bool(self.ctx.end),
m32: F::from_bool(instruction.m32),
};
emu_slice.full_trace.push(full_trace_step);

Expand Down
12 changes: 6 additions & 6 deletions emulator/src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl ZiskEmulator {
emu.run(inputs.to_owned(), options, callback);

if !emu.terminated() {
return Err(ZiskEmulatorErr::EmulationNoCompleted)
return Err(ZiskEmulatorErr::EmulationNoCompleted);
}

let duration = start.elapsed();
Expand Down Expand Up @@ -205,11 +205,11 @@ impl Emulator for ZiskEmulator {
if options.rom.is_some() && options.elf.is_some() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ROM file and ELF file are incompatible; use only one of them",
)))
)));
} else if options.rom.is_none() && options.elf.is_none() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ROM file or ELF file must be provided",
)))
)));
}

// INPUTs:
Expand All @@ -229,14 +229,14 @@ impl Emulator for ZiskEmulator {
if metadata.is_err() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ROM file does not exist",
)))
)));
}

let metadata = metadata.unwrap();
if metadata.is_dir() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ROM file must be a file",
)))
)));
}

Self::process_rom_file(rom_filename, &inputs, options, callback)
Expand All @@ -247,7 +247,7 @@ impl Emulator for ZiskEmulator {
if metadata.is_err() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ELF file does not exist",
)))
)));
}

let metadata = metadata.unwrap();
Expand Down
5 changes: 2 additions & 3 deletions pil/fork_0/pil/zisk.pil
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "../../state-machines/main/pil/main.pil"

require "../../../state-machines/main/pil/main.pil"
airgroup Main {
Main(N: 2**21, RC: 1);
Main(N: 2**21, RC: 2);
}
Binary file modified pil/fork_0/pil/zisk.pilout
Binary file not shown.
2 changes: 1 addition & 1 deletion pil/fork_0/src/pil_helpers/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
use proofman_common::trace;

trace!(Main0Row, Main0Trace<F> {
a: [F; 1], b: [F; 1], c: [F; 1], last_c: [F; 1], 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,
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,
});
5 changes: 2 additions & 3 deletions state-machines/binary/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ impl Provable<ZiskRequiredOperation, OpResult> for BinarySM {
for operation in operations {
if basic_operations.contains(&operation.opcode) {
_inputs_basic.push(operation.clone());
}
if extension_operations.contains(&operation.opcode) {
} else if extension_operations.contains(&operation.opcode) {
_inputs_extension.push(operation.clone());
} else {
panic!("BinarySM: Operator {:x} not found", operation.opcode);
panic!("BinarySM: Operator {:#04x} not found", operation.opcode);
}
}

Expand Down
Loading

0 comments on commit a572071

Please sign in to comment.