diff --git a/jolt-core/src/jolt/trace/mod.rs b/jolt-core/src/jolt/trace/mod.rs index 06b23aaf9..8b78357b1 100644 --- a/jolt-core/src/jolt/trace/mod.rs +++ b/jolt-core/src/jolt/trace/mod.rs @@ -2,7 +2,7 @@ use ark_ff::PrimeField; use super::{ instruction::JoltInstruction, - vm::{pc::ELFRow, read_write_memory::MemoryOp}, + vm::{bytecode::ELFRow, read_write_memory::MemoryOp}, }; trait JoltProvableTrace { diff --git a/jolt-core/src/jolt/trace/rv.rs b/jolt-core/src/jolt/trace/rv.rs index 915c76cef..6e47f28b5 100644 --- a/jolt-core/src/jolt/trace/rv.rs +++ b/jolt-core/src/jolt/trace/rv.rs @@ -20,7 +20,7 @@ use crate::jolt::instruction::srl::SRLInstruction; use crate::jolt::instruction::xor::XORInstruction; use crate::jolt::instruction::JoltInstruction; use crate::jolt::instruction::{add::ADDInstruction, sub::SUBInstruction}; -use crate::jolt::vm::{pc::ELFRow, rv32i_vm::RV32I}; +use crate::jolt::vm::{bytecode::ELFRow, rv32i_vm::RV32I}; use common::{constants::REGISTER_COUNT, RV32InstructionFormat, RV32IM}; use super::JoltProvableTrace; diff --git a/jolt-core/src/jolt/vm/pc.rs b/jolt-core/src/jolt/vm/bytecode.rs similarity index 88% rename from jolt-core/src/jolt/vm/pc.rs rename to jolt-core/src/jolt/vm/bytecode.rs index 99f9710c4..d5047aab7 100644 --- a/jolt-core/src/jolt/vm/pc.rs +++ b/jolt-core/src/jolt/vm/bytecode.rs @@ -137,7 +137,7 @@ impl FiveTuplePoly { } } -pub struct PCPolys> { +pub struct BytecodePolynomials> { _group: PhantomData, /// MLE of read/write addresses. For offline memory checking, each read is paired with a "virtual" write, /// so the read addresses and write addresses are the same. @@ -156,7 +156,7 @@ pub struct PCPolys> { t_final: DensePolynomial, } -impl> PCPolys { +impl> BytecodePolynomials { pub fn new_program(mut program: Vec, mut trace: Vec) -> Self { Self::validate_program(&program, &trace); Self::preprocess(&mut program, &mut trace); @@ -168,7 +168,7 @@ impl> PCPolys { let num_ops = trace.len().next_power_of_two(); let code_size = program.len().next_power_of_two(); - println!("PCPolys::new_program num_ops {num_ops} code_size {code_size}"); + println!("BytecodePolynomials::new_program num_ops {num_ops} code_size {code_size}"); let mut a_read_write_usize: Vec = vec![0; num_ops]; let mut read_cts: Vec = vec![0; num_ops]; @@ -241,7 +241,7 @@ impl> PCPolys { } } -pub struct BatchedPCPolys { +pub struct BatchedBytecodePolynomials { /// Contains: /// - a_read_write, t_read, v_read_write combined_read_write: DensePolynomial, @@ -251,8 +251,8 @@ pub struct BatchedPCPolys { combined_init_final: DensePolynomial, } -pub struct ProgramCommitment { - generators: PCCommitmentGenerators, +pub struct BytecodeCommitment { + generators: BytecodeCommitmentGenerators, /// Combined commitment for: /// - a_read_write, t_read, v_read_write pub read_write_commitments: CombinedTableCommitment, @@ -262,18 +262,18 @@ pub struct ProgramCommitment { pub init_final_commitments: CombinedTableCommitment, } -pub struct PCCommitmentGenerators { +pub struct BytecodeCommitmentGenerators { pub gens_read_write: PolyCommitmentGens, pub gens_init_final: PolyCommitmentGens, } -impl BatchablePolynomials for PCPolys +impl BatchablePolynomials for BytecodePolynomials where F: PrimeField, G: CurveGroup, { - type BatchedPolynomials = BatchedPCPolys; - type Commitment = ProgramCommitment; + type BatchedPolynomials = BatchedBytecodePolynomials; + type Commitment = BytecodeCommitment; fn batch(&self) -> Self::BatchedPolynomials { let combined_read_write = DensePolynomial::merge(&vec![ @@ -303,12 +303,12 @@ where fn commit(batched_polys: &Self::BatchedPolynomials) -> Self::Commitment { let (gens_read_write, read_write_commitments) = batched_polys .combined_read_write - .combined_commit(b"BatchedPCPolys.read_write"); + .combined_commit(b"BatchedBytecodePolynomials.read_write"); let (gens_init_final, init_final_commitments) = batched_polys .combined_init_final - .combined_commit(b"BatchedPCPolys.init_final"); + .combined_commit(b"BatchedBytecodePolynomials.init_final"); - let generators = PCCommitmentGenerators { + let generators = BytecodeCommitmentGenerators { gens_read_write, gens_init_final, }; @@ -321,13 +321,13 @@ where } } -impl MemoryCheckingProver> for PCPolys +impl MemoryCheckingProver> for BytecodePolynomials where F: PrimeField, G: CurveGroup, { - type ReadWriteOpenings = PCReadWriteOpenings; - type InitFinalOpenings = PCInitFinalOpenings; + type ReadWriteOpenings = BytecodeReadWriteOpenings; + type InitFinalOpenings = BytecodeInitFinalOpenings; // [a, opcode, rd, rs1, rs2, imm, t] type MemoryTuple = [F; 7]; @@ -344,14 +344,14 @@ where fn read_leaves( &self, - polynomials: &PCPolys, + polynomials: &BytecodePolynomials, gamma: &F, tau: &F, ) -> Vec> { let num_ops = polynomials.a_read_write.len(); let read_fingerprints = (0..num_ops) .map(|i| { - >>::fingerprint( + >>::fingerprint( &[ polynomials.a_read_write[i], polynomials.v_read_write.opcode[i], @@ -370,14 +370,14 @@ where } fn write_leaves( &self, - polynomials: &PCPolys, + polynomials: &BytecodePolynomials, gamma: &F, tau: &F, ) -> Vec> { let num_ops = polynomials.a_read_write.len(); let read_fingerprints = (0..num_ops) .map(|i| { - >>::fingerprint( + >>::fingerprint( &[ polynomials.a_read_write[i], polynomials.v_read_write.opcode[i], @@ -396,14 +396,14 @@ where } fn init_leaves( &self, - polynomials: &PCPolys, + polynomials: &BytecodePolynomials, gamma: &F, tau: &F, ) -> Vec> { let memory_size = polynomials.v_init_final.opcode.len(); let init_fingerprints = (0..memory_size) .map(|i| { - >>::fingerprint( + >>::fingerprint( &[ F::from(i as u64), polynomials.v_init_final.opcode[i], @@ -422,14 +422,14 @@ where } fn final_leaves( &self, - polynomials: &PCPolys, + polynomials: &BytecodePolynomials, gamma: &F, tau: &F, ) -> Vec> { let memory_size = polynomials.v_init_final.opcode.len(); let init_fingerprints = (0..memory_size) .map(|i| { - >>::fingerprint( + >>::fingerprint( &[ F::from(i as u64), polynomials.v_init_final.opcode[i], @@ -452,7 +452,7 @@ where } } -impl MemoryCheckingVerifier> for PCPolys +impl MemoryCheckingVerifier> for BytecodePolynomials where F: PrimeField, G: CurveGroup, @@ -508,7 +508,7 @@ where } } -pub struct PCReadWriteOpenings +pub struct BytecodeReadWriteOpenings where F: PrimeField, G: CurveGroup, @@ -523,14 +523,14 @@ where read_write_opening_proof: CombinedTableEvalProof, } -impl StructuredOpeningProof> for PCReadWriteOpenings +impl StructuredOpeningProof> for BytecodeReadWriteOpenings where F: PrimeField, G: CurveGroup, { type Openings = (F, Vec, F); - fn open(polynomials: &PCPolys, opening_point: &Vec) -> Self::Openings { + fn open(polynomials: &BytecodePolynomials, opening_point: &Vec) -> Self::Openings { ( polynomials.a_read_write.evaluate(&opening_point), polynomials.v_read_write.evaluate(&opening_point), @@ -539,8 +539,8 @@ where } fn prove_openings( - polynomials: &BatchedPCPolys, - commitment: &ProgramCommitment, + polynomials: &BatchedBytecodePolynomials, + commitment: &BytecodeCommitment, opening_point: &Vec, openings: (F, Vec, F), transcript: &mut Transcript, @@ -573,7 +573,7 @@ where fn verify_openings( &self, - commitment: &ProgramCommitment, + commitment: &BytecodeCommitment, opening_point: &Vec, transcript: &mut Transcript, ) -> Result<(), ProofVerifyError> { @@ -593,7 +593,7 @@ where } } -pub struct PCInitFinalOpenings +pub struct BytecodeInitFinalOpenings where F: PrimeField, G: CurveGroup, @@ -608,14 +608,14 @@ where init_final_opening_proof: CombinedTableEvalProof, } -impl StructuredOpeningProof> for PCInitFinalOpenings +impl StructuredOpeningProof> for BytecodeInitFinalOpenings where F: PrimeField, G: CurveGroup, { type Openings = (Vec, F); - fn open(polynomials: &PCPolys, opening_point: &Vec) -> Self::Openings { + fn open(polynomials: &BytecodePolynomials, opening_point: &Vec) -> Self::Openings { ( polynomials.v_init_final.evaluate(&opening_point), polynomials.t_final.evaluate(&opening_point), @@ -623,8 +623,8 @@ where } fn prove_openings( - polynomials: &BatchedPCPolys, - commitment: &ProgramCommitment, + polynomials: &BatchedBytecodePolynomials, + commitment: &BytecodeCommitment, opening_point: &Vec, openings: Self::Openings, transcript: &mut Transcript, @@ -654,7 +654,7 @@ where fn verify_openings( &self, - commitment: &ProgramCommitment, + commitment: &BytecodeCommitment, opening_point: &Vec, transcript: &mut Transcript, ) -> Result<(), ProofVerifyError> { @@ -716,7 +716,8 @@ mod tests { ELFRow::new(3, 16u64, 16u64, 16u64, 16u64, 16u64), ELFRow::new(2, 8u64, 8u64, 8u64, 8u64, 8u64), ]; - let polys: PCPolys = PCPolys::new_program(program, trace); + let polys: BytecodePolynomials = + BytecodePolynomials::new_program(program, trace); let (gamma, tau) = (&Fr::from(100), &Fr::from(35)); let init_leaves: Vec> = polys.init_leaves(&polys, gamma, tau); @@ -747,13 +748,14 @@ mod tests { ELFRow::new(3, 16u64, 16u64, 16u64, 16u64, 16u64), ELFRow::new(2, 8u64, 8u64, 8u64, 8u64, 8u64), ]; - let polys: PCPolys = PCPolys::new_program(program, trace); + let polys: BytecodePolynomials = + BytecodePolynomials::new_program(program, trace); let mut transcript = Transcript::new(b"test_transcript"); let mut random_tape = RandomTape::new(b"test_tape"); let batched_polys = polys.batch(); - let commitments = PCPolys::commit(&batched_polys); + let commitments = BytecodePolynomials::commit(&batched_polys); let proof = polys.prove_memory_checking( &polys, &batched_polys, @@ -763,7 +765,7 @@ mod tests { ); let mut transcript = Transcript::new(b"test_transcript"); - PCPolys::verify_memory_checking(proof, &commitments, &mut transcript) + BytecodePolynomials::verify_memory_checking(proof, &commitments, &mut transcript) .expect("proof should verify"); } @@ -782,9 +784,10 @@ mod tests { ELFRow::new(4, 32u64, 32u64, 32u64, 32u64, 32u64), ]; - let polys: PCPolys = PCPolys::new_program(program, trace); + let polys: BytecodePolynomials = + BytecodePolynomials::new_program(program, trace); let batch = polys.batch(); - let commitments = PCPolys::commit(&batch); + let commitments = BytecodePolynomials::commit(&batch); let mut transcript = Transcript::new(b"test_transcript"); let mut random_tape = RandomTape::new(b"test_tape"); @@ -798,7 +801,7 @@ mod tests { ); let mut transcript = Transcript::new(b"test_transcript"); - PCPolys::verify_memory_checking(proof, &commitments, &mut transcript) + BytecodePolynomials::verify_memory_checking(proof, &commitments, &mut transcript) .expect("should verify"); } @@ -817,7 +820,8 @@ mod tests { ELFRow::new(2, 8u64, 8u64, 8u64, 8u64, 8u64), ELFRow::new(5, 0u64, 0u64, 0u64, 0u64, 0u64), // no_op: shouldn't exist in pgoram ]; - let _polys: PCPolys = PCPolys::new_program(program, trace); + let _polys: BytecodePolynomials = + BytecodePolynomials::new_program(program, trace); } #[test] @@ -833,6 +837,7 @@ mod tests { ELFRow::new(3, 16u64, 16u64, 16u64, 16u64, 16u64), ELFRow::new(2, 8u64, 8u64, 8u64, 8u64, 8u64), ]; - let _polys: PCPolys = PCPolys::new_program(program, trace); + let _polys: BytecodePolynomials = + BytecodePolynomials::new_program(program, trace); } } diff --git a/jolt-core/src/jolt/vm/mod.rs b/jolt-core/src/jolt/vm/mod.rs index 83d174d94..4f6cd6454 100644 --- a/jolt-core/src/jolt/vm/mod.rs +++ b/jolt-core/src/jolt/vm/mod.rs @@ -19,12 +19,19 @@ use crate::jolt::{ use crate::poly::structured_poly::BatchablePolynomials; use crate::utils::{errors::ProofVerifyError, random::RandomTape}; +use self::bytecode::{ + BytecodeCommitment, BytecodeInitFinalOpenings, BytecodePolynomials, BytecodeReadWriteOpenings, + ELFRow, +}; use self::instruction_lookups::{InstructionLookups, InstructionLookupsProof}; -use self::pc::{ELFRow, PCInitFinalOpenings, PCPolys, PCReadWriteOpenings, ProgramCommitment}; use self::read_write_memory::{ MemoryCommitment, MemoryInitFinalOpenings, MemoryOp, MemoryReadWriteOpenings, ReadWriteMemory, }; +struct JoltProof> { + instruction_lookups: InstructionLookupsProof, +} + pub trait Jolt, const C: usize, const M: usize> { type InstructionSet: JoltInstruction + Opcode + IntoEnumIterator + EnumCount; type Subtables: LassoSubtable + IntoEnumIterator + EnumCount + From + Into; @@ -64,12 +71,17 @@ pub trait Jolt, const C: usize, co transcript: &mut Transcript, random_tape: &mut RandomTape, ) -> ( - MemoryCheckingProof, PCReadWriteOpenings, PCInitFinalOpenings>, - ProgramCommitment, + MemoryCheckingProof< + G, + BytecodePolynomials, + BytecodeReadWriteOpenings, + BytecodeInitFinalOpenings, + >, + BytecodeCommitment, ) { - let polys: PCPolys = PCPolys::new_program(program, trace); + let polys: BytecodePolynomials = BytecodePolynomials::new_program(program, trace); let batched_polys = polys.batch(); - let commitments = PCPolys::commit(&batched_polys); + let commitments = BytecodePolynomials::commit(&batched_polys); ( polys.prove_memory_checking( @@ -86,14 +98,14 @@ pub trait Jolt, const C: usize, co fn verify_program_code( proof: MemoryCheckingProof< G, - PCPolys, - PCReadWriteOpenings, - PCInitFinalOpenings, + BytecodePolynomials, + BytecodeReadWriteOpenings, + BytecodeInitFinalOpenings, >, - commitment: ProgramCommitment, + commitment: BytecodeCommitment, transcript: &mut Transcript, ) -> Result<(), ProofVerifyError> { - PCPolys::verify_memory_checking(proof, &commitment, transcript) + BytecodePolynomials::verify_memory_checking(proof, &commitment, transcript) } fn prove_memory( @@ -108,6 +120,7 @@ pub trait Jolt, const C: usize, co MemoryReadWriteOpenings, MemoryInitFinalOpenings, >, + MemoryCommitment, SurgeProof, ) { const MAX_TRACE_SIZE: usize = 1 << 22; @@ -138,7 +151,7 @@ pub trait Jolt, const C: usize, co >::new(timestamp_validity_lookups) .prove(transcript); - (memory_checking_proof, timestamp_validity_proof) + (memory_checking_proof, commitments, timestamp_validity_proof) } fn verify_memory( @@ -165,7 +178,7 @@ pub trait Jolt, const C: usize, co } } +pub mod bytecode; pub mod instruction_lookups; -pub mod pc; pub mod read_write_memory; pub mod rv32i_vm;