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

WIP SVM verifier support #447

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target/

# Ignore node modules
node_modules/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ keywords = ["SNARK", "cryptography", "proofs"]
[workspace]
members = [
"jolt-core",
"jolt-types",
"tracer",
"common",
"jolt-sdk",
Expand Down
1 change: 1 addition & 0 deletions jolt-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ license-file = "LICENSE"
keywords = ["SNARK", "cryptography", "proofs"]

[dependencies]
jolt-types = { path = "../jolt-types", default-features = true }
ark-bn254 = "0.4.0"
ark-ec = { version = "0.4.2", default-features = false }
ark-ff = { version = "0.4.2", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::field::JoltField;
use crate::host;
use crate::jolt::vm::rv32i_vm::{RV32IJoltVM, C, M};
use crate::jolt::vm::Jolt;
Expand All @@ -7,6 +6,7 @@ use crate::poly::commitment::hyperkzg::HyperKZG;
use crate::poly::commitment::hyrax::HyraxScheme;
use crate::poly::commitment::zeromorph::Zeromorph;
use ark_bn254::{Bn254, Fr, G1Projective};
use jolt_types::field::JoltField;
use serde::Serialize;

#[derive(Debug, Copy, Clone, clap::ValueEnum)]
Expand Down
10 changes: 5 additions & 5 deletions jolt-core/src/field/binius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ark_std::{One, Zero};
use binius_field::{BinaryField128b, BinaryField128bPolyval};
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign};

use super::{FieldOps, JoltField};
use jolt_types::field::{FieldOps, JoltField};

impl BiniusConstructable for BinaryField128b {
fn new(n: u64) -> Self {
Expand Down Expand Up @@ -126,16 +126,16 @@ impl<F: BiniusSpecific> JoltField for BiniusField<F> {
Self(self.0.square())
}

fn inverse(&self) -> Option<Self> {
self.0.invert().map(Self)
}

fn from_bytes(bytes: &[u8]) -> Self {
assert_eq!(bytes.len(), Self::NUM_BYTES);

let field_element = bytemuck::try_from_bytes::<F>(bytes).unwrap();
Self(field_element.to_owned())
}

fn inverse(&self) -> Option<Self> {
self.0.invert().map(Self)
}
}

impl<F: BiniusSpecific> Zero for BiniusField<F> {
Expand Down
92 changes: 0 additions & 92 deletions jolt-core/src/field/mod.rs
Original file line number Diff line number Diff line change
@@ -1,93 +1 @@
use std::fmt::Debug;
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign};

use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{One, Zero};

pub trait FieldOps<Rhs = Self, Output = Self>:
Add<Rhs, Output = Output>
+ Sub<Rhs, Output = Output>
+ Mul<Rhs, Output = Output>
+ Div<Rhs, Output = Output>
{
}

pub trait JoltField:
'static
+ Sized
+ Zero
+ One
+ Neg<Output = Self>
+ FieldOps<Self, Self>
+ for<'a> FieldOps<&'a Self, Self>
+ AddAssign<Self>
+ SubAssign<Self>
+ MulAssign<Self>
+ core::iter::Sum<Self>
+ for<'a> core::iter::Sum<&'a Self>
+ core::iter::Product<Self>
+ for<'a> core::iter::Product<&'a Self>
+ Eq
+ Copy
+ Sync
+ Send
+ Debug
+ Default
+ CanonicalSerialize
+ CanonicalDeserialize
{
const NUM_BYTES: usize;
fn random<R: rand_core::RngCore>(rng: &mut R) -> Self;

fn from_u64(n: u64) -> Option<Self>;
fn from_i64(val: i64) -> Self;
fn square(&self) -> Self;
fn from_bytes(bytes: &[u8]) -> Self;
fn inverse(&self) -> Option<Self>;
fn to_u64(&self) -> Option<u64> {
unimplemented!("conversion to u64 not implemented");
}
}

pub trait OptimizedMul<Rhs, Output>: Sized + Mul<Rhs, Output = Output> {
fn mul_0_optimized(self, other: Rhs) -> Self::Output;
fn mul_1_optimized(self, other: Rhs) -> Self::Output;
fn mul_01_optimized(self, other: Rhs) -> Self::Output;
}

impl<T> OptimizedMul<T, T> for T
where
T: JoltField,
{
#[inline(always)]
fn mul_0_optimized(self, other: T) -> T {
if self.is_zero() || other.is_zero() {
Self::zero()
} else {
self * other
}
}

#[inline(always)]
fn mul_1_optimized(self, other: T) -> T {
if self.is_one() {
other
} else if other.is_one() {
self
} else {
self * other
}
}

#[inline(always)]
fn mul_01_optimized(self, other: T) -> T {
if self.is_zero() || other.is_zero() {
Self::zero()
} else {
self.mul_1_optimized(other)
}
}
}

pub mod ark;
pub mod binius;
6 changes: 2 additions & 4 deletions jolt-core/src/host/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ use std::{collections::HashMap, fs::File, io, path::PathBuf};
use serde::{Deserialize, Serialize};
use tracer::{ELFInstruction, JoltDevice, RVTraceRow, RV32IM};

use crate::{
field::JoltField,
jolt::vm::{rv32i_vm::RV32I, JoltTraceStep},
};
use crate::jolt::vm::{rv32i_vm::RV32I, JoltTraceStep};
use jolt_types::field::JoltField;

#[derive(Clone, Serialize, Deserialize)]
pub struct ProgramSummary {
Expand Down
19 changes: 9 additions & 10 deletions jolt-core/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ use postcard;
use rayon::prelude::*;
use serde::Serialize;

use common::{
constants::{
DEFAULT_MAX_INPUT_SIZE, DEFAULT_MAX_OUTPUT_SIZE, DEFAULT_MEMORY_SIZE, DEFAULT_STACK_SIZE,
},
rv_trace::{JoltDevice, NUM_CIRCUIT_FLAGS},
};
use strum::EnumCount;
pub use tracer::ELFInstruction;

use crate::{
field::JoltField,
jolt::{
instruction::{
div::DIVInstruction, divu::DIVUInstruction, mulh::MULHInstruction,
Expand All @@ -33,6 +23,15 @@ use crate::{
},
utils::thread::unsafe_allocate_zero_vec,
};
use common::{
constants::{
DEFAULT_MAX_INPUT_SIZE, DEFAULT_MAX_OUTPUT_SIZE, DEFAULT_MEMORY_SIZE, DEFAULT_STACK_SIZE,
},
rv_trace::{JoltDevice, NUM_CIRCUIT_FLAGS},
};
use jolt_types::field::JoltField;
use strum::EnumCount;
pub use tracer::ELFInstruction;

use self::analyze::ProgramSummary;
#[cfg(not(target_arch = "wasm32"))]
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::{
identity::IdentitySubtable, truncate_overflow::TruncateOverflowSubtable, LassoSubtable,
};
use crate::utils::instruction_utils::{
add_and_chunk_operands, assert_valid_parameters, concatenate_lookups,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct ADDInstruction<const WORD_SIZE: usize>(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::{and::AndSubtable, LassoSubtable};
use crate::utils::instruction_utils::{chunk_and_concatenate_operands, concatenate_lookups};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct ANDInstruction(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/beq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use serde::{Deserialize, Serialize};

use super::JoltInstruction;
use crate::{
field::JoltField,
jolt::{
instruction::SubtableIndices,
subtable::{eq::EqSubtable, LassoSubtable},
},
utils::instruction_utils::chunk_and_concatenate_operands,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct BEQInstruction(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/bge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use serde::{Deserialize, Serialize};

use super::{slt::SLTInstruction, JoltInstruction, SubtableIndices};
use crate::{
field::JoltField,
jolt::subtable::{
eq::EqSubtable, eq_abs::EqAbsSubtable, left_msb::LeftMSBSubtable, lt_abs::LtAbsSubtable,
ltu::LtuSubtable, right_msb::RightMSBSubtable, LassoSubtable,
},
utils::instruction_utils::chunk_and_concatenate_operands,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct BGEInstruction(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/bgeu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use serde::{Deserialize, Serialize};

use super::{sltu::SLTUInstruction, JoltInstruction, SubtableIndices};
use crate::{
field::JoltField,
jolt::subtable::{eq::EqSubtable, ltu::LtuSubtable, LassoSubtable},
utils::instruction_utils::chunk_and_concatenate_operands,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct BGEUInstruction(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/bne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use serde::{Deserialize, Serialize};

use super::JoltInstruction;
use crate::{
field::JoltField,
jolt::{
instruction::SubtableIndices,
subtable::{eq::EqSubtable, LassoSubtable},
},
utils::instruction_utils::chunk_and_concatenate_operands,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct BNEInstruction(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/lb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::identity::IdentitySubtable;
use crate::jolt::subtable::{
sign_extend::SignExtendSubtable, truncate_overflow::TruncateOverflowSubtable, LassoSubtable,
};
use crate::utils::instruction_utils::chunk_operand_usize;
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct LBInstruction(pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/lh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::{
identity::IdentitySubtable, sign_extend::SignExtendSubtable, LassoSubtable,
};
use crate::utils::instruction_utils::chunk_operand_usize;
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct LHInstruction(pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::ops::Range;
use strum::{EnumCount, IntoEnumIterator};
use tracer::{RVTraceRow, RegisterState};

use crate::field::JoltField;
use crate::jolt::subtable::LassoSubtable;
use crate::utils::instruction_utils::chunk_operand;
use common::rv_trace::ELFInstruction;
use jolt_types::field::JoltField;
use std::fmt::Debug;

#[enum_dispatch]
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::{
identity::IdentitySubtable, truncate_overflow::TruncateOverflowSubtable, LassoSubtable,
};
use crate::utils::instruction_utils::{
assert_valid_parameters, concatenate_lookups, multiply_and_chunk_operands,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct MULInstruction<const WORD_SIZE: usize>(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/mulhu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::{identity::IdentitySubtable, LassoSubtable};
use crate::utils::instruction_utils::{
assert_valid_parameters, concatenate_lookups, multiply_and_chunk_operands,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct MULHUInstruction<const WORD_SIZE: usize>(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/mulu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::{
identity::IdentitySubtable, truncate_overflow::TruncateOverflowSubtable, LassoSubtable,
};
use crate::utils::instruction_utils::{
assert_valid_parameters, concatenate_lookups, multiply_and_chunk_operands,
};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct MULUInstruction<const WORD_SIZE: usize>(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::{or::OrSubtable, LassoSubtable};
use crate::utils::instruction_utils::{chunk_and_concatenate_operands, concatenate_lookups};
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct ORInstruction(pub u64, pub u64);
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/sb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};

use super::{JoltInstruction, SubtableIndices};
use crate::field::JoltField;
use crate::jolt::subtable::identity::IdentitySubtable;
use crate::jolt::subtable::{truncate_overflow::TruncateOverflowSubtable, LassoSubtable};
use crate::utils::instruction_utils::chunk_operand_usize;
use jolt_types::field::JoltField;

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub struct SBInstruction(pub u64);
Expand Down
Loading
Loading