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

Wiring part 1 #106

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions jolt-core/src/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use crate::jolt::vm::instruction_lookups::InstructionLookupsProof;
use crate::jolt::vm::rv32i_vm::{RV32IJoltVM, RV32I};
use crate::jolt::vm::Jolt;
use crate::lasso::surge::Surge;
use crate::utils::math::Math;
use crate::utils::{math::Math, random::RandomTape};
use crate::{jolt::instruction::xor::XORInstruction, utils::gen_random_point};
use ark_curve25519::{EdwardsProjective, Fr};
use ark_std::{test_rng};
use ark_std::test_rng;
use merlin::Transcript;
use rand_chacha::rand_core::RngCore;

Expand Down Expand Up @@ -152,12 +152,12 @@ fn rv32i_lookup_benchmarks() -> Vec<(tracing::Span, Box<dyn FnOnce()>)> {
println!("Running {:?}", ops.len());

let work = Box::new(|| {
let r: Vec<Fr> = gen_random_point::<Fr>(ops.len().log_2());
let mut prover_transcript = Transcript::new(b"example");
let mut random_tape = RandomTape::new(b"test_tape");
let proof: InstructionLookupsProof<Fr, EdwardsProjective> =
RV32IJoltVM::prove_instruction_lookups(ops, r.clone(), &mut prover_transcript);
RV32IJoltVM::prove_instruction_lookups(ops, &mut prover_transcript, &mut random_tape);
let mut verifier_transcript = Transcript::new(b"example");
assert!(RV32IJoltVM::verify_instruction_lookups(proof, r, &mut verifier_transcript).is_ok());
assert!(RV32IJoltVM::verify_instruction_lookups(proof, &mut verifier_transcript).is_ok());
});
vec![(tracing::info_span!("RV32IM"), work)]
}
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/jolt/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use ark_ff::PrimeField;

use super::{
instruction::JoltInstruction,
vm::{pc::ELFRow, read_write_memory::MemoryOp},
vm::{bytecode::ELFRow, read_write_memory::MemoryOp},
};

trait JoltProvableTrace {
type JoltInstructionEnum: JoltInstruction;
fn to_jolt_instructions(&self) -> Vec<Self::JoltInstructionEnum>;
fn to_ram_ops(&self) -> Vec<MemoryOp>;
fn to_pc_trace(&self) -> ELFRow;
fn to_bytecode_trace(&self) -> ELFRow;
fn to_circuit_flags<F: PrimeField>(&self) -> Vec<F>;
}

Expand Down
41 changes: 29 additions & 12 deletions jolt-core/src/jolt/trace/rv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use crate::jolt::instruction::sltu::SLTUInstruction;
use crate::jolt::instruction::sra::SRAInstruction;
use crate::jolt::instruction::srl::SRLInstruction;
use crate::jolt::instruction::xor::XORInstruction;
use crate::jolt::instruction::{add::ADDInstruction, sub::SUBInstruction};
use crate::jolt::instruction::JoltInstruction;
use crate::jolt::vm::{pc::ELFRow, rv32i_vm::RV32I};
use crate::jolt::instruction::{add::ADDInstruction, sub::SUBInstruction};
use crate::jolt::vm::{bytecode::ELFRow, rv32i_vm::RV32I};
use common::{constants::REGISTER_COUNT, RV32InstructionFormat, RV32IM};

use super::JoltProvableTrace;
Expand Down Expand Up @@ -843,7 +843,7 @@ impl JoltProvableTrace for RVTraceRow {
}
}

fn to_pc_trace(&self) -> ELFRow {
fn to_bytecode_trace(&self) -> ELFRow {
ELFRow::new(
self.pc.try_into().unwrap(),
self.opcode as u64,
Expand Down Expand Up @@ -1016,18 +1016,18 @@ mod tests {
use std::convert;

#[test]
fn to_pc_trace() {
fn to_bytecode_trace() {
// ADD
let add_row = RVTraceRow::RType(2, RV32IM::ADD, 12, 10, 11, 0, 35, 15, 20);
let add_pc = add_row.to_pc_trace();
let add_pc = add_row.to_bytecode_trace();
let expected_pc = ELFRow::new(2, RV32IM::ADD as u64, 12, 10, 11, 0u64);
assert_eq!(add_pc, expected_pc);

// LUI
let imm = 20;
let rd_update = 20 << 12;
let lui_row = RVTraceRow::UType(0, RV32IM::LUI, 10, 0, rd_update, imm);
let lui_pc = lui_row.to_pc_trace();
let lui_pc = lui_row.to_bytecode_trace();
let expected_pc = ELFRow::new(0, RV32IM::LUI as u64, 10, 0, 0, 20u64);
assert_eq!(lui_pc, expected_pc);
}
Expand Down Expand Up @@ -1070,19 +1070,32 @@ mod tests {
.into_iter()
.map(|common| RVTraceRow::from_common(common))
.collect();
let _: Vec<ELFRow> = converted_trace
.iter()
.map(|row| row.to_bytecode_trace())
.collect();

let mut num_errors = 0;
for row in &converted_trace {
if let Err(e) = row.validate() {
// if row.opcode != RV32IM::SLLI {
println!("Validation error: {} \n{:#?}\n\n", e, row);
// }
num_errors += 1;
}
}
println!("Total errors: {num_errors}");
}

#[test]
fn load_bytecode() {
use common::path::JoltPaths;
use common::serializable::Serializable;

let bytecode_location = JoltPaths::bytecode_path("fibonacci");
let instructions = Vec::<common::ELFInstruction>::deserialize_from_file(&bytecode_location)
.expect("deserialization failed");
let _: Vec<ELFRow> = instructions.iter().map(|x| ELFRow::from(x)).collect();
}

#[test]
fn fib_e2e() {
use crate::jolt::vm::rv32i_vm::RV32I;
Expand Down Expand Up @@ -1115,13 +1128,18 @@ mod tests {
.into_iter()
.flat_map(|row| row.to_jolt_instructions())
.collect();
let r: Vec<Fr> = gen_random_point::<Fr>(lookup_ops.len().log_2());
let mut prover_transcript = Transcript::new(b"example");
let mut random_tape = RandomTape::new(b"test_tape");

let proof: InstructionLookupsProof<Fr, EdwardsProjective> =
RV32IJoltVM::prove_instruction_lookups(lookup_ops, r.clone(), &mut prover_transcript);
RV32IJoltVM::prove_instruction_lookups(
lookup_ops,
&mut prover_transcript,
&mut random_tape,
);
let mut verifier_transcript = Transcript::new(b"example");
assert!(
RV32IJoltVM::verify_instruction_lookups(proof, r, &mut verifier_transcript).is_ok()
RV32IJoltVM::verify_instruction_lookups(proof, &mut verifier_transcript).is_ok()
);

// Prove memory
Expand All @@ -1141,7 +1159,6 @@ mod tests {
let batched_polys = rw_memory.batch();
let commitments = ReadWriteMemory::commit(&batched_polys);

let mut random_tape = RandomTape::new(b"test_tape");
let proof = rw_memory.prove_memory_checking(
&rw_memory,
&batched_polys,
Expand Down
Loading