From 92392e01fd95a1adc12e52dd601c476ea23ccc5d Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Thu, 22 Aug 2024 23:31:50 -0700 Subject: [PATCH 1/4] WIP SVM HyperKZG support --- .gitignore | 5 +- Cargo.toml | 1 + jolt-core/Cargo.toml | 1 + jolt-core/src/benches/bench.rs | 2 +- jolt-core/src/field/binius.rs | 10 +- jolt-core/src/field/mod.rs | 92 -- jolt-core/src/host/analyze.rs | 6 +- jolt-core/src/host/mod.rs | 19 +- jolt-core/src/jolt/instruction/add.rs | 2 +- jolt-core/src/jolt/instruction/and.rs | 2 +- jolt-core/src/jolt/instruction/beq.rs | 2 +- jolt-core/src/jolt/instruction/bge.rs | 2 +- jolt-core/src/jolt/instruction/bgeu.rs | 2 +- jolt-core/src/jolt/instruction/bne.rs | 2 +- jolt-core/src/jolt/instruction/lb.rs | 2 +- jolt-core/src/jolt/instruction/lh.rs | 2 +- jolt-core/src/jolt/instruction/mod.rs | 2 +- jolt-core/src/jolt/instruction/mul.rs | 2 +- jolt-core/src/jolt/instruction/mulhu.rs | 2 +- jolt-core/src/jolt/instruction/mulu.rs | 2 +- jolt-core/src/jolt/instruction/or.rs | 2 +- jolt-core/src/jolt/instruction/sb.rs | 2 +- jolt-core/src/jolt/instruction/sh.rs | 2 +- jolt-core/src/jolt/instruction/sll.rs | 2 +- jolt-core/src/jolt/instruction/slt.rs | 2 +- jolt-core/src/jolt/instruction/sltu.rs | 2 +- jolt-core/src/jolt/instruction/sra.rs | 2 +- jolt-core/src/jolt/instruction/srl.rs | 2 +- jolt-core/src/jolt/instruction/sub.rs | 2 +- jolt-core/src/jolt/instruction/sw.rs | 2 +- .../src/jolt/instruction/virtual_advice.rs | 2 +- .../jolt/instruction/virtual_assert_lte.rs | 2 +- .../instruction/virtual_assert_valid_div0.rs | 13 +- .../virtual_assert_valid_signed_remainder.rs | 10 +- ...virtual_assert_valid_unsigned_remainder.rs | 3 +- .../src/jolt/instruction/virtual_move.rs | 2 +- .../src/jolt/instruction/virtual_movsign.rs | 2 +- jolt-core/src/jolt/instruction/xor.rs | 2 +- jolt-core/src/jolt/subtable/and.rs | 4 +- jolt-core/src/jolt/subtable/div_by_zero.rs | 3 +- jolt-core/src/jolt/subtable/eq.rs | 2 +- jolt-core/src/jolt/subtable/eq_abs.rs | 2 +- jolt-core/src/jolt/subtable/identity.rs | 2 +- jolt-core/src/jolt/subtable/left_is_zero.rs | 2 +- jolt-core/src/jolt/subtable/left_msb.rs | 4 +- jolt-core/src/jolt/subtable/lt_abs.rs | 4 +- jolt-core/src/jolt/subtable/ltu.rs | 4 +- jolt-core/src/jolt/subtable/mod.rs | 2 +- jolt-core/src/jolt/subtable/or.rs | 4 +- jolt-core/src/jolt/subtable/right_is_zero.rs | 2 +- jolt-core/src/jolt/subtable/right_msb.rs | 4 +- jolt-core/src/jolt/subtable/sign_extend.rs | 2 +- jolt-core/src/jolt/subtable/sll.rs | 6 +- jolt-core/src/jolt/subtable/sra_sign.rs | 6 +- jolt-core/src/jolt/subtable/srl.rs | 6 +- .../src/jolt/subtable/truncate_overflow.rs | 4 +- jolt-core/src/jolt/subtable/xor.rs | 4 +- jolt-core/src/jolt/subtable/zero_lsb.rs | 2 +- jolt-core/src/jolt/vm/bytecode.rs | 6 +- jolt-core/src/jolt/vm/instruction_lookups.rs | 29 +- jolt-core/src/jolt/vm/mod.rs | 6 +- jolt-core/src/jolt/vm/read_write_memory.rs | 13 +- jolt-core/src/jolt/vm/rv32i_vm.rs | 4 +- .../src/jolt/vm/timestamp_range_check.rs | 9 +- jolt-core/src/lasso/memory_checking.rs | 6 +- jolt-core/src/lasso/surge.rs | 6 +- jolt-core/src/poly/commitment/binius.rs | 4 +- .../src/poly/commitment/commitment_scheme.rs | 12 +- jolt-core/src/poly/commitment/hyperkzg.rs | 28 +- jolt-core/src/poly/commitment/hyrax.rs | 10 +- jolt-core/src/poly/commitment/kzg.rs | 13 +- jolt-core/src/poly/commitment/mock.rs | 11 +- jolt-core/src/poly/commitment/zeromorph.rs | 14 +- jolt-core/src/poly/dense_mlpoly.rs | 10 +- jolt-core/src/poly/eq_poly.rs | 6 +- jolt-core/src/poly/identity_poly.rs | 4 +- jolt-core/src/poly/structured_poly.rs | 8 +- jolt-core/src/poly/unipoly.rs | 4 +- jolt-core/src/r1cs/builder.rs | 24 +- jolt-core/src/r1cs/inputs.rs | 9 +- jolt-core/src/r1cs/jolt_constraints.rs | 4 +- jolt-core/src/r1cs/key.rs | 9 +- jolt-core/src/r1cs/ops.rs | 6 +- jolt-core/src/r1cs/spartan.rs | 6 +- jolt-core/src/r1cs/special_polys.rs | 12 +- jolt-core/src/subprotocols/grand_product.rs | 6 +- .../src/subprotocols/grand_product_quarks.rs | 6 +- jolt-core/src/subprotocols/sumcheck.rs | 8 +- jolt-core/src/utils/gaussian_elimination.rs | 2 +- jolt-core/src/utils/instruction_utils.rs | 2 +- jolt-core/src/utils/mod.rs | 128 -- jolt-core/src/utils/sol_types.rs | 2 +- jolt-core/src/utils/thread.rs | 2 +- jolt-svm-verifier/.gitignore | 2 + jolt-svm-verifier/package.json | 21 + jolt-svm-verifier/program/Cargo.toml | 25 + jolt-svm-verifier/program/src/constants.rs | 104 ++ jolt-svm-verifier/program/src/lib.rs | 138 ++ .../program/src/subprotocols/hyperkzg.rs | 205 +++ .../program/src/subprotocols/mod.rs | 1 + jolt-svm-verifier/program/src/utils.rs | 15 + jolt-svm-verifier/tests/jolt-verifier.ts | 38 + jolt-svm-verifier/tsconfig.json | 11 + jolt-svm-verifier/yarn.lock | 1113 +++++++++++++++++ jolt-types/Cargo.toml | 42 + {jolt-core => jolt-types}/src/field/ark.rs | 7 +- jolt-types/src/field/mod.rs | 93 ++ jolt-types/src/lib.rs | 4 + .../src/poly/commitment/hyperkzg/mod.rs | 18 + jolt-types/src/poly/commitment/kzg.rs | 9 + jolt-types/src/poly/commitment/mod.rs | 2 + jolt-types/src/poly/mod.rs | 1 + {jolt-core => jolt-types}/src/utils/errors.rs | 0 {jolt-core => jolt-types}/src/utils/math.rs | 0 jolt-types/src/utils/mod.rs | 133 ++ .../src/utils/transcript.rs | 0 116 files changed, 2213 insertions(+), 483 deletions(-) create mode 100644 jolt-svm-verifier/.gitignore create mode 100644 jolt-svm-verifier/package.json create mode 100644 jolt-svm-verifier/program/Cargo.toml create mode 100644 jolt-svm-verifier/program/src/constants.rs create mode 100644 jolt-svm-verifier/program/src/lib.rs create mode 100644 jolt-svm-verifier/program/src/subprotocols/hyperkzg.rs create mode 100644 jolt-svm-verifier/program/src/subprotocols/mod.rs create mode 100644 jolt-svm-verifier/program/src/utils.rs create mode 100644 jolt-svm-verifier/tests/jolt-verifier.ts create mode 100644 jolt-svm-verifier/tsconfig.json create mode 100644 jolt-svm-verifier/yarn.lock create mode 100644 jolt-types/Cargo.toml rename {jolt-core => jolt-types}/src/field/ark.rs (88%) create mode 100644 jolt-types/src/field/mod.rs create mode 100644 jolt-types/src/lib.rs create mode 100644 jolt-types/src/poly/commitment/hyperkzg/mod.rs create mode 100644 jolt-types/src/poly/commitment/kzg.rs create mode 100644 jolt-types/src/poly/commitment/mod.rs create mode 100644 jolt-types/src/poly/mod.rs rename {jolt-core => jolt-types}/src/utils/errors.rs (100%) rename {jolt-core => jolt-types}/src/utils/math.rs (100%) create mode 100644 jolt-types/src/utils/mod.rs rename {jolt-core => jolt-types}/src/utils/transcript.rs (100%) diff --git a/.gitignore b/.gitignore index 8e508ed1c..e2727a8f7 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 352f58ec0..2bcf58ec1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ keywords = ["SNARK", "cryptography", "proofs"] [workspace] members = [ "jolt-core", + "jolt-types", "tracer", "common", "jolt-sdk", diff --git a/jolt-core/Cargo.toml b/jolt-core/Cargo.toml index d4aa2f3ce..0fd28a725 100644 --- a/jolt-core/Cargo.toml +++ b/jolt-core/Cargo.toml @@ -20,6 +20,7 @@ license-file = "LICENSE" keywords = ["SNARK", "cryptography", "proofs"] [dependencies] +jolt-types = { path = "../jolt-types" } ark-bn254 = "0.4.0" ark-ec = { version = "0.4.2", default-features = false } ark-ff = { version = "0.4.2", default-features = false } diff --git a/jolt-core/src/benches/bench.rs b/jolt-core/src/benches/bench.rs index 27ec03faf..ac82cee0a 100644 --- a/jolt-core/src/benches/bench.rs +++ b/jolt-core/src/benches/bench.rs @@ -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; @@ -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)] diff --git a/jolt-core/src/field/binius.rs b/jolt-core/src/field/binius.rs index 5b7fb583d..509d51789 100644 --- a/jolt-core/src/field/binius.rs +++ b/jolt-core/src/field/binius.rs @@ -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 { @@ -126,16 +126,16 @@ impl JoltField for BiniusField { Self(self.0.square()) } - fn inverse(&self) -> Option { - 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::(bytes).unwrap(); Self(field_element.to_owned()) } + + fn inverse(&self) -> Option { + self.0.invert().map(Self) + } } impl Zero for BiniusField { diff --git a/jolt-core/src/field/mod.rs b/jolt-core/src/field/mod.rs index 02ee610c9..2cde28aca 100644 --- a/jolt-core/src/field/mod.rs +++ b/jolt-core/src/field/mod.rs @@ -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: - Add - + Sub - + Mul - + Div -{ -} - -pub trait JoltField: - 'static - + Sized - + Zero - + One - + Neg - + FieldOps - + for<'a> FieldOps<&'a Self, Self> - + AddAssign - + SubAssign - + MulAssign - + core::iter::Sum - + for<'a> core::iter::Sum<&'a Self> - + core::iter::Product - + for<'a> core::iter::Product<&'a Self> - + Eq - + Copy - + Sync - + Send - + Debug - + Default - + CanonicalSerialize - + CanonicalDeserialize -{ - const NUM_BYTES: usize; - fn random(rng: &mut R) -> Self; - - fn from_u64(n: u64) -> Option; - fn from_i64(val: i64) -> Self; - fn square(&self) -> Self; - fn from_bytes(bytes: &[u8]) -> Self; - fn inverse(&self) -> Option; - fn to_u64(&self) -> Option { - unimplemented!("conversion to u64 not implemented"); - } -} - -pub trait OptimizedMul: Sized + Mul { - 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 OptimizedMul 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; diff --git a/jolt-core/src/host/analyze.rs b/jolt-core/src/host/analyze.rs index 24fa9e976..9c98a4738 100644 --- a/jolt-core/src/host/analyze.rs +++ b/jolt-core/src/host/analyze.rs @@ -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 { diff --git a/jolt-core/src/host/mod.rs b/jolt-core/src/host/mod.rs index 5c2516f3f..dc701ff0f 100644 --- a/jolt-core/src/host/mod.rs +++ b/jolt-core/src/host/mod.rs @@ -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, @@ -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"))] diff --git a/jolt-core/src/jolt/instruction/add.rs b/jolt-core/src/jolt/instruction/add.rs index 5b27e6a6c..6627f5bb6 100644 --- a/jolt-core/src/jolt/instruction/add.rs +++ b/jolt-core/src/jolt/instruction/add.rs @@ -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(pub u64, pub u64); diff --git a/jolt-core/src/jolt/instruction/and.rs b/jolt-core/src/jolt/instruction/and.rs index ed8a6f6f1..4d2250348 100644 --- a/jolt-core/src/jolt/instruction/and.rs +++ b/jolt-core/src/jolt/instruction/and.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/beq.rs b/jolt-core/src/jolt/instruction/beq.rs index e6cda119c..d1db6827d 100644 --- a/jolt-core/src/jolt/instruction/beq.rs +++ b/jolt-core/src/jolt/instruction/beq.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/bge.rs b/jolt-core/src/jolt/instruction/bge.rs index 381b4877b..1f717c990 100644 --- a/jolt-core/src/jolt/instruction/bge.rs +++ b/jolt-core/src/jolt/instruction/bge.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/bgeu.rs b/jolt-core/src/jolt/instruction/bgeu.rs index cfa96a861..431e66046 100644 --- a/jolt-core/src/jolt/instruction/bgeu.rs +++ b/jolt-core/src/jolt/instruction/bgeu.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/bne.rs b/jolt-core/src/jolt/instruction/bne.rs index 6f91a1db9..45ee73fbc 100644 --- a/jolt-core/src/jolt/instruction/bne.rs +++ b/jolt-core/src/jolt/instruction/bne.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/lb.rs b/jolt-core/src/jolt/instruction/lb.rs index 7acb7e444..5384dceac 100644 --- a/jolt-core/src/jolt/instruction/lb.rs +++ b/jolt-core/src/jolt/instruction/lb.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/lh.rs b/jolt-core/src/jolt/instruction/lh.rs index 37b9e0969..2a72da2fc 100644 --- a/jolt-core/src/jolt/instruction/lh.rs +++ b/jolt-core/src/jolt/instruction/lh.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/mod.rs b/jolt-core/src/jolt/instruction/mod.rs index 60c5b1083..36f619d4f 100644 --- a/jolt-core/src/jolt/instruction/mod.rs +++ b/jolt-core/src/jolt/instruction/mod.rs @@ -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] diff --git a/jolt-core/src/jolt/instruction/mul.rs b/jolt-core/src/jolt/instruction/mul.rs index 7068d62e6..15fbe05ec 100644 --- a/jolt-core/src/jolt/instruction/mul.rs +++ b/jolt-core/src/jolt/instruction/mul.rs @@ -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(pub u64, pub u64); diff --git a/jolt-core/src/jolt/instruction/mulhu.rs b/jolt-core/src/jolt/instruction/mulhu.rs index cd611b43b..f45beda35 100644 --- a/jolt-core/src/jolt/instruction/mulhu.rs +++ b/jolt-core/src/jolt/instruction/mulhu.rs @@ -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(pub u64, pub u64); diff --git a/jolt-core/src/jolt/instruction/mulu.rs b/jolt-core/src/jolt/instruction/mulu.rs index 9a49c8cc0..206037337 100644 --- a/jolt-core/src/jolt/instruction/mulu.rs +++ b/jolt-core/src/jolt/instruction/mulu.rs @@ -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(pub u64, pub u64); diff --git a/jolt-core/src/jolt/instruction/or.rs b/jolt-core/src/jolt/instruction/or.rs index 8883782c1..aa76ed6a9 100644 --- a/jolt-core/src/jolt/instruction/or.rs +++ b/jolt-core/src/jolt/instruction/or.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/sb.rs b/jolt-core/src/jolt/instruction/sb.rs index f926c83a4..43f67ad90 100644 --- a/jolt-core/src/jolt/instruction/sb.rs +++ b/jolt-core/src/jolt/instruction/sb.rs @@ -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); diff --git a/jolt-core/src/jolt/instruction/sh.rs b/jolt-core/src/jolt/instruction/sh.rs index c231af277..7d381ced1 100644 --- a/jolt-core/src/jolt/instruction/sh.rs +++ b/jolt-core/src/jolt/instruction/sh.rs @@ -3,9 +3,9 @@ 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::chunk_operand_usize; +use jolt_types::field::JoltField; #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] pub struct SHInstruction(pub u64); diff --git a/jolt-core/src/jolt/instruction/sll.rs b/jolt-core/src/jolt/instruction/sll.rs index ee0240bea..fe53b20c9 100644 --- a/jolt-core/src/jolt/instruction/sll.rs +++ b/jolt-core/src/jolt/instruction/sll.rs @@ -4,11 +4,11 @@ use rand::RngCore; use serde::{Deserialize, Serialize}; use super::{JoltInstruction, SubtableIndices}; -use crate::field::JoltField; use crate::jolt::subtable::{sll::SllSubtable, LassoSubtable}; use crate::utils::instruction_utils::{ assert_valid_parameters, chunk_and_concatenate_for_shift, concatenate_lookups, }; +use jolt_types::field::JoltField; #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] pub struct SLLInstruction(pub u64, pub u64); diff --git a/jolt-core/src/jolt/instruction/slt.rs b/jolt-core/src/jolt/instruction/slt.rs index 1a809f249..72df0a2bd 100644 --- a/jolt-core/src/jolt/instruction/slt.rs +++ b/jolt-core/src/jolt/instruction/slt.rs @@ -1,4 +1,4 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/instruction/sltu.rs b/jolt-core/src/jolt/instruction/sltu.rs index 3dc45d0ca..f34826aa2 100644 --- a/jolt-core/src/jolt/instruction/sltu.rs +++ b/jolt-core/src/jolt/instruction/sltu.rs @@ -1,4 +1,4 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/instruction/sra.rs b/jolt-core/src/jolt/instruction/sra.rs index 75047c43e..ba7006ce8 100644 --- a/jolt-core/src/jolt/instruction/sra.rs +++ b/jolt-core/src/jolt/instruction/sra.rs @@ -1,4 +1,4 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/instruction/srl.rs b/jolt-core/src/jolt/instruction/srl.rs index 67f987689..8ae75d531 100644 --- a/jolt-core/src/jolt/instruction/srl.rs +++ b/jolt-core/src/jolt/instruction/srl.rs @@ -1,4 +1,4 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/instruction/sub.rs b/jolt-core/src/jolt/instruction/sub.rs index b5772536f..31a3d4ca5 100644 --- a/jolt-core/src/jolt/instruction/sub.rs +++ b/jolt-core/src/jolt/instruction/sub.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/instruction/sw.rs b/jolt-core/src/jolt/instruction/sw.rs index 50e723b14..ef56935df 100644 --- a/jolt-core/src/jolt/instruction/sw.rs +++ b/jolt-core/src/jolt/instruction/sw.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/instruction/virtual_advice.rs b/jolt-core/src/jolt/instruction/virtual_advice.rs index 47396f579..a6fb74e09 100644 --- a/jolt-core/src/jolt/instruction/virtual_advice.rs +++ b/jolt-core/src/jolt/instruction/virtual_advice.rs @@ -4,10 +4,10 @@ use rand::RngCore; use serde::{Deserialize, Serialize}; use super::{JoltInstruction, SubtableIndices}; -use crate::field::JoltField; use crate::jolt::subtable::truncate_overflow::TruncateOverflowSubtable; use crate::jolt::subtable::{identity::IdentitySubtable, LassoSubtable}; use crate::utils::instruction_utils::{chunk_operand_usize, concatenate_lookups}; +use jolt_types::field::JoltField; #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] pub struct ADVICEInstruction(pub u64); diff --git a/jolt-core/src/jolt/instruction/virtual_assert_lte.rs b/jolt-core/src/jolt/instruction/virtual_assert_lte.rs index f8114c71c..6960be132 100644 --- a/jolt-core/src/jolt/instruction/virtual_assert_lte.rs +++ b/jolt-core/src/jolt/instruction/virtual_assert_lte.rs @@ -4,10 +4,10 @@ use serde::{Deserialize, Serialize}; use super::{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 ASSERTLTEInstruction(pub u64, pub u64); diff --git a/jolt-core/src/jolt/instruction/virtual_assert_valid_div0.rs b/jolt-core/src/jolt/instruction/virtual_assert_valid_div0.rs index abd80663a..5d4153c60 100644 --- a/jolt-core/src/jolt/instruction/virtual_assert_valid_div0.rs +++ b/jolt-core/src/jolt/instruction/virtual_assert_valid_div0.rs @@ -1,16 +1,13 @@ -use crate::{ - field::JoltField, - jolt::subtable::{div_by_zero::DivByZeroSubtable, left_is_zero::LeftIsZeroSubtable}, -}; -use rand::prelude::StdRng; -use rand::RngCore; -use serde::{Deserialize, Serialize}; - use super::JoltInstruction; +use crate::jolt::subtable::{div_by_zero::DivByZeroSubtable, left_is_zero::LeftIsZeroSubtable}; use crate::{ jolt::{instruction::SubtableIndices, subtable::LassoSubtable}, utils::instruction_utils::chunk_and_concatenate_operands, }; +use jolt_types::field::JoltField; +use rand::prelude::StdRng; +use rand::RngCore; +use serde::{Deserialize, Serialize}; #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] /// (divisor, quotient) diff --git a/jolt-core/src/jolt/instruction/virtual_assert_valid_signed_remainder.rs b/jolt-core/src/jolt/instruction/virtual_assert_valid_signed_remainder.rs index 9dd548b5c..9b612731a 100644 --- a/jolt-core/src/jolt/instruction/virtual_assert_valid_signed_remainder.rs +++ b/jolt-core/src/jolt/instruction/virtual_assert_valid_signed_remainder.rs @@ -1,9 +1,5 @@ -use crate::{field::JoltField, jolt::subtable::right_is_zero::RightIsZeroSubtable}; -use rand::prelude::StdRng; -use rand::RngCore; -use serde::{Deserialize, Serialize}; - use super::{JoltInstruction, SubtableIndices}; +use crate::jolt::subtable::right_is_zero::RightIsZeroSubtable; use crate::{ jolt::subtable::{ eq::EqSubtable, eq_abs::EqAbsSubtable, left_is_zero::LeftIsZeroSubtable, @@ -12,6 +8,10 @@ use crate::{ }, utils::instruction_utils::chunk_and_concatenate_operands, }; +use jolt_types::field::JoltField; +use rand::prelude::StdRng; +use rand::RngCore; +use serde::{Deserialize, Serialize}; #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] /// (remainder, divisor) diff --git a/jolt-core/src/jolt/instruction/virtual_assert_valid_unsigned_remainder.rs b/jolt-core/src/jolt/instruction/virtual_assert_valid_unsigned_remainder.rs index 647ad84c8..68aca24b1 100644 --- a/jolt-core/src/jolt/instruction/virtual_assert_valid_unsigned_remainder.rs +++ b/jolt-core/src/jolt/instruction/virtual_assert_valid_unsigned_remainder.rs @@ -1,4 +1,5 @@ -use crate::{field::JoltField, jolt::subtable::right_is_zero::RightIsZeroSubtable}; +use crate::jolt::subtable::right_is_zero::RightIsZeroSubtable; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/instruction/virtual_move.rs b/jolt-core/src/jolt/instruction/virtual_move.rs index 77be2ac9c..3b2a9e53d 100644 --- a/jolt-core/src/jolt/instruction/virtual_move.rs +++ b/jolt-core/src/jolt/instruction/virtual_move.rs @@ -5,13 +5,13 @@ use serde::{Deserialize, Serialize}; use super::JoltInstruction; use crate::{ - field::JoltField, jolt::{ instruction::SubtableIndices, subtable::{identity::IdentitySubtable, LassoSubtable}, }, utils::instruction_utils::{chunk_operand_usize, concatenate_lookups}, }; +use jolt_types::field::JoltField; #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] pub struct MOVEInstruction(pub u64); diff --git a/jolt-core/src/jolt/instruction/virtual_movsign.rs b/jolt-core/src/jolt/instruction/virtual_movsign.rs index 01a854b02..b279a7837 100644 --- a/jolt-core/src/jolt/instruction/virtual_movsign.rs +++ b/jolt-core/src/jolt/instruction/virtual_movsign.rs @@ -5,13 +5,13 @@ use serde::{Deserialize, Serialize}; use super::JoltInstruction; use crate::{ - field::JoltField, jolt::{ instruction::SubtableIndices, subtable::{identity::IdentitySubtable, sign_extend::SignExtendSubtable, LassoSubtable}, }, utils::instruction_utils::{chunk_operand_usize, concatenate_lookups}, }; +use jolt_types::field::JoltField; #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] pub struct MOVSIGNInstruction(pub u64); diff --git a/jolt-core/src/jolt/instruction/xor.rs b/jolt-core/src/jolt/instruction/xor.rs index 2ba41d51e..0f45a7819 100644 --- a/jolt-core/src/jolt/instruction/xor.rs +++ b/jolt-core/src/jolt/instruction/xor.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use rand::prelude::StdRng; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/jolt-core/src/jolt/subtable/and.rs b/jolt-core/src/jolt/subtable/and.rs index 1ff52e9a2..99eea44ca 100644 --- a/jolt-core/src/jolt/subtable/and.rs +++ b/jolt-core/src/jolt/subtable/and.rs @@ -1,9 +1,9 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct AndSubtable { diff --git a/jolt-core/src/jolt/subtable/div_by_zero.rs b/jolt-core/src/jolt/subtable/div_by_zero.rs index 55db5f9fe..40952d998 100644 --- a/jolt-core/src/jolt/subtable/div_by_zero.rs +++ b/jolt-core/src/jolt/subtable/div_by_zero.rs @@ -1,5 +1,6 @@ -use crate::{field::JoltField, utils::split_bits}; use ark_std::log2; +use jolt_types::field::JoltField; +use jolt_types::utils::split_bits; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/eq.rs b/jolt-core/src/jolt/subtable/eq.rs index 7a39301ac..63e1d00c3 100644 --- a/jolt-core/src/jolt/subtable/eq.rs +++ b/jolt-core/src/jolt/subtable/eq.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/eq_abs.rs b/jolt-core/src/jolt/subtable/eq_abs.rs index c3ca4bd64..8f7c13fbb 100644 --- a/jolt-core/src/jolt/subtable/eq_abs.rs +++ b/jolt-core/src/jolt/subtable/eq_abs.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/identity.rs b/jolt-core/src/jolt/subtable/identity.rs index d44b1385b..c75748226 100644 --- a/jolt-core/src/jolt/subtable/identity.rs +++ b/jolt-core/src/jolt/subtable/identity.rs @@ -1,4 +1,4 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/left_is_zero.rs b/jolt-core/src/jolt/subtable/left_is_zero.rs index c7f2d4130..101864116 100644 --- a/jolt-core/src/jolt/subtable/left_is_zero.rs +++ b/jolt-core/src/jolt/subtable/left_is_zero.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/left_msb.rs b/jolt-core/src/jolt/subtable/left_msb.rs index b83b90d8c..32a8daec0 100644 --- a/jolt-core/src/jolt/subtable/left_msb.rs +++ b/jolt-core/src/jolt/subtable/left_msb.rs @@ -1,9 +1,9 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct LeftMSBSubtable { diff --git a/jolt-core/src/jolt/subtable/lt_abs.rs b/jolt-core/src/jolt/subtable/lt_abs.rs index 316d17ab4..b3d176c87 100644 --- a/jolt-core/src/jolt/subtable/lt_abs.rs +++ b/jolt-core/src/jolt/subtable/lt_abs.rs @@ -1,9 +1,9 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct LtAbsSubtable { diff --git a/jolt-core/src/jolt/subtable/ltu.rs b/jolt-core/src/jolt/subtable/ltu.rs index 989eaf78f..aec030168 100644 --- a/jolt-core/src/jolt/subtable/ltu.rs +++ b/jolt-core/src/jolt/subtable/ltu.rs @@ -1,9 +1,9 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct LtuSubtable { diff --git a/jolt-core/src/jolt/subtable/mod.rs b/jolt-core/src/jolt/subtable/mod.rs index 977f9b436..001184bcd 100644 --- a/jolt-core/src/jolt/subtable/mod.rs +++ b/jolt-core/src/jolt/subtable/mod.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use enum_dispatch::enum_dispatch; +use jolt_types::field::JoltField; use std::any::TypeId; use std::marker::Sync; use strum::{EnumCount, IntoEnumIterator}; diff --git a/jolt-core/src/jolt/subtable/or.rs b/jolt-core/src/jolt/subtable/or.rs index 0c5b25f4b..9c8f2199c 100644 --- a/jolt-core/src/jolt/subtable/or.rs +++ b/jolt-core/src/jolt/subtable/or.rs @@ -1,9 +1,9 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct OrSubtable { diff --git a/jolt-core/src/jolt/subtable/right_is_zero.rs b/jolt-core/src/jolt/subtable/right_is_zero.rs index f8b5faacc..7e3d5f4e5 100644 --- a/jolt-core/src/jolt/subtable/right_is_zero.rs +++ b/jolt-core/src/jolt/subtable/right_is_zero.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/right_msb.rs b/jolt-core/src/jolt/subtable/right_msb.rs index bbf6ed1d0..81facce92 100644 --- a/jolt-core/src/jolt/subtable/right_msb.rs +++ b/jolt-core/src/jolt/subtable/right_msb.rs @@ -1,9 +1,9 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct RightMSBSubtable { diff --git a/jolt-core/src/jolt/subtable/sign_extend.rs b/jolt-core/src/jolt/subtable/sign_extend.rs index 63743cd01..7c6f98455 100644 --- a/jolt-core/src/jolt/subtable/sign_extend.rs +++ b/jolt-core/src/jolt/subtable/sign_extend.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/sll.rs b/jolt-core/src/jolt/subtable/sll.rs index 27ab69e52..62fb7488c 100644 --- a/jolt-core/src/jolt/subtable/sll.rs +++ b/jolt-core/src/jolt/subtable/sll.rs @@ -1,11 +1,11 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::cmp::min; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::math::Math; -use crate::utils::split_bits; +use jolt_types::utils::math::Math; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct SllSubtable { diff --git a/jolt-core/src/jolt/subtable/sra_sign.rs b/jolt-core/src/jolt/subtable/sra_sign.rs index b995403d0..92351e10a 100644 --- a/jolt-core/src/jolt/subtable/sra_sign.rs +++ b/jolt-core/src/jolt/subtable/sra_sign.rs @@ -1,10 +1,10 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::math::Math; -use crate::utils::split_bits; +use jolt_types::utils::math::Math; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct SraSignSubtable { diff --git a/jolt-core/src/jolt/subtable/srl.rs b/jolt-core/src/jolt/subtable/srl.rs index 0b7769312..e1d8bbe65 100644 --- a/jolt-core/src/jolt/subtable/srl.rs +++ b/jolt-core/src/jolt/subtable/srl.rs @@ -1,11 +1,11 @@ -use crate::field::JoltField; use ark_std::log2; use std::cmp::min; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::math::Math; -use crate::utils::split_bits; +use jolt_types::utils::math::Math; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct SrlSubtable { diff --git a/jolt-core/src/jolt/subtable/truncate_overflow.rs b/jolt-core/src/jolt/subtable/truncate_overflow.rs index a3a8b2ac8..d76bb12de 100644 --- a/jolt-core/src/jolt/subtable/truncate_overflow.rs +++ b/jolt-core/src/jolt/subtable/truncate_overflow.rs @@ -1,8 +1,8 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/subtable/xor.rs b/jolt-core/src/jolt/subtable/xor.rs index cb4481e0f..528a5072d 100644 --- a/jolt-core/src/jolt/subtable/xor.rs +++ b/jolt-core/src/jolt/subtable/xor.rs @@ -1,9 +1,9 @@ -use crate::field::JoltField; use ark_std::log2; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; -use crate::utils::split_bits; +use jolt_types::utils::split_bits; #[derive(Default)] pub struct XorSubtable { diff --git a/jolt-core/src/jolt/subtable/zero_lsb.rs b/jolt-core/src/jolt/subtable/zero_lsb.rs index 0bfbefaf0..d11d58fb9 100644 --- a/jolt-core/src/jolt/subtable/zero_lsb.rs +++ b/jolt-core/src/jolt/subtable/zero_lsb.rs @@ -1,4 +1,4 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/vm/bytecode.rs b/jolt-core/src/jolt/vm/bytecode.rs index 007581ac0..07a8b485f 100644 --- a/jolt-core/src/jolt/vm/bytecode.rs +++ b/jolt-core/src/jolt/vm/bytecode.rs @@ -6,15 +6,15 @@ use serde::{Deserialize, Serialize}; use std::collections::HashSet; use std::{collections::HashMap, marker::PhantomData}; -use crate::field::JoltField; use crate::jolt::instruction::JoltInstructionSet; use crate::poly::commitment::commitment_scheme::{BatchType, CommitShape, CommitmentScheme}; use crate::poly::eq_poly::EqPolynomial; -use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use common::constants::{BYTES_PER_INSTRUCTION, RAM_START_ADDRESS, REGISTER_COUNT}; use common::rv_trace::ELFInstruction; use common::to_ram_address; +use jolt_types::field::JoltField; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use rayon::prelude::*; @@ -25,8 +25,8 @@ use crate::{ identity_poly::IdentityPolynomial, structured_poly::{StructuredCommitment, StructuredOpeningProof}, }, - utils::errors::ProofVerifyError, }; +use jolt_types::utils::errors::ProofVerifyError; use super::JoltTraceStep; diff --git a/jolt-core/src/jolt/vm/instruction_lookups.rs b/jolt-core/src/jolt/vm/instruction_lookups.rs index 2228cea21..bb2ab31fd 100644 --- a/jolt-core/src/jolt/vm/instruction_lookups.rs +++ b/jolt-core/src/jolt/vm/instruction_lookups.rs @@ -1,17 +1,8 @@ -use crate::subprotocols::grand_product::{BatchedGrandProduct, ToggledBatchedGrandProduct}; -use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use itertools::{interleave, Itertools}; -use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; -use rayon::prelude::*; -use std::marker::PhantomData; -use tracing::trace_span; - -use crate::field::JoltField; use crate::jolt::instruction::{JoltInstructionSet, SubtableIndices}; use crate::jolt::subtable::JoltSubtableSet; use crate::lasso::memory_checking::MultisetHashes; use crate::poly::commitment::commitment_scheme::{BatchType, CommitShape, CommitmentScheme}; -use crate::utils::mul_0_1_optimized; +use crate::subprotocols::grand_product::{BatchedGrandProduct, ToggledBatchedGrandProduct}; use crate::{ lasso::memory_checking::{MemoryCheckingProof, MemoryCheckingProver, MemoryCheckingVerifier}, poly::{ @@ -22,12 +13,20 @@ use crate::{ unipoly::{CompressedUniPoly, UniPoly}, }, subprotocols::sumcheck::SumcheckInstanceProof, - utils::{ - errors::ProofVerifyError, - math::Math, - transcript::{AppendToTranscript, ProofTranscript}, - }, }; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use itertools::{interleave, Itertools}; +use jolt_types::field::JoltField; +use jolt_types::utils::mul_0_1_optimized; +use jolt_types::utils::{ + errors::ProofVerifyError, + math::Math, + transcript::{AppendToTranscript, ProofTranscript}, +}; +use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; +use rayon::prelude::*; +use std::marker::PhantomData; +use tracing::trace_span; use super::JoltTraceStep; diff --git a/jolt-core/src/jolt/vm/mod.rs b/jolt-core/src/jolt/vm/mod.rs index d43908d6c..4f2a16cb9 100644 --- a/jolt-core/src/jolt/vm/mod.rs +++ b/jolt-core/src/jolt/vm/mod.rs @@ -1,12 +1,12 @@ #![allow(clippy::type_complexity)] -use crate::field::JoltField; use crate::r1cs::builder::CombinedUniformBuilder; use crate::r1cs::jolt_constraints::{construct_jolt_constraints, JoltIn}; use crate::r1cs::spartan::{self, UniformSpartanProof}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::log2; use common::constants::RAM_START_ADDRESS; +use jolt_types::field::JoltField; use rayon::prelude::*; use serde::{Deserialize, Serialize}; use strum::EnumCount; @@ -26,13 +26,13 @@ use crate::poly::commitment::commitment_scheme::{BatchType, CommitmentScheme}; use crate::poly::dense_mlpoly::DensePolynomial; use crate::poly::structured_poly::StructuredCommitment; use crate::r1cs::inputs::{R1CSCommitment, R1CSInputs, R1CSProof}; -use crate::utils::errors::ProofVerifyError; use crate::utils::thread::{drop_in_background_thread, unsafe_allocate_zero_vec}; -use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; use common::{ constants::MEMORY_OPS_PER_INSTRUCTION, rv_trace::{ELFInstruction, JoltDevice, MemoryOp}, }; +use jolt_types::utils::errors::ProofVerifyError; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use self::bytecode::BytecodePreprocessing; use self::instruction_lookups::{ diff --git a/jolt-core/src/jolt/vm/read_write_memory.rs b/jolt-core/src/jolt/vm/read_write_memory.rs index 95147ba6e..304826359 100644 --- a/jolt-core/src/jolt/vm/read_write_memory.rs +++ b/jolt-core/src/jolt/vm/read_write_memory.rs @@ -1,5 +1,5 @@ -use crate::field::JoltField; use crate::jolt::instruction::JoltInstructionSet; +use jolt_types::field::JoltField; use rand::rngs::StdRng; use rand::RngCore; use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; @@ -9,8 +9,9 @@ use std::marker::PhantomData; #[cfg(test)] use std::sync::{Arc, Mutex}; +use super::JoltTraceStep; +use super::{timestamp_range_check::TimestampValidityProof, JoltCommitments, JoltPolynomials}; use crate::poly::commitment::commitment_scheme::{BatchType, CommitShape, CommitmentScheme}; -use crate::utils::transcript::AppendToTranscript; use crate::{ lasso::memory_checking::{ MemoryCheckingProof, MemoryCheckingProver, MemoryCheckingVerifier, MultisetHashes, @@ -21,7 +22,6 @@ use crate::{ structured_poly::StructuredOpeningProof, }, subprotocols::sumcheck::SumcheckInstanceProof, - utils::{errors::ProofVerifyError, math::Math, mul_0_optimized, transcript::ProofTranscript}, }; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use common::constants::{ @@ -29,9 +29,10 @@ use common::constants::{ RAM_OPS_PER_INSTRUCTION, RAM_START_ADDRESS, REGISTER_COUNT, REG_OPS_PER_INSTRUCTION, }; use common::rv_trace::{JoltDevice, MemoryLayout, MemoryOp}; - -use super::JoltTraceStep; -use super::{timestamp_range_check::TimestampValidityProof, JoltCommitments, JoltPolynomials}; +use jolt_types::utils::transcript::AppendToTranscript; +use jolt_types::utils::{ + errors::ProofVerifyError, math::Math, mul_0_optimized, transcript::ProofTranscript, +}; pub fn random_memory_trace( memory_init: &Vec<(u64, u8)>, diff --git a/jolt-core/src/jolt/vm/rv32i_vm.rs b/jolt-core/src/jolt/vm/rv32i_vm.rs index d70535e80..2d883fa5a 100644 --- a/jolt-core/src/jolt/vm/rv32i_vm.rs +++ b/jolt-core/src/jolt/vm/rv32i_vm.rs @@ -1,4 +1,3 @@ -use crate::field::JoltField; use crate::jolt::instruction::virtual_assert_valid_div0::AssertValidDiv0Instruction; use crate::jolt::instruction::virtual_assert_valid_unsigned_remainder::AssertValidUnsignedRemainderInstruction; use crate::jolt::instruction::virtual_move::MOVEInstruction; @@ -8,6 +7,7 @@ use crate::poly::commitment::hyrax::HyraxScheme; use ark_bn254::{Fr, G1Projective}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use enum_dispatch::enum_dispatch; +use jolt_types::field::JoltField; use rand::{prelude::StdRng, RngCore}; use serde::{Deserialize, Serialize}; use std::any::TypeId; @@ -231,7 +231,6 @@ mod tests { use std::collections::HashSet; - use crate::field::JoltField; use crate::host; use crate::jolt::instruction::JoltInstruction; use crate::jolt::vm::rv32i_vm::{Jolt, RV32IJoltVM, C, M}; @@ -240,6 +239,7 @@ mod tests { use crate::poly::commitment::hyrax::HyraxScheme; use crate::poly::commitment::mock::MockCommitScheme; use crate::poly::commitment::zeromorph::Zeromorph; + use jolt_types::field::JoltField; use std::sync::Mutex; use strum::{EnumCount, IntoEnumIterator}; diff --git a/jolt-core/src/jolt/vm/timestamp_range_check.rs b/jolt-core/src/jolt/vm/timestamp_range_check.rs index 9851119b1..bf141a5ab 100644 --- a/jolt-core/src/jolt/vm/timestamp_range_check.rs +++ b/jolt-core/src/jolt/vm/timestamp_range_check.rs @@ -1,4 +1,3 @@ -use crate::field::JoltField; use crate::subprotocols::grand_product::{ BatchedDenseGrandProduct, BatchedGrandProduct, BatchedGrandProductLayer, BatchedGrandProductProof, @@ -7,6 +6,7 @@ use crate::utils::thread::drop_in_background_thread; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use common::constants::MEMORY_OPS_PER_INSTRUCTION; use itertools::interleave; +use jolt_types::field::JoltField; use rayon::iter::{ IntoParallelIterator, IntoParallelRefIterator, ParallelExtend, ParallelIterator, }; @@ -15,7 +15,11 @@ use std::collections::HashSet; use std::{iter::zip, marker::PhantomData}; use crate::poly::commitment::commitment_scheme::{BatchType, CommitShape, CommitmentScheme}; -use crate::utils::transcript::AppendToTranscript; +use jolt_types::utils::{ + errors::ProofVerifyError, mul_0_1_optimized, transcript::AppendToTranscript, + transcript::ProofTranscript, +}; + use crate::{ lasso::memory_checking::{ MemoryCheckingProof, MemoryCheckingProver, MemoryCheckingVerifier, MultisetHashes, @@ -27,7 +31,6 @@ use crate::{ identity_poly::IdentityPolynomial, structured_poly::{StructuredCommitment, StructuredOpeningProof}, }, - utils::{errors::ProofVerifyError, mul_0_1_optimized, transcript::ProofTranscript}, }; use super::read_write_memory::MemoryCommitment; diff --git a/jolt-core/src/lasso/memory_checking.rs b/jolt-core/src/lasso/memory_checking.rs index efcf361a9..b5a008efb 100644 --- a/jolt-core/src/lasso/memory_checking.rs +++ b/jolt-core/src/lasso/memory_checking.rs @@ -1,9 +1,7 @@ #![allow(clippy::too_many_arguments)] #![allow(clippy::type_complexity)] -use crate::utils::errors::ProofVerifyError; use crate::utils::thread::drop_in_background_thread; -use crate::utils::transcript::ProofTranscript; use crate::{ poly::{ commitment::commitment_scheme::CommitmentScheme, @@ -13,10 +11,12 @@ use crate::{ BatchedDenseGrandProduct, BatchedGrandProduct, BatchedGrandProductProof, }, }; +use jolt_types::utils::errors::ProofVerifyError; +use jolt_types::utils::transcript::ProofTranscript; -use crate::field::JoltField; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use itertools::interleave; +use jolt_types::field::JoltField; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use std::iter::zip; use std::marker::PhantomData; diff --git a/jolt-core/src/lasso/surge.rs b/jolt-core/src/lasso/surge.rs index 680d99c99..d8bfa9392 100644 --- a/jolt-core/src/lasso/surge.rs +++ b/jolt-core/src/lasso/surge.rs @@ -1,6 +1,6 @@ -use crate::field::JoltField; use crate::poly::commitment::commitment_scheme::BatchType; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use jolt_types::field::JoltField; use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::marker::{PhantomData, Sync}; @@ -15,7 +15,9 @@ use crate::{ structured_poly::{StructuredCommitment, StructuredOpeningProof}, }, subprotocols::sumcheck::SumcheckInstanceProof, - utils::{errors::ProofVerifyError, math::Math, mul_0_1_optimized, transcript::ProofTranscript}, +}; +use jolt_types::utils::{ + errors::ProofVerifyError, math::Math, mul_0_1_optimized, transcript::ProofTranscript, }; pub struct SurgePolys diff --git a/jolt-core/src/poly/commitment/binius.rs b/jolt-core/src/poly/commitment/binius.rs index 0c33ebc4c..c39901cf6 100644 --- a/jolt-core/src/poly/commitment/binius.rs +++ b/jolt-core/src/poly/commitment/binius.rs @@ -4,9 +4,9 @@ use crate::poly::commitment::commitment_scheme::BatchType; use crate::poly::commitment::commitment_scheme::CommitShape; use crate::poly::commitment::commitment_scheme::CommitmentScheme; use crate::poly::dense_mlpoly::DensePolynomial; -use crate::utils::errors::ProofVerifyError; -use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use jolt_types::utils::errors::ProofVerifyError; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; #[derive(Clone)] pub struct Binius128Scheme {} diff --git a/jolt-core/src/poly/commitment/commitment_scheme.rs b/jolt-core/src/poly/commitment/commitment_scheme.rs index e055847ef..7edcdbdcd 100644 --- a/jolt-core/src/poly/commitment/commitment_scheme.rs +++ b/jolt-core/src/poly/commitment/commitment_scheme.rs @@ -1,12 +1,10 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use crate::{ - field::JoltField, - poly::dense_mlpoly::DensePolynomial, - utils::{ - errors::ProofVerifyError, - transcript::{AppendToTranscript, ProofTranscript}, - }, +use crate::poly::dense_mlpoly::DensePolynomial; +use jolt_types::field::JoltField; +use jolt_types::utils::{ + errors::ProofVerifyError, + transcript::{AppendToTranscript, ProofTranscript}, }; #[derive(Clone, Debug)] diff --git a/jolt-core/src/poly/commitment/hyperkzg.rs b/jolt-core/src/poly/commitment/hyperkzg.rs index dea0d9906..86e089069 100644 --- a/jolt-core/src/poly/commitment/hyperkzg.rs +++ b/jolt-core/src/poly/commitment/hyperkzg.rs @@ -9,23 +9,23 @@ //! and within the KZG commitment scheme implementation itself). use super::{ commitment_scheme::{BatchType, CommitmentScheme}, - kzg::{KZGProverKey, KZGVerifierKey, UnivariateKZG}, + kzg::{KZGProverKey, UnivariateKZG}, }; -use crate::field; use crate::poly::commitment::commitment_scheme::CommitShape; -use crate::utils::mul_0_1_optimized; use crate::utils::thread::unsafe_allocate_zero_vec; use crate::{ msm::VariableBaseMSM, poly::{commitment::kzg::SRS, dense_mlpoly::DensePolynomial, unipoly::UniPoly}, - utils::{ - errors::ProofVerifyError, - transcript::{AppendToTranscript, ProofTranscript}, - }, }; use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::{One, Zero}; +use jolt_types::field; +use jolt_types::utils::mul_0_1_optimized; +use jolt_types::utils::{ + errors::ProofVerifyError, + transcript::{AppendToTranscript, ProofTranscript}, +}; use rand_chacha::ChaCha20Rng; use rand_core::{CryptoRng, RngCore, SeedableRng}; use rayon::iter::{ @@ -35,6 +35,8 @@ use rayon::iter::{ use std::{marker::PhantomData, sync::Arc}; use tracing::trace_span; +pub use jolt_types::poly::commitment::hyperkzg::{HyperKZGProof, HyperKZGVerifierKey}; + pub struct HyperKZGSRS(Arc>); impl HyperKZGSRS

{ @@ -53,11 +55,6 @@ pub struct HyperKZGProverKey { pub kzg_pk: KZGProverKey

, } -#[derive(Copy, Clone, Debug)] -pub struct HyperKZGVerifierKey { - pub kzg_vk: KZGVerifierKey

, -} - #[derive(Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize)] pub struct HyperKZGCommitment(pub P::G1Affine); @@ -67,13 +64,6 @@ impl AppendToTranscript for HyperKZGCommitment

{ } } -#[derive(Clone, CanonicalSerialize, CanonicalDeserialize, Debug)] -pub struct HyperKZGProof { - pub com: Vec, - pub w: Vec, - pub v: Vec>, -} - // On input f(x) and u compute the witness polynomial used to prove // that f(u) = v. The main part of this is to compute the // division (f(x) - f(u)) / (x - u), but we don't use a general diff --git a/jolt-core/src/poly/commitment/hyrax.rs b/jolt-core/src/poly/commitment/hyrax.rs index 17d9b4b0f..5228d7dcb 100644 --- a/jolt-core/src/poly/commitment/hyrax.rs +++ b/jolt-core/src/poly/commitment/hyrax.rs @@ -2,15 +2,15 @@ use std::marker::PhantomData; use super::commitment_scheme::{BatchType, CommitShape, CommitmentScheme}; use super::pedersen::{PedersenCommitment, PedersenGenerators}; -use crate::field::JoltField; use crate::poly::dense_mlpoly::DensePolynomial; use crate::poly::eq_poly::EqPolynomial; -use crate::utils::errors::ProofVerifyError; -use crate::utils::math::Math; -use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; -use crate::utils::{compute_dotproduct, mul_0_1_optimized}; use ark_ec::CurveGroup; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use jolt_types::field::JoltField; +use jolt_types::utils::errors::ProofVerifyError; +use jolt_types::utils::math::Math; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; +use jolt_types::utils::{compute_dotproduct, mul_0_1_optimized}; use num_integer::Roots; use rayon::prelude::*; use tracing::trace_span; diff --git a/jolt-core/src/poly/commitment/kzg.rs b/jolt-core/src/poly/commitment/kzg.rs index 12ee48d24..e3798a16a 100644 --- a/jolt-core/src/poly/commitment/kzg.rs +++ b/jolt-core/src/poly/commitment/kzg.rs @@ -1,15 +1,17 @@ -use crate::field::JoltField; use crate::msm::VariableBaseMSM; use crate::poly::unipoly::UniPoly; -use crate::utils::errors::ProofVerifyError; use ark_ec::scalar_mul::fixed_base::FixedBase; use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup}; use ark_ff::PrimeField; use ark_std::{One, UniformRand, Zero}; +use jolt_types::field::JoltField; +use jolt_types::utils::errors::ProofVerifyError; use rand_core::{CryptoRng, RngCore}; use std::marker::PhantomData; use std::sync::Arc; +pub use jolt_types::poly::commitment::kzg::KZGVerifierKey; + #[derive(Clone, Debug)] pub struct SRS { pub g1_powers: Vec, @@ -100,13 +102,6 @@ impl KZGProverKey

{ } } -#[derive(Clone, Copy, Debug)] -pub struct KZGVerifierKey { - pub g1: P::G1Affine, - pub g2: P::G2Affine, - pub beta_g2: P::G2Affine, -} - #[derive(Debug, Clone, Eq, PartialEq, Default)] pub struct UnivariateKZG { _phantom: PhantomData

, diff --git a/jolt-core/src/poly/commitment/mock.rs b/jolt-core/src/poly/commitment/mock.rs index bee321c6a..59f443911 100644 --- a/jolt-core/src/poly/commitment/mock.rs +++ b/jolt-core/src/poly/commitment/mock.rs @@ -2,13 +2,10 @@ use std::marker::PhantomData; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use crate::{ - field::JoltField, - poly::dense_mlpoly::DensePolynomial, - utils::{ - errors::ProofVerifyError, - transcript::{AppendToTranscript, ProofTranscript}, - }, +use crate::{field::JoltField, poly::dense_mlpoly::DensePolynomial}; +use jolt_types::utils::{ + errors::ProofVerifyError, + transcript::{AppendToTranscript, ProofTranscript}, }; use super::commitment_scheme::{BatchType, CommitShape, CommitmentScheme}; diff --git a/jolt-core/src/poly/commitment/zeromorph.rs b/jolt-core/src/poly/commitment/zeromorph.rs index 38594720e..13c5783be 100644 --- a/jolt-core/src/poly/commitment/zeromorph.rs +++ b/jolt-core/src/poly/commitment/zeromorph.rs @@ -3,20 +3,20 @@ use std::{iter, marker::PhantomData}; -use crate::field; use crate::msm::VariableBaseMSM; use crate::poly::{dense_mlpoly::DensePolynomial, unipoly::UniPoly}; -use crate::utils::mul_0_1_optimized; use crate::utils::thread::unsafe_allocate_zero_vec; -use crate::utils::{ - errors::ProofVerifyError, - transcript::{AppendToTranscript, ProofTranscript}, -}; use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup}; use ark_ff::{batch_inversion, Field}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::{One, Zero}; use itertools::izip; +use jolt_types::field; +use jolt_types::utils::{ + errors::ProofVerifyError, + mul_0_1_optimized, + transcript::{AppendToTranscript, ProofTranscript}, +}; use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng}; use rand_core::{CryptoRng, RngCore}; use std::sync::Arc; @@ -596,10 +596,10 @@ where #[cfg(test)] mod test { use super::*; - use crate::utils::math::Math; use ark_bn254::{Bn254, Fr}; use ark_ff::{BigInt, Zero}; use ark_std::{test_rng, UniformRand}; + use jolt_types::utils::math::Math; use rand_core::SeedableRng; // Evaluate Phi_k(x) = \sum_{i=0}^k x^i using the direct inefficent formula diff --git a/jolt-core/src/poly/dense_mlpoly.rs b/jolt-core/src/poly/dense_mlpoly.rs index f28d4ff2a..67489a87c 100644 --- a/jolt-core/src/poly/dense_mlpoly.rs +++ b/jolt-core/src/poly/dense_mlpoly.rs @@ -1,12 +1,12 @@ #![allow(clippy::too_many_arguments)] use crate::poly::eq_poly::EqPolynomial; use crate::utils::thread::{drop_in_background_thread, unsafe_allocate_zero_vec}; -use crate::utils::{self, compute_dotproduct, compute_dotproduct_low_optimized}; +use jolt_types::utils::{compute_dotproduct, compute_dotproduct_low_optimized}; -use crate::field::JoltField; -use crate::utils::math::Math; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use core::ops::Index; +use jolt_types::field::JoltField; +use jolt_types::utils::math::Math; use rand_core::{CryptoRng, RngCore}; use rayon::prelude::*; use std::ops::{AddAssign, Mul}; @@ -21,7 +21,7 @@ pub struct DensePolynomial { impl DensePolynomial { pub fn new(Z: Vec) -> Self { assert!( - utils::is_power_of_two(Z.len()), + jolt_types::utils::is_power_of_two(Z.len()), "Dense multi-linear polynomials must be made from a power of 2 (not {})", Z.len() ); @@ -36,7 +36,7 @@ impl DensePolynomial { pub fn new_padded(evals: Vec) -> Self { // Pad non-power-2 evaluations to fill out the dense multilinear polynomial let mut poly_evals = evals; - while !(utils::is_power_of_two(poly_evals.len())) { + while !(jolt_types::utils::is_power_of_two(poly_evals.len())) { poly_evals.push(F::zero()); } diff --git a/jolt-core/src/poly/eq_poly.rs b/jolt-core/src/poly/eq_poly.rs index adfc8964d..6f7e9e6b2 100644 --- a/jolt-core/src/poly/eq_poly.rs +++ b/jolt-core/src/poly/eq_poly.rs @@ -1,8 +1,8 @@ -use crate::field::JoltField; +use crate::utils::thread::unsafe_allocate_zero_vec; +use jolt_types::field::JoltField; +use jolt_types::utils::math::Math; use rayon::prelude::*; -use crate::utils::{math::Math, thread::unsafe_allocate_zero_vec}; - pub struct EqPolynomial { r: Vec, } diff --git a/jolt-core/src/poly/identity_poly.rs b/jolt-core/src/poly/identity_poly.rs index 0758cf337..3c95622a3 100644 --- a/jolt-core/src/poly/identity_poly.rs +++ b/jolt-core/src/poly/identity_poly.rs @@ -1,6 +1,6 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; -use crate::utils::math::Math; +use jolt_types::utils::math::Math; pub struct IdentityPolynomial { size_point: usize, diff --git a/jolt-core/src/poly/structured_poly.rs b/jolt-core/src/poly/structured_poly.rs index 872a70b52..fe65a9ae0 100644 --- a/jolt-core/src/poly/structured_poly.rs +++ b/jolt-core/src/poly/structured_poly.rs @@ -1,11 +1,9 @@ -use crate::field::JoltField; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use jolt_types::field::JoltField; use super::commitment::commitment_scheme::CommitmentScheme; -use crate::{ - lasso::memory_checking::NoPreprocessing, - utils::{errors::ProofVerifyError, transcript::ProofTranscript}, -}; +use crate::lasso::memory_checking::NoPreprocessing; +use jolt_types::utils::{errors::ProofVerifyError, transcript::ProofTranscript}; /// Encapsulates the pattern of a collection of related polynomials (e.g. those used to /// prove instruction lookups in Jolt) that can be "batched" for more efficient diff --git a/jolt-core/src/poly/unipoly.rs b/jolt-core/src/poly/unipoly.rs index bdf52232e..e145ce1be 100644 --- a/jolt-core/src/poly/unipoly.rs +++ b/jolt-core/src/poly/unipoly.rs @@ -1,11 +1,11 @@ #![allow(dead_code)] -use crate::field::JoltField; +use jolt_types::field::JoltField; use std::cmp::Ordering; use std::ops::{AddAssign, Index, IndexMut, Mul, MulAssign}; use crate::utils::gaussian_elimination::gaussian_elimination; -use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; use ark_serialize::*; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use rand_core::{CryptoRng, RngCore}; use rayon::iter::{IntoParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; diff --git a/jolt-core/src/r1cs/builder.rs b/jolt-core/src/r1cs/builder.rs index bbc9e8dd2..62be2cdfe 100644 --- a/jolt-core/src/r1cs/builder.rs +++ b/jolt-core/src/r1cs/builder.rs @@ -1,26 +1,22 @@ +use super::{ + key::{NonUniformR1CS, NonUniformR1CSConstraint, SparseEqualityItem}, + ops::{ConstraintInput, Term, Variable, LC}, + special_polys::SparsePolynomial, +}; use crate::{ - field::JoltField, r1cs::key::{SparseConstraints, UniformR1CS}, - utils::{ - math::Math, - mul_0_1_optimized, - thread::{ - drop_in_background_thread, par_flatten_triple, unsafe_allocate_sparse_zero_vec, - unsafe_allocate_zero_vec, - }, + utils::thread::{ + drop_in_background_thread, par_flatten_triple, unsafe_allocate_sparse_zero_vec, + unsafe_allocate_zero_vec, }, }; #[allow(unused_imports)] // clippy thinks these aren't needed lol use ark_std::{One, Zero}; +use jolt_types::field::JoltField; +use jolt_types::utils::{math::Math, mul_0_1_optimized}; use rayon::prelude::*; use std::{collections::HashMap, fmt::Debug}; -use super::{ - key::{NonUniformR1CS, NonUniformR1CSConstraint, SparseEqualityItem}, - ops::{ConstraintInput, Term, Variable, LC}, - special_polys::SparsePolynomial, -}; - pub trait R1CSConstraintBuilder { type Inputs: ConstraintInput; diff --git a/jolt-core/src/r1cs/inputs.rs b/jolt-core/src/r1cs/inputs.rs index cb5dbbaaa..a453680a5 100644 --- a/jolt-core/src/r1cs/inputs.rs +++ b/jolt-core/src/r1cs/inputs.rs @@ -4,20 +4,17 @@ clippy::too_many_arguments )] +use crate::jolt::vm::{rv32i_vm::RV32I, JoltCommitments}; use crate::poly::commitment::commitment_scheme::CommitmentScheme; use crate::r1cs::jolt_constraints::JoltIn; -use crate::utils::transcript::AppendToTranscript; -use crate::{ - jolt::vm::{rv32i_vm::RV32I, JoltCommitments}, - utils::transcript::ProofTranscript, -}; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use super::key::UniformSpartanKey; use super::spartan::{SpartanError, UniformSpartanProof}; -use crate::field::JoltField; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use common::constants::MEMORY_OPS_PER_INSTRUCTION; +use jolt_types::field::JoltField; use rayon::prelude::*; use strum::EnumCount; diff --git a/jolt-core/src/r1cs/jolt_constraints.rs b/jolt-core/src/r1cs/jolt_constraints.rs index 5fb0d8711..f22aae590 100644 --- a/jolt-core/src/r1cs/jolt_constraints.rs +++ b/jolt-core/src/r1cs/jolt_constraints.rs @@ -1,7 +1,7 @@ use crate::{ - assert_static_aux_index, field::JoltField, impl_r1cs_input_lc_conversions, input_range, - jolt::vm::rv32i_vm::C, + assert_static_aux_index, impl_r1cs_input_lc_conversions, input_range, jolt::vm::rv32i_vm::C, }; +use jolt_types::field::JoltField; use super::{ builder::{CombinedUniformBuilder, OffsetEqConstraint, R1CSBuilder, R1CSConstraintBuilder}, diff --git a/jolt-core/src/r1cs/key.rs b/jolt-core/src/r1cs/key.rs index d26005d4c..e8a86d08a 100644 --- a/jolt-core/src/r1cs/key.rs +++ b/jolt-core/src/r1cs/key.rs @@ -2,16 +2,16 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use sha3::Sha3_256; use crate::{ - field::JoltField, poly::eq_poly::EqPolynomial, r1cs::special_polys::{eq_plus_one, SparsePolynomial}, - utils::{index_to_field_bitvector, mul_0_1_optimized, thread::unsafe_allocate_zero_vec}, + utils::thread::unsafe_allocate_zero_vec, }; +use jolt_types::field::JoltField; use super::{builder::CombinedUniformBuilder, ops::ConstraintInput}; use sha3::Digest; -use crate::utils::math::Math; +use jolt_types::utils::{index_to_field_bitvector, math::Math, mul_0_1_optimized}; use rayon::prelude::*; @@ -439,8 +439,9 @@ mod test { materialize_full_uniform, simp_test_big_matrices, simp_test_builder_key, TestInputs, }, }, - utils::{index_to_field_bitvector, math::Math}, + utils::index_to_field_bitvector, }; + use jolt_types::utils::math::Math; use strum::EnumCount; #[test] diff --git a/jolt-core/src/r1cs/ops.rs b/jolt-core/src/r1cs/ops.rs index 48d6c06bf..43585cab2 100644 --- a/jolt-core/src/r1cs/ops.rs +++ b/jolt-core/src/r1cs/ops.rs @@ -1,10 +1,8 @@ //! Defines the Linear Combination (LC) object and associated operations. //! A LinearCombination is a vector of Terms, where each Term is a pair of a Variable and a coefficient. -use crate::{ - field::{JoltField, OptimizedMul}, - utils::thread::unsafe_allocate_zero_vec, -}; +use crate::utils::thread::unsafe_allocate_zero_vec; +use jolt_types::field::{JoltField, OptimizedMul}; use rayon::prelude::*; use std::fmt::Debug; use std::hash::Hash; diff --git a/jolt-core/src/r1cs/spartan.rs b/jolt-core/src/r1cs/spartan.rs index fc32ea251..c65f670ea 100644 --- a/jolt-core/src/r1cs/spartan.rs +++ b/jolt-core/src/r1cs/spartan.rs @@ -1,16 +1,16 @@ #![allow(clippy::len_without_is_empty)] -use crate::field::JoltField; use crate::poly::commitment::commitment_scheme::BatchType; use crate::poly::commitment::commitment_scheme::CommitmentScheme; use crate::r1cs::key::UniformSpartanKey; use crate::r1cs::special_polys::SegmentedPaddedWitness; -use crate::utils::math::Math; use crate::utils::thread::drop_in_background_thread; +use jolt_types::field::JoltField; +use jolt_types::utils::math::Math; -use crate::utils::transcript::ProofTranscript; use ark_serialize::CanonicalDeserialize; use ark_serialize::CanonicalSerialize; +use jolt_types::utils::transcript::ProofTranscript; use thiserror::Error; diff --git a/jolt-core/src/r1cs/special_polys.rs b/jolt-core/src/r1cs/special_polys.rs index e643d728f..3c659ccd3 100644 --- a/jolt-core/src/r1cs/special_polys.rs +++ b/jolt-core/src/r1cs/special_polys.rs @@ -1,13 +1,9 @@ use crate::{ - field::JoltField, poly::{dense_mlpoly::DensePolynomial, eq_poly::EqPolynomial}, - utils::{ - compute_dotproduct_low_optimized, - math::Math, - mul_0_1_optimized, - thread::{drop_in_background_thread, unsafe_allocate_sparse_zero_vec}, - }, + utils::thread::{drop_in_background_thread, unsafe_allocate_sparse_zero_vec}, }; +use jolt_types::field::JoltField; +use jolt_types::utils::{compute_dotproduct_low_optimized, math::Math, mul_0_1_optimized}; use num_integer::Integer; use rayon::prelude::*; @@ -218,7 +214,7 @@ impl SparsePolynomial { #[cfg(test)] #[tracing::instrument(skip_all)] pub fn to_dense(self) -> DensePolynomial { - use crate::utils::{math::Math, thread::unsafe_allocate_zero_vec}; + use crate::utils::thread::unsafe_allocate_zero_vec; let mut evals = unsafe_allocate_zero_vec(self.num_vars.pow2()); diff --git a/jolt-core/src/subprotocols/grand_product.rs b/jolt-core/src/subprotocols/grand_product.rs index 9a16cfb81..063f265a8 100644 --- a/jolt-core/src/subprotocols/grand_product.rs +++ b/jolt-core/src/subprotocols/grand_product.rs @@ -1,15 +1,15 @@ use super::grand_product_quarks::QuarkGrandProductProof; use super::sumcheck::{BatchedCubicSumcheck, SumcheckInstanceProof}; -use crate::field::{JoltField, OptimizedMul}; use crate::poly::commitment::commitment_scheme::CommitmentScheme; use crate::poly::eq_poly::EqPolynomial; use crate::poly::{dense_mlpoly::DensePolynomial, unipoly::UniPoly}; -use crate::utils::math::Math; use crate::utils::thread::drop_in_background_thread; -use crate::utils::transcript::ProofTranscript; use ark_ff::Zero; use ark_serialize::*; use itertools::Itertools; +use jolt_types::field::{JoltField, OptimizedMul}; +use jolt_types::utils::math::Math; +use jolt_types::utils::transcript::ProofTranscript; use rayon::prelude::*; #[derive(CanonicalSerialize, CanonicalDeserialize)] diff --git a/jolt-core/src/subprotocols/grand_product_quarks.rs b/jolt-core/src/subprotocols/grand_product_quarks.rs index 9647f4b4c..b724c91ea 100644 --- a/jolt-core/src/subprotocols/grand_product_quarks.rs +++ b/jolt-core/src/subprotocols/grand_product_quarks.rs @@ -3,15 +3,15 @@ use super::grand_product::{ BatchedGrandProductProof, }; use super::sumcheck::SumcheckInstanceProof; -use crate::field::JoltField; use crate::poly::commitment::commitment_scheme::{BatchType, CommitmentScheme}; use crate::poly::dense_mlpoly::DensePolynomial; use crate::poly::eq_poly::EqPolynomial; -use crate::utils::math::Math; -use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; use ark_serialize::*; use ark_std::{One, Zero}; use itertools::Itertools; +use jolt_types::field::JoltField; +use jolt_types::utils::math::Math; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use rayon::prelude::*; use thiserror::Error; diff --git a/jolt-core/src/subprotocols/sumcheck.rs b/jolt-core/src/subprotocols/sumcheck.rs index ca506f545..747bc7590 100644 --- a/jolt-core/src/subprotocols/sumcheck.rs +++ b/jolt-core/src/subprotocols/sumcheck.rs @@ -1,15 +1,15 @@ #![allow(clippy::too_many_arguments)] #![allow(clippy::type_complexity)] -use crate::field::JoltField; use crate::poly::dense_mlpoly::DensePolynomial; use crate::poly::unipoly::{CompressedUniPoly, UniPoly}; use crate::r1cs::special_polys::{IndexablePoly, SparsePolynomial, SparseTripleIterator}; -use crate::utils::errors::ProofVerifyError; -use crate::utils::mul_0_optimized; use crate::utils::thread::drop_in_background_thread; -use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; use ark_serialize::*; +use jolt_types::field::JoltField; +use jolt_types::utils::errors::ProofVerifyError; +use jolt_types::utils::mul_0_optimized; +use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use rayon::prelude::*; /// Batched cubic sumcheck used in grand products diff --git a/jolt-core/src/utils/gaussian_elimination.rs b/jolt-core/src/utils/gaussian_elimination.rs index 0bbe78f47..ba5ad8bd2 100644 --- a/jolt-core/src/utils/gaussian_elimination.rs +++ b/jolt-core/src/utils/gaussian_elimination.rs @@ -4,7 +4,7 @@ // Wikipedia reference: augmented matrix: https://en.wikipedia.org/wiki/Augmented_matrix // Wikipedia reference: algorithm: https://en.wikipedia.org/wiki/Gaussian_elimination -use crate::field::JoltField; +use jolt_types::field::JoltField; pub fn gaussian_elimination(matrix: &mut [Vec]) -> Vec { let size = matrix.len(); diff --git a/jolt-core/src/utils/instruction_utils.rs b/jolt-core/src/utils/instruction_utils.rs index f52c2b7d2..1f388c84d 100644 --- a/jolt-core/src/utils/instruction_utils.rs +++ b/jolt-core/src/utils/instruction_utils.rs @@ -1,4 +1,4 @@ -use crate::field::JoltField; +use jolt_types::field::JoltField; /// Asserts that `C * log_M` is at least as large as the word size. pub fn assert_valid_parameters(word_size: usize, C: usize, log_M: usize) { diff --git a/jolt-core/src/utils/mod.rs b/jolt-core/src/utils/mod.rs index ba4fca1db..57881a121 100644 --- a/jolt-core/src/utils/mod.rs +++ b/jolt-core/src/utils/mod.rs @@ -1,134 +1,6 @@ #![allow(dead_code)] -use crate::field::JoltField; - -use ark_std::test_rng; -use rayon::prelude::*; - -pub mod errors; pub mod gaussian_elimination; pub mod instruction_utils; -pub mod math; pub mod profiling; pub mod sol_types; pub mod thread; -pub mod transcript; - -/// Converts an integer value to a bitvector (all values {0,1}) of field elements. -/// Note: ordering has the MSB in the highest index. All of the following represent the integer 1: -/// - [1] -/// - [0, 0, 1] -/// - [0, 0, 0, 0, 0, 0, 0, 1] -/// ```ignore -/// use jolt_core::utils::index_to_field_bitvector; -/// # use ark_bn254::Fr; -/// # use ark_std::{One, Zero}; -/// let zero = Fr::zero(); -/// let one = Fr::one(); -/// -/// assert_eq!(index_to_field_bitvector::(1, 1), vec![one]); -/// assert_eq!(index_to_field_bitvector::(1, 3), vec![zero, zero, one]); -/// assert_eq!(index_to_field_bitvector::(1, 7), vec![zero, zero, zero, zero, zero, zero, one]); -/// ``` -pub fn index_to_field_bitvector(value: usize, bits: usize) -> Vec { - assert!(value < 1 << bits); - - let mut bitvector: Vec = Vec::with_capacity(bits); - - for i in (0..bits).rev() { - if (value >> i) & 1 == 1 { - bitvector.push(F::one()); - } else { - bitvector.push(F::zero()); - } - } - bitvector -} - -#[tracing::instrument(skip_all)] -pub fn compute_dotproduct(a: &[F], b: &[F]) -> F { - a.par_iter() - .zip_eq(b.par_iter()) - .map(|(a_i, b_i)| *a_i * *b_i) - .sum() -} - -/// Compute dotproduct optimized for values being 0 / 1 -#[tracing::instrument(skip_all)] -pub fn compute_dotproduct_low_optimized(a: &[F], b: &[F]) -> F { - a.par_iter() - .zip_eq(b.par_iter()) - .map(|(a_i, b_i)| mul_0_1_optimized(a_i, b_i)) - .sum() -} - -#[inline(always)] -pub fn mul_0_1_optimized(a: &F, b: &F) -> F { - if a.is_zero() || b.is_zero() { - F::zero() - } else if a.is_one() { - *b - } else if b.is_one() { - *a - } else { - *a * *b - } -} - -#[inline(always)] -pub fn mul_0_optimized(likely_zero: &F, x: &F) -> F { - if likely_zero.is_zero() { - F::zero() - } else { - *likely_zero * *x - } -} - -/// Checks if `num` is a power of 2. -pub fn is_power_of_two(num: usize) -> bool { - num != 0 && (num & (num - 1)) == 0 -} - -/// Take the first two `num_bits` chunks of `item` (from the right / LSB) and return them as a tuple `(high_chunk, low_chunk)`. -/// -/// If `item` is shorter than `2 * num_bits`, the remaining bits are zero-padded. -/// -/// If `item` is longer than `2 * num_bits`, the remaining bits are discarded. -/// -/// # Examples -/// -/// ``` -/// use jolt_core::utils::split_bits; -/// -/// assert_eq!(split_bits(0b101000, 2), (0b10, 0b00)); -/// assert_eq!(split_bits(0b101000, 3), (0b101, 0b000)); -/// assert_eq!(split_bits(0b101000, 4), (0b0010, 0b1000)); -/// ``` -pub fn split_bits(item: usize, num_bits: usize) -> (usize, usize) { - let max_value = (1 << num_bits) - 1; // Calculate the maximum value that can be represented with num_bits - - let low_chunk = item & max_value; // Extract the lower bits - let high_chunk = (item >> num_bits) & max_value; // Shift the item to the right and extract the next set of bits - - (high_chunk, low_chunk) -} - -/// Generate a random point with `memory_bits` field elements. -pub fn gen_random_point(memory_bits: usize) -> Vec { - let mut rng = test_rng(); - let mut r_i: Vec = Vec::with_capacity(memory_bits); - for _ in 0..memory_bits { - r_i.push(F::random(&mut rng)); - } - r_i -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn split() { - assert_eq!(split_bits(0b00_01, 2), (0, 1)); - assert_eq!(split_bits(0b10_01, 2), (2, 1)); - } -} diff --git a/jolt-core/src/utils/sol_types.rs b/jolt-core/src/utils/sol_types.rs index 1de10c4d9..a1272092e 100644 --- a/jolt-core/src/utils/sol_types.rs +++ b/jolt-core/src/utils/sol_types.rs @@ -2,7 +2,6 @@ use ark_bn254::Bn254; use ark_ff::BigInteger; use ark_ff::PrimeField; -use crate::field::JoltField; use crate::poly::commitment::hyperkzg::{HyperKZG, HyperKZGProof, HyperKZGVerifierKey}; use crate::r1cs::spartan::UniformSpartanProof; use crate::subprotocols::grand_product::BatchedGrandProductLayerProof; @@ -13,6 +12,7 @@ use alloy_sol_types::sol; use ark_bn254::FrConfig; use ark_ff::Fp; use ark_ff::MontBackend; +use jolt_types::field::JoltField; sol!(struct HyperKZGProofSol { uint256[] com; // G1 points represented pairwise diff --git a/jolt-core/src/utils/thread.rs b/jolt-core/src/utils/thread.rs index 92754a095..aa5b88b12 100644 --- a/jolt-core/src/utils/thread.rs +++ b/jolt-core/src/utils/thread.rs @@ -1,7 +1,7 @@ use rayon::prelude::*; use std::thread::{self, JoinHandle}; -use crate::field::JoltField; +use jolt_types::field::JoltField; pub fn drop_in_background_thread(data: T) where diff --git a/jolt-svm-verifier/.gitignore b/jolt-svm-verifier/.gitignore new file mode 100644 index 000000000..c9a28ec4d --- /dev/null +++ b/jolt-svm-verifier/.gitignore @@ -0,0 +1,2 @@ +#ignore test outputs +tests/fixtures/ \ No newline at end of file diff --git a/jolt-svm-verifier/package.json b/jolt-svm-verifier/package.json new file mode 100644 index 000000000..34a69c47b --- /dev/null +++ b/jolt-svm-verifier/package.json @@ -0,0 +1,21 @@ +{ + "scripts": { + "test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/*", + "build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test", + "build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so", + "deploy": "solana program deploy ./program/target/so/hello_solana_program.so" + }, + "dependencies": { + "@solana/web3.js": "^1.47.3" + }, + "devDependencies": { + "@types/bn.js": "^5.1.0", + "@types/chai": "^4.3.1", + "@types/mocha": "^9.1.1", + "chai": "^4.3.4", + "mocha": "^9.0.3", + "solana-bankrun": "^0.3.0", + "ts-mocha": "^10.0.0", + "typescript": "^4.3.5" + } +} \ No newline at end of file diff --git a/jolt-svm-verifier/program/Cargo.toml b/jolt-svm-verifier/program/Cargo.toml new file mode 100644 index 000000000..4bdaf9369 --- /dev/null +++ b/jolt-svm-verifier/program/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "jolt-svm-verifier" +version = "0.1.0" +description = "SVM program to verify JOLT proofs" +edition = "2021" + +[workspace] +members = [ +] + +[lib] +crate-type = ["cdylib", "lib"] + +[dependencies] +ark-serialize = "0.4.2" +ark-bn254 = { version = "0.4.0", default-features = false } +ark-ec = { version = "0.4.2", default-features = false } +ark-std = { version = "0.4.0", default-features = false } +ark-ff = { version = "0.4.2", default-features = false } +array-bytes = "6.2.3" +solana-program = "2.0.6" +jolt-types = { path = "../../jolt-types", default-features = false } + +[target.'cfg(not(target_os = "solana"))'.dependencies] +jolt-types = { path = "../../jolt-types" } \ No newline at end of file diff --git a/jolt-svm-verifier/program/src/constants.rs b/jolt-svm-verifier/program/src/constants.rs new file mode 100644 index 000000000..a3f43e229 --- /dev/null +++ b/jolt-svm-verifier/program/src/constants.rs @@ -0,0 +1,104 @@ +pub const POINT_BYTES: [u8; 72] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +]; +pub const EVAL_BYTES: [u8; 32] = [ + 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +]; +pub const V_POS_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x53, 0x70, 0xf2, 0xee, 0x18, 0x3d, 0x60, 0x13, 0xea, 0x65, 0xf4, 0xf7, 0x30, 0xe2, 0xc7, + 0xbf, 0xd4, 0x62, 0xdf, 0x8a, 0xbe, 0xec, 0x65, 0xed, 0x4b, 0x2d, 0x07, 0xb5, 0x3a, 0xa0, 0x2c, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x74, 0xff, 0x04, 0x17, 0x29, 0xa5, 0xfc, + 0x30, 0xdb, 0x03, 0x9a, 0xf9, 0x27, 0x09, 0xf5, 0x7d, 0x8b, 0xef, 0x3d, 0x2e, 0xa9, 0x3e, 0xb5, + 0x8d, 0x1c, 0x6b, 0x41, 0x2c, 0x89, 0x5e, 0x0a, +]; +pub const V_NEG_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2a, 0xc2, 0x7a, 0x75, 0xb5, 0x1e, 0xee, 0xeb, 0x16, 0x03, 0x6a, 0x51, 0x48, 0x2f, 0x6b, 0x84, + 0x38, 0x06, 0x98, 0x53, 0xfa, 0xcd, 0xa8, 0xda, 0xd1, 0x46, 0xb9, 0xfb, 0xa2, 0xe5, 0xe2, 0xdf, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xef, 0x4f, 0x6e, 0xca, 0x07, 0xfa, 0x2d, + 0x87, 0x75, 0x42, 0x1b, 0x88, 0x5a, 0x4e, 0x67, 0xaa, 0xa7, 0xf9, 0x0b, 0x4b, 0x10, 0x31, 0xdb, + 0xb6, 0xc5, 0x8a, 0x52, 0xc3, 0x76, 0xa1, 0xff, +]; +pub const V_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x18, 0x28, 0xe8, 0x11, 0x24, 0x9d, 0x95, 0x63, 0x4f, 0x95, 0x32, 0x9a, 0x15, 0x85, 0x5c, + 0xe4, 0x71, 0xf5, 0x68, 0xcf, 0x1e, 0x74, 0xfc, 0x27, 0x8c, 0x54, 0x57, 0x34, 0x5c, 0x60, 0x7f, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xe6, 0xd7, 0x01, 0x45, 0x55, 0x3c, 0x00, + 0x56, 0xd2, 0x9d, 0xf4, 0xaf, 0x55, 0x6c, 0x35, 0x6d, 0x73, 0xbd, 0x75, 0x54, 0x39, 0xf5, 0x28, + 0x55, 0xe7, 0xe0, 0xdd, 0x48, 0xa2, 0x8f, 0x28, +]; +pub const COM_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x30, 0x5c, 0xed, 0x4c, 0xc9, 0x17, 0xf4, 0x0f, 0xeb, 0x65, 0xc7, 0x54, 0xd3, 0xfd, 0xeb, + 0xd4, 0x24, 0x13, 0xb9, 0x14, 0xaa, 0xb1, 0x7d, 0x76, 0xcf, 0xfa, 0x1a, 0x78, 0x5b, 0xba, 0x43, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x84, 0xf6, 0x8e, 0xb3, 0x25, 0xcc, + 0x83, 0x49, 0x24, 0xc0, 0x22, 0x3b, 0x78, 0xaa, 0x96, 0xcf, 0xbb, 0xdb, 0x70, 0xb1, 0x63, 0x9c, + 0x01, 0x3b, 0xa7, 0xe0, 0xb7, 0xd9, 0x8d, 0x3f, +]; +pub const W_BYTES: [u8; 248] = [ + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xd2, 0xe8, 0x06, 0x57, 0x75, 0x3a, 0xfb, 0x56, 0x14, 0x51, 0xef, 0x2e, 0x78, 0x6d, 0xc2, + 0x60, 0x39, 0x60, 0xb7, 0x97, 0x43, 0xb2, 0xed, 0xde, 0x40, 0x43, 0x4d, 0x1b, 0x6b, 0x71, 0x62, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0xfc, 0x07, 0x22, 0x98, 0x06, 0x25, 0xf3, + 0xda, 0x20, 0x33, 0x2a, 0x05, 0x83, 0xc5, 0x96, 0xa7, 0x57, 0x53, 0xea, 0xef, 0xed, 0x07, 0x90, + 0x91, 0xbc, 0xa1, 0x6f, 0xdd, 0xd9, 0xed, 0xa9, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x06, 0x16, 0x19, 0x67, 0x88, 0x05, 0xd9, 0x72, 0xd4, 0xd5, 0x48, 0xfb, 0xd9, 0xa5, 0xdc, + 0x8f, 0x8a, 0x7d, 0xf8, 0x06, 0x19, 0x09, 0x84, 0x0e, 0x11, 0xa0, 0xdc, 0x66, 0x5a, 0xd9, 0xfa, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x14, 0xa3, 0x0b, 0x0c, 0x63, 0x61, 0x47, + 0xc4, 0xb9, 0x04, 0x22, 0x7b, 0x86, 0x71, 0x21, 0x0a, 0x0f, 0x65, 0x5a, 0x89, 0x49, 0x98, 0xaa, + 0xdb, 0x8e, 0x8a, 0x3a, 0x58, 0x61, 0xdc, 0xf8, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x22, 0x7b, 0x59, 0x7d, 0x14, 0x15, 0x7a, 0xce, 0x59, 0x3e, 0xfe, 0xe8, 0xb2, 0xf1, 0xac, 0xff, + 0x36, 0x98, 0x40, 0x0d, 0xa6, 0x2c, 0x2a, 0x6b, 0x1f, 0x8e, 0x8d, 0x0e, 0xdd, 0xd5, 0xb0, 0x02, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x0d, 0xa6, 0xcc, 0x2e, 0xfa, 0x24, 0x81, + 0xa5, 0x7d, 0x98, 0x29, 0x08, 0x29, 0x22, 0x97, 0x2a, 0x08, 0xa3, 0xe1, 0xf0, 0x3d, 0xb5, 0x40, + 0x6f, 0xb8, 0x44, 0x7f, 0x31, 0xdc, 0x18, 0x62, +]; + +pub const VK_G1_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x2f, 0x77, 0x0c, 0x9d, 0x84, 0x4c, 0x3c, 0xd5, 0x51, 0xdf, 0x50, 0x87, 0xb9, 0xa8, 0x4d, + 0xd9, 0xec, 0x15, 0xd6, 0x43, 0x81, 0x40, 0x41, 0xe1, 0x8f, 0x82, 0xe0, 0x12, 0x80, 0xcf, 0x6f, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x09, 0x2d, 0x55, 0xb8, 0x9a, 0xe5, 0xf5, + 0xd7, 0xf5, 0x70, 0xbc, 0xa0, 0xbf, 0x03, 0x69, 0x70, 0x05, 0x1c, 0x33, 0xf1, 0x49, 0x4a, 0xcf, + 0x7c, 0x30, 0xc1, 0xc5, 0xa4, 0xf2, 0x80, 0xbb, +]; +pub const VK_G2_BYTES: [u8; 168] = [ + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0xae, 0xe6, 0xcc, 0xe7, 0xb7, 0x43, 0xa7, 0xa8, 0xc2, 0x94, 0x64, 0xf0, 0x50, 0x19, + 0xc1, 0x96, 0x46, 0xc2, 0x8f, 0xbb, 0x2e, 0xe0, 0xe7, 0x6f, 0x07, 0x1a, 0x19, 0x0a, 0x6a, 0x38, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x84, 0xdf, 0xa0, 0x52, 0x5d, 0x1e, 0x79, + 0xea, 0x6a, 0x64, 0xf6, 0x2b, 0x1c, 0x6a, 0x2d, 0xb2, 0x9f, 0x10, 0xce, 0xb3, 0x90, 0x82, 0x37, + 0xa5, 0xcb, 0x40, 0xc8, 0x01, 0x77, 0x89, 0x07, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x22, 0x01, 0x8f, 0x06, 0x83, 0x8c, 0x43, 0xd4, 0x16, 0x35, 0x5e, 0x1e, 0xfb, 0x7f, 0xe9, + 0x77, 0xf4, 0x8f, 0x36, 0x56, 0x50, 0x24, 0xf3, 0x47, 0x22, 0x92, 0x34, 0x90, 0x23, 0x31, 0xe2, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0xce, 0xbd, 0x47, 0x4d, 0xaa, 0xc3, 0xfb, + 0x13, 0x4e, 0x80, 0x1a, 0x53, 0xd1, 0xbb, 0x05, 0x79, 0xc0, 0x0c, 0xdb, 0x9c, 0x5d, 0xb5, 0x92, + 0x42, 0xd7, 0xb1, 0x76, 0x69, 0x27, 0x8d, 0x17, +]; +pub const VK_BETA_G2_BYTES: [u8; 168] = [ + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x26, 0x65, 0xdb, 0x07, 0x85, 0xd0, 0xac, 0x2f, 0x22, 0xfc, 0x48, 0xa9, 0xb0, 0x04, 0x9e, + 0xe2, 0x85, 0xd1, 0xaf, 0xd1, 0x95, 0xde, 0x3e, 0x52, 0x74, 0xbf, 0x30, 0xa4, 0x9d, 0x0a, 0xfc, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x32, 0x86, 0x7e, 0xcc, 0x64, 0xd2, 0xa4, + 0xae, 0x27, 0x06, 0x39, 0xa1, 0x5b, 0x79, 0xd2, 0xb1, 0xef, 0xc2, 0xaf, 0x94, 0x1f, 0x92, 0xff, + 0xd2, 0x6b, 0xd4, 0xf2, 0x07, 0x48, 0x18, 0xd2, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2a, 0x64, 0xf0, 0xaf, 0x8c, 0xfc, 0x2c, 0xd3, 0x34, 0x1a, 0xb1, 0xfb, 0x76, 0xca, 0xbb, 0x26, + 0xab, 0x32, 0xd3, 0x17, 0x70, 0x18, 0x76, 0x66, 0x40, 0x7b, 0xa1, 0x1b, 0xea, 0x26, 0xab, 0x99, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc8, 0x05, 0x58, 0xa2, 0x02, 0x32, 0x91, + 0x3a, 0x32, 0xc5, 0xd5, 0x06, 0x52, 0x2c, 0x6d, 0xfa, 0x89, 0xdd, 0x24, 0xd2, 0x0b, 0x3c, 0x82, + 0x7a, 0x85, 0xf9, 0xc3, 0xcf, 0x72, 0xb4, 0x8c, +]; +pub const C_G1_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x4b, 0xcb, 0xcf, 0x4a, 0xe1, 0xfc, 0xc5, 0x81, 0x65, 0x4a, 0x7a, 0x33, 0x77, 0xdf, 0xe5, + 0x93, 0x4a, 0xf9, 0x7d, 0x89, 0x34, 0x9c, 0x54, 0x25, 0x7f, 0x0b, 0x6a, 0x33, 0x7f, 0x4c, 0x24, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0xbf, 0x39, 0x12, 0x4f, 0xab, 0xa4, 0x50, + 0xaa, 0x56, 0xf4, 0x53, 0x6b, 0x78, 0x52, 0x0a, 0xb1, 0x84, 0xaf, 0xa3, 0xc6, 0xde, 0x91, 0x96, + 0x38, 0x71, 0xc2, 0x38, 0xc8, 0x79, 0x0f, 0xb0, +]; diff --git a/jolt-svm-verifier/program/src/lib.rs b/jolt-svm-verifier/program/src/lib.rs new file mode 100644 index 000000000..46a313f50 --- /dev/null +++ b/jolt-svm-verifier/program/src/lib.rs @@ -0,0 +1,138 @@ +#![allow(non_snake_case)] + +mod constants; +mod subprotocols; +mod utils; + +use constants::*; + +use crate::subprotocols::hyperkzg; +use ark_bn254::{Bn254, Fq, Fq2, Fr, G1Affine, G2Affine}; +use ark_ff::PrimeField; +use ark_serialize::CanonicalDeserialize; +use jolt_types::poly::commitment::hyperkzg::{ + HyperKZGCommitment, HyperKZGProof, HyperKZGVerifierKey, +}; +use jolt_types::poly::commitment::kzg::KZGVerifierKey; +use jolt_types::utils::transcript::ProofTranscript; +use solana_program::{ + account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey, +}; + +entrypoint!(process_instruction); + +fn process_instruction( + _program_id: &Pubkey, + _accounts: &[AccountInfo], + _instruction_data: &[u8], +) -> ProgramResult { + msg!("Solana WIP Jolt Verifier!"); + verify_hyperKZG_JOLT(); + Ok(()) +} + +fn verify_hyperKZG_JOLT() { + let eval: Fr = CanonicalDeserialize::deserialize_uncompressed(&EVAL_BYTES[..]).unwrap(); + let point: Vec = CanonicalDeserialize::deserialize_uncompressed(&POINT_BYTES[..]).unwrap(); + + let proof = readProof(); + let vk = readVK(); + let C = readC(); + + let mut transcript = ProofTranscript::new(b"TestEval"); + let res = hyperkzg::verify_hyperkzg(&vk, &C, &point, &eval, &proof, &mut transcript); + msg!("Verify Result: {:?}", res); +} + +fn readProof() -> HyperKZGProof { + let v_pos: Vec> = + CanonicalDeserialize::deserialize_uncompressed(&V_POS_BYTES[..]).unwrap(); + let v_neg: Vec> = + CanonicalDeserialize::deserialize_uncompressed(&V_NEG_BYTES[..]).unwrap(); + let v_y: Vec> = CanonicalDeserialize::deserialize_uncompressed(&V_BYTES[..]).unwrap(); + + let pre_com: Vec> = + CanonicalDeserialize::deserialize_uncompressed(&COM_BYTES[..]).unwrap(); + let pre_w: Vec> = CanonicalDeserialize::deserialize_uncompressed(&W_BYTES[..]).unwrap(); + + let mut com: Vec = vec![]; + for coords in pre_com.chunks(2) { + // convert coords into G1Affine + let x = Fq::from_be_bytes_mod_order(&coords[0]); + let y = Fq::from_be_bytes_mod_order(&coords[1]); + com.push(G1Affine::new_unchecked(x, y)); + } + + let mut w: Vec = vec![]; + for coords in pre_w.chunks(2) { + // convert coords into G1Affine + let x = Fq::from_be_bytes_mod_order(&coords[0]); + let y = Fq::from_be_bytes_mod_order(&coords[1]); + w.push(G1Affine::new_unchecked(x, y)); + } + let v_pos = v_pos + .iter() + .map(|v| Fr::from_be_bytes_mod_order(v)) + .collect::>(); + let v_neg = v_neg + .iter() + .map(|v| Fr::from_be_bytes_mod_order(v)) + .collect::>(); + let v_y = v_y + .iter() + .map(|v| Fr::from_be_bytes_mod_order(v)) + .collect::>(); + + HyperKZGProof { + com, + w, + v: vec![v_pos, v_neg, v_y], + } +} + +fn readVK() -> HyperKZGVerifierKey { + let pre_g1: Vec> = + CanonicalDeserialize::deserialize_uncompressed(&VK_G1_BYTES[..]).unwrap(); + let pre_g2: Vec> = + CanonicalDeserialize::deserialize_uncompressed(&VK_G2_BYTES[..]).unwrap(); + let pre_beta_g2: Vec> = + CanonicalDeserialize::deserialize_uncompressed(&VK_BETA_G2_BYTES[..]).unwrap(); + + let x = Fq::from_be_bytes_mod_order(&pre_g1[0]); + let y = Fq::from_be_bytes_mod_order(&pre_g1[1]); + let g1 = G1Affine::new_unchecked(x, y); + + let x_c0 = Fq::from_be_bytes_mod_order(&pre_g2[0]); + let y_c0 = Fq::from_be_bytes_mod_order(&pre_g2[1]); + let x_c1 = Fq::from_be_bytes_mod_order(&pre_g2[2]); + let y_c1 = Fq::from_be_bytes_mod_order(&pre_g2[3]); + let g2 = G2Affine::new_unchecked(Fq2::new(x_c0, y_c0), Fq2::new(x_c1, y_c1)); + + let x_c0 = Fq::from_be_bytes_mod_order(&pre_beta_g2[0]); + let y_c0 = Fq::from_be_bytes_mod_order(&pre_beta_g2[1]); + let x_c1 = Fq::from_be_bytes_mod_order(&pre_beta_g2[2]); + let y_c1 = Fq::from_be_bytes_mod_order(&pre_beta_g2[3]); + let beta_g2 = G2Affine::new_unchecked(Fq2::new(x_c0, y_c0), Fq2::new(x_c1, y_c1)); + + HyperKZGVerifierKey { + kzg_vk: KZGVerifierKey { g1, g2, beta_g2 }, + } +} + +fn readC() -> HyperKZGCommitment { + let pre_c: Vec> = + CanonicalDeserialize::deserialize_uncompressed(&C_G1_BYTES[..]).unwrap(); + let x = Fq::from_be_bytes_mod_order(&pre_c[0]); + let y = Fq::from_be_bytes_mod_order(&pre_c[1]); + HyperKZGCommitment(G1Affine::new_unchecked(x, y)) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_simple_verify() { + verify_hyperKZG_JOLT(); + } +} diff --git a/jolt-svm-verifier/program/src/subprotocols/hyperkzg.rs b/jolt-svm-verifier/program/src/subprotocols/hyperkzg.rs new file mode 100644 index 000000000..0c7d4cc65 --- /dev/null +++ b/jolt-svm-verifier/program/src/subprotocols/hyperkzg.rs @@ -0,0 +1,205 @@ +use ark_ec::pairing::Pairing; +use ark_ec::AffineRepr; +use ark_ff::{BigInteger, PrimeField}; +use ark_serialize::CanonicalSerialize; +use ark_std::{One, Zero}; +use jolt_types::field; +use jolt_types::poly::commitment::hyperkzg::{ + HyperKZGCommitment, HyperKZGProof, HyperKZGVerifierKey, +}; +use jolt_types::utils::errors::ProofVerifyError; +use jolt_types::utils::transcript::ProofTranscript; + +use crate::utils::convert_endianness_64; +use solana_program::alt_bn128::prelude::{ + alt_bn128_addition, alt_bn128_multiplication, alt_bn128_pairing, +}; + +/// A method to verify purported evaluations of a batch of polynomials +pub fn verify_hyperkzg( + vk: &HyperKZGVerifierKey

, + C: &HyperKZGCommitment

, + point: &[P::ScalarField], + P_of_x: &P::ScalarField, + pi: &HyperKZGProof

, + transcript: &mut ProofTranscript, +) -> Result<(), ProofVerifyError> +where +

::ScalarField: field::JoltField, +{ + let x = point.to_vec(); + let y = P_of_x; + + let ell = x.len(); + + let mut com = pi.com.clone(); + + // we do not need to add x to the transcript, because in our context x was + // obtained from the transcript + transcript.append_points(&com.iter().map(|g| g.into_group()).collect::>()); + let r:

::ScalarField = transcript.challenge_scalar(); + + if r == P::ScalarField::zero() || C.0 == P::G1Affine::zero() { + return Err(ProofVerifyError::InternalError); + } + com.insert(0, C.0); // set com_0 = C, shifts other commitments to the right + + let u = vec![r, -r, r * r]; + + // Setup vectors (Y, ypos, yneg) from pi.v + let v = &pi.v; + if v.len() != 3 { + return Err(ProofVerifyError::InternalError); + } + if v[0].len() != ell || v[1].len() != ell || v[2].len() != ell { + return Err(ProofVerifyError::InternalError); + } + let ypos = &v[0]; + let yneg = &v[1]; + let mut Y = v[2].to_vec(); + Y.push(*y); + + // Check consistency of (Y, ypos, yneg) + let two = P::ScalarField::from(2u64); + for i in 0..ell { + println!("Y[{}]: {:?}", i, two * r * Y[i + 1]); + println!( + "Y[{}]: {:?}", + i, + r * (P::ScalarField::one() - x[ell - i - 1]) * (ypos[i] + yneg[i]) + + x[ell - i - 1] * (ypos[i] - yneg[i]) + ); + + if two * r * Y[i + 1] + != r * (P::ScalarField::one() - x[ell - i - 1]) * (ypos[i] + yneg[i]) + + x[ell - i - 1] * (ypos[i] - yneg[i]) + { + return Err(ProofVerifyError::InternalError); + } + // Note that we don't make any checks about Y[0] here, but our batching + // check below requires it + } + + // Check commitments to (Y, ypos, yneg) are valid + if !kzg_verify_batch_single(vk, &com, &pi.w, &u, &pi.v, transcript) { + return Err(ProofVerifyError::InternalError); + } + + Ok(()) +} + +// vk is hashed in transcript already, so we do not add it here +fn kzg_verify_batch_single( + vk: &HyperKZGVerifierKey

, + C: &[P::G1Affine], + W: &[P::G1Affine], + u: &[P::ScalarField], + v: &[Vec], + transcript: &mut ProofTranscript, +) -> bool +where +

::ScalarField: field::JoltField, +{ + let k = C.len(); + let t = u.len(); + + // 25k CU savings by doing this, but it doesn't work for some reason + // v.iter().flat_map(|x| x.iter()).for_each(|x| transcript.append_scalar(x)); + transcript.append_scalars(&v.iter().flatten().cloned().collect::>()); + let q_powers: Vec = transcript.challenge_scalar_powers(k); + + transcript.append_points(&W.iter().map(|g| g.into_group()).collect::>()); + let d_0: P::ScalarField = transcript.challenge_scalar(); + let d_1 = d_0 * d_0; + + assert_eq!(t, 3); + assert_eq!(W.len(), 3); + + // Compute the batched openings + // compute B(u_i) = v[i][0] + q*v[i][1] + ... + q^(t-1) * v[i][t-1] + let B_u = v + .into_iter() + .map(|v_i| { + v_i.into_iter() + .zip(q_powers.iter()) + .map(|(a, b)| *a * *b) + .sum() + }) + .collect::>(); + + // Finally we do a MSM to get the value of the left hand side + // NOTE - This is gas inefficient and grows with log of the proof size so we might want + // to move to a pippenger window algo with much smaller MSMs which we might save gas on. + // Our first value is the C[0]. + let mut c_0 = vec![]; + C[0].serialize_uncompressed(&mut c_0).unwrap(); + let c_0 = convert_endianness_64(&c_0); + + let q_powers_0 = q_powers[0].into_bigint().to_bytes_be(); + let mut L_bytes = alt_bn128_multiplication(&[c_0, q_powers_0].concat()).unwrap(); + + // Now do a running sum over the points in com + for (i, point) in C.iter().enumerate() { + let mut temp_bytes = vec![]; + point.serialize_uncompressed(&mut temp_bytes).unwrap(); + let temp_bytes = convert_endianness_64(&temp_bytes); + + let q_powers_i = q_powers[i / 2 + 1].into_bigint().to_bytes_be(); + let temp = alt_bn128_multiplication(&[temp_bytes, q_powers_i].concat()).unwrap(); + L_bytes = alt_bn128_addition(&[L_bytes, temp].concat()).unwrap(); + } + + // Next add in the W dot product U + let mut temp_bytes = Vec::::with_capacity(64); + W[0].serialize_uncompressed(&mut temp_bytes).unwrap(); + let W_0_bytes = convert_endianness_64(&temp_bytes); + let temp = + alt_bn128_multiplication(&[W_0_bytes.clone(), u[0].into_bigint().to_bytes_be()].concat()) + .unwrap(); + L_bytes = alt_bn128_addition(&[L_bytes, temp].concat()).unwrap(); + + temp_bytes.clear(); + W[1].serialize_uncompressed(&mut temp_bytes).unwrap(); + let W_1_bytes = convert_endianness_64(&temp_bytes); + let temp = alt_bn128_multiplication( + &[W_1_bytes.clone(), (u[1] * d_0).into_bigint().to_bytes_be()].concat(), + ) + .unwrap(); + L_bytes = alt_bn128_addition(&[L_bytes, temp].concat()).unwrap(); + + temp_bytes.clear(); + W[2].serialize_uncompressed(&mut temp_bytes).unwrap(); + let W_2_bytes = convert_endianness_64(&temp_bytes); + let temp = alt_bn128_multiplication( + &[W_2_bytes.clone(), (u[2] * d_1).into_bigint().to_bytes_be()].concat(), + ) + .unwrap(); + L_bytes = alt_bn128_addition(&[L_bytes, temp].concat()).unwrap(); + + //-(B_u[0] + d_0 * B_u[1] + d_1 * B_u[2]) + let b_u = -(B_u[0] + d_0 * B_u[1] + d_1 * B_u[2]); + + // Add in to the msm b_u Vk_g1 + temp_bytes.clear(); + vk.kzg_vk + .g1 + .serialize_uncompressed(&mut temp_bytes) + .unwrap(); + let temp_bytes = convert_endianness_64(&temp_bytes); + let temp = + alt_bn128_multiplication(&[temp_bytes, b_u.into_bigint().to_bytes_be()].concat()).unwrap(); + L_bytes = alt_bn128_addition(&[L_bytes, temp].concat()).unwrap(); + + // W[0] + W[1] * d_0 + W[2] * d_1; + let mut R_bytes = W_0_bytes; + let temp = + alt_bn128_multiplication(&[W_1_bytes, d_0.into_bigint().to_bytes_be()].concat()).unwrap(); + R_bytes = alt_bn128_addition(&[R_bytes, temp].concat()).unwrap(); + let temp = + alt_bn128_multiplication(&[W_2_bytes, d_1.into_bigint().to_bytes_be()].concat()).unwrap(); + R_bytes = alt_bn128_addition(&[R_bytes, temp].concat()).unwrap(); + + let pairing_res = alt_bn128_pairing(&[L_bytes, R_bytes].concat()); + println!("Pairing result: {:?}", pairing_res); + pairing_res.is_ok() +} diff --git a/jolt-svm-verifier/program/src/subprotocols/mod.rs b/jolt-svm-verifier/program/src/subprotocols/mod.rs new file mode 100644 index 000000000..bbb221ef1 --- /dev/null +++ b/jolt-svm-verifier/program/src/subprotocols/mod.rs @@ -0,0 +1 @@ +pub mod hyperkzg; diff --git a/jolt-svm-verifier/program/src/utils.rs b/jolt-svm-verifier/program/src/utils.rs new file mode 100644 index 000000000..835f3b059 --- /dev/null +++ b/jolt-svm-verifier/program/src/utils.rs @@ -0,0 +1,15 @@ +#![allow(dead_code)] + +pub fn convert_endianness_64(bytes: &[u8]) -> Vec { + bytes + .chunks(32) + .flat_map(|b| b.iter().copied().rev().collect::>()) + .collect::>() +} + +pub fn convert_endianness_128(bytes: &[u8]) -> Vec { + bytes + .chunks(64) + .flat_map(|b| b.iter().copied().rev().collect::>()) + .collect::>() +} diff --git a/jolt-svm-verifier/tests/jolt-verifier.ts b/jolt-svm-verifier/tests/jolt-verifier.ts new file mode 100644 index 000000000..7b99f742f --- /dev/null +++ b/jolt-svm-verifier/tests/jolt-verifier.ts @@ -0,0 +1,38 @@ +import { describe, test } from 'node:test'; +import { + ComputeBudgetInstruction, + ComputeBudgetProgram, + PublicKey, + SystemProgram, + Transaction, + TransactionInstruction +} from '@solana/web3.js'; +import { assert } from 'chai'; +import { start } from 'solana-bankrun'; + +describe('jolt-verifier', async () => { + // load program in solana-bankrun + const PROGRAM_ID = PublicKey.unique(); + const context = await start([{ name: 'jolt_svm_verifier', programId: PROGRAM_ID }], []); + const client = context.banksClient; + const payer = context.payer; + + test('test basic', async () => { + const blockhash = context.lastBlockhash; + const compute_ix = ComputeBudgetProgram.setComputeUnitLimit({units: 1_400_000}); + // We setup our instruction. + const ix = new TransactionInstruction({ + keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }], + programId: PROGRAM_ID, + data: Buffer.alloc(0), // No data + }); + + const tx = new Transaction(); + tx.recentBlockhash = blockhash; + tx.add(compute_ix); + tx.add(ix).sign(payer); + + // Now we process the transaction + const transaction = await client.processTransaction(tx); + }); +}); diff --git a/jolt-svm-verifier/tsconfig.json b/jolt-svm-verifier/tsconfig.json new file mode 100644 index 000000000..558b83e5e --- /dev/null +++ b/jolt-svm-verifier/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "types": ["mocha", "chai"], + "typeRoots": ["./node_modules/@types"], + "lib": ["es2015"], + "module": "commonjs", + "target": "es6", + "esModuleInterop": true + } + } + \ No newline at end of file diff --git a/jolt-svm-verifier/yarn.lock b/jolt-svm-verifier/yarn.lock new file mode 100644 index 000000000..347fa9116 --- /dev/null +++ b/jolt-svm-verifier/yarn.lock @@ -0,0 +1,1113 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@babel/runtime@^7.25.0": + version "7.25.4" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.25.4.tgz#6ef37d678428306e7d75f054d5b1bdb8cf8aa8ee" + integrity sha512-DSgLeL/FNcpXuzav5wfYvHCGvynXkJbn3Zvc3823AEe9nPwW9IK4UoCSS5yGymmQzN0pCPvivtgS6/8U2kkm1w== + dependencies: + regenerator-runtime "^0.14.0" + +"@noble/curves@^1.4.2": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.5.0.tgz#7a9b9b507065d516e6dce275a1e31db8d2a100dd" + integrity sha512-J5EKamIHnKPyClwVrzmaf5wSdQXgdHcPZIZLu3bwnbeCx8/7NPK5q2ZBWF+5FvYGByjiQQsJYX6jfgB2wDPn3A== + dependencies: + "@noble/hashes" "1.4.0" + +"@noble/hashes@1.4.0", "@noble/hashes@^1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426" + integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg== + +"@solana/buffer-layout@^4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@solana/buffer-layout/-/buffer-layout-4.0.1.tgz#b996235eaec15b1e0b5092a8ed6028df77fa6c15" + integrity sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA== + dependencies: + buffer "~6.0.3" + +"@solana/web3.js@^1.47.3", "@solana/web3.js@^1.68.0": + version "1.95.3" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.95.3.tgz#70b5f4d76823f56b5af6403da51125fffeb65ff3" + integrity sha512-O6rPUN0w2fkNqx/Z3QJMB9L225Ex10PRDH8bTaIUPZXMPV0QP8ZpPvjQnXK+upUczlRgzHzd6SjKIha1p+I6og== + dependencies: + "@babel/runtime" "^7.25.0" + "@noble/curves" "^1.4.2" + "@noble/hashes" "^1.4.0" + "@solana/buffer-layout" "^4.0.1" + agentkeepalive "^4.5.0" + bigint-buffer "^1.1.5" + bn.js "^5.2.1" + borsh "^0.7.0" + bs58 "^4.0.1" + buffer "6.0.3" + fast-stable-stringify "^1.0.0" + jayson "^4.1.1" + node-fetch "^2.7.0" + rpc-websockets "^9.0.2" + superstruct "^2.0.2" + +"@swc/helpers@^0.5.11": + version "0.5.12" + resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.12.tgz#37aaca95284019eb5d2207101249435659709f4b" + integrity sha512-KMZNXiGibsW9kvZAO1Pam2JPTDBm+KSHMMHWdsyI/1DbIZjT2A6Gy3hblVXUMEDvUAKq+e0vL0X0o54owWji7g== + dependencies: + tslib "^2.4.0" + +"@types/bn.js@^5.1.0": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.5.tgz#2e0dacdcce2c0f16b905d20ff87aedbc6f7b4bf0" + integrity sha512-V46N0zwKRF5Q00AZ6hWtN0T8gGmDUaUzLWQvHFo5yThtVwK/VCenFY3wXVbOvNfajEpsTfQM4IN9k/d6gUVX3A== + dependencies: + "@types/node" "*" + +"@types/chai@^4.3.1": + version "4.3.17" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.17.tgz#9195f9d242f2ac3b429908864b6b871a8f73f489" + integrity sha512-zmZ21EWzR71B4Sscphjief5djsLre50M6lI622OSySTmn9DB3j+C3kWroHfBQWXbOBwbgg/M8CG/hUxDLIloow== + +"@types/connect@^3.4.33": + version "3.4.38" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.38.tgz#5ba7f3bc4fbbdeaff8dded952e5ff2cc53f8d858" + integrity sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug== + dependencies: + "@types/node" "*" + +"@types/json5@^0.0.29": + version "0.0.29" + resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" + integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ== + +"@types/mocha@^9.1.1": + version "9.1.1" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.1.1.tgz#e7c4f1001eefa4b8afbd1eee27a237fee3bf29c4" + integrity sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw== + +"@types/node@*": + version "22.5.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.0.tgz#10f01fe9465166b4cab72e75f60d8b99d019f958" + integrity sha512-DkFrJOe+rfdHTqqMg0bSNlGlQ85hSoh2TPzZyhHsXnMtligRWpxUySiyw8FY14ITt24HVCiQPWxS3KO/QlGmWg== + dependencies: + undici-types "~6.19.2" + +"@types/node@^12.12.54": + version "12.20.55" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" + integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== + +"@types/uuid@^8.3.4": + version "8.3.4" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc" + integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw== + +"@types/ws@^7.4.4": + version "7.4.7" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.7.tgz#f7c390a36f7a0679aa69de2d501319f4f8d9b702" + integrity sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww== + dependencies: + "@types/node" "*" + +"@types/ws@^8.2.2": + version "8.5.12" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.12.tgz#619475fe98f35ccca2a2f6c137702d85ec247b7e" + integrity sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ== + dependencies: + "@types/node" "*" + +"@ungap/promise-all-settled@1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" + integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== + +JSONStream@^1.3.5: + version "1.3.5" + resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" + integrity sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ== + dependencies: + jsonparse "^1.2.0" + through ">=2.2.7 <3" + +agentkeepalive@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-4.5.0.tgz#2673ad1389b3c418c5a20c5d7364f93ca04be923" + integrity sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew== + dependencies: + humanize-ms "^1.2.1" + +ansi-colors@4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" + integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + +ansi-styles@^4.0.0, ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +anymatch@~3.1.2: + version "3.1.3" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" + integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw== + dependencies: + normalize-path "^3.0.0" + picomatch "^2.0.4" + +argparse@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" + integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== + +arrify@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" + integrity sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA== + +assertion-error@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +base-x@^3.0.2: + version "3.0.10" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.10.tgz#62de58653f8762b5d6f8d9fe30fa75f7b2585a75" + integrity sha512-7d0s06rR9rYaIWHkpfLIFICM/tkSVdoPC9qYAQRpxn9DdKNWNsKC0uk++akckyLq16Tx2WIinnZ6WRriAt6njQ== + dependencies: + safe-buffer "^5.0.1" + +base64-js@^1.3.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" + integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== + +bigint-buffer@^1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/bigint-buffer/-/bigint-buffer-1.1.5.tgz#d038f31c8e4534c1f8d0015209bf34b4fa6dd442" + integrity sha512-trfYco6AoZ+rKhKnxA0hgX0HAbVP/s808/EuDSe2JDzUnCp/xAsli35Orvk67UrTEcwuxZqYZDmfA2RXJgxVvA== + dependencies: + bindings "^1.3.0" + +binary-extensions@^2.0.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522" + integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw== + +bindings@^1.3.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" + integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== + dependencies: + file-uri-to-path "1.0.0" + +bn.js@^5.2.0, bn.js@^5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" + integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== + +borsh@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/borsh/-/borsh-0.7.0.tgz#6e9560d719d86d90dc589bca60ffc8a6c51fec2a" + integrity sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA== + dependencies: + bn.js "^5.2.0" + bs58 "^4.0.0" + text-encoding-utf-8 "^1.0.2" + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +braces@~3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== + dependencies: + fill-range "^7.1.1" + +browser-stdout@1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" + integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== + +bs58@^4.0.0, bs58@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a" + integrity sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw== + dependencies: + base-x "^3.0.2" + +buffer-from@^1.0.0, buffer-from@^1.1.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" + integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== + +buffer@6.0.3, buffer@^6.0.3, buffer@~6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" + integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.2.1" + +bufferutil@^4.0.1: + version "4.0.8" + resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.8.tgz#1de6a71092d65d7766c4d8a522b261a6e787e8ea" + integrity sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw== + dependencies: + node-gyp-build "^4.3.0" + +camelcase@^6.0.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" + integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== + +chai@^4.3.4: + version "4.5.0" + resolved "https://registry.yarnpkg.com/chai/-/chai-4.5.0.tgz#707e49923afdd9b13a8b0b47d33d732d13812fd8" + integrity sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw== + dependencies: + assertion-error "^1.1.0" + check-error "^1.0.3" + deep-eql "^4.1.3" + get-func-name "^2.0.2" + loupe "^2.3.6" + pathval "^1.1.1" + type-detect "^4.1.0" + +chalk@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +check-error@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.3.tgz#a6502e4312a7ee969f646e83bb3ddd56281bd694" + integrity sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg== + dependencies: + get-func-name "^2.0.2" + +chokidar@3.5.3: + version "3.5.3" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" + integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== + dependencies: + anymatch "~3.1.2" + braces "~3.0.2" + glob-parent "~5.1.2" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.6.0" + optionalDependencies: + fsevents "~2.3.2" + +cliui@^7.0.2: + version "7.0.4" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" + integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^7.0.0" + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +commander@^2.20.3: + version "2.20.3" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" + integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== + +debug@4.3.3: + version "4.3.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664" + integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q== + dependencies: + ms "2.1.2" + +decamelize@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837" + integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ== + +deep-eql@^4.1.3: + version "4.1.4" + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.4.tgz#d0d3912865911bb8fac5afb4e3acfa6a28dc72b7" + integrity sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg== + dependencies: + type-detect "^4.0.0" + +delay@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/delay/-/delay-5.0.0.tgz#137045ef1b96e5071060dd5be60bf9334436bd1d" + integrity sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw== + +diff@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" + integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== + +diff@^3.1.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" + integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== + +emoji-regex@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" + integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== + +es6-promise@^4.0.3: + version "4.2.8" + resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a" + integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w== + +es6-promisify@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203" + integrity sha512-C+d6UdsYDk0lMebHNR4S2NybQMMngAOnOwYBQjTOiv0MkoJMP0Myw2mgpDLBcpfCmRLxyFqYhS/CfOENq4SJhQ== + dependencies: + es6-promise "^4.0.3" + +escalade@^3.1.1: + version "3.1.2" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27" + integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA== + +escape-string-regexp@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" + integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + +eventemitter3@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" + integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== + +eyes@^0.1.8: + version "0.1.8" + resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0" + integrity sha512-GipyPsXO1anza0AOZdy69Im7hGFCNB7Y/NGjDlZGJ3GJJLtwNSb2vrzYrTYJRrRloVx7pl+bhUaTB8yiccPvFQ== + +fast-stable-stringify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fast-stable-stringify/-/fast-stable-stringify-1.0.0.tgz#5c5543462b22aeeefd36d05b34e51c78cb86d313" + integrity sha512-wpYMUmFu5f00Sm0cj2pfivpmawLZ0NKdviQ4w9zJeR8JVtOpOxHmLaJuj0vxvGqMJQWyP/COUkF75/57OKyRag== + +file-uri-to-path@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" + integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== + +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== + dependencies: + to-regex-range "^5.0.1" + +find-up@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + +flat@^5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" + integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== + +fsevents@~2.3.2: + version "2.3.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + +get-caller-file@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + +get-func-name@^2.0.1, get-func-name@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" + integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== + +glob-parent@~5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" + integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== + dependencies: + is-glob "^4.0.1" + +glob@7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" + integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +growl@1.10.5: + version "1.10.5" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" + integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +he@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" + integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== + +humanize-ms@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/humanize-ms/-/humanize-ms-1.2.1.tgz#c46e3159a293f6b896da29316d8b6fe8bb79bbed" + integrity sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ== + dependencies: + ms "^2.0.0" + +ieee754@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" + integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA== + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +is-binary-path@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" + integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== + dependencies: + binary-extensions "^2.0.0" + +is-extglob@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + integrity sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ== + +is-fullwidth-code-point@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" + integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== + +is-glob@^4.0.1, is-glob@~4.0.1: + version "4.0.3" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" + integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== + dependencies: + is-extglob "^2.1.1" + +is-number@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" + integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== + +is-plain-obj@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287" + integrity sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA== + +is-unicode-supported@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" + integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw== + +isomorphic-ws@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz#55fd4cd6c5e6491e76dc125938dd863f5cd4f2dc" + integrity sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w== + +jayson@^4.1.1: + version "4.1.2" + resolved "https://registry.yarnpkg.com/jayson/-/jayson-4.1.2.tgz#443c26a8658703e0b2e881117b09395d88b6982e" + integrity sha512-5nzMWDHy6f+koZOuYsArh2AXs73NfWYVlFyJJuCedr93GpY+Ku8qq10ropSXVfHK+H0T6paA88ww+/dV+1fBNA== + dependencies: + "@types/connect" "^3.4.33" + "@types/node" "^12.12.54" + "@types/ws" "^7.4.4" + JSONStream "^1.3.5" + commander "^2.20.3" + delay "^5.0.0" + es6-promisify "^5.0.0" + eyes "^0.1.8" + isomorphic-ws "^4.0.1" + json-stringify-safe "^5.0.1" + uuid "^8.3.2" + ws "^7.5.10" + +js-yaml@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" + integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== + dependencies: + argparse "^2.0.1" + +json-stringify-safe@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" + integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA== + +json5@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" + integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA== + dependencies: + minimist "^1.2.0" + +jsonparse@^1.2.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" + integrity sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg== + +locate-path@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286" + integrity sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw== + dependencies: + p-locate "^5.0.0" + +log-symbols@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" + integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== + dependencies: + chalk "^4.1.0" + is-unicode-supported "^0.1.0" + +loupe@^2.3.6: + version "2.3.7" + resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.7.tgz#6e69b7d4db7d3ab436328013d37d1c8c3540c697" + integrity sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA== + dependencies: + get-func-name "^2.0.1" + +make-error@^1.1.1: + version "1.3.6" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== + +minimatch@4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-4.2.1.tgz#40d9d511a46bdc4e563c22c3080cde9c0d8299b4" + integrity sha512-9Uq1ChtSZO+Mxa/CL1eGizn2vRn3MlLgzhT0Iz8zaY8NdvxvB0d5QdPFmCKf7JKA9Lerx5vRrnwO03jsSfGG9g== + dependencies: + brace-expansion "^1.1.7" + +minimatch@^3.0.4: + version "3.1.2" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" + integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== + dependencies: + brace-expansion "^1.1.7" + +minimist@^1.2.0, minimist@^1.2.6: + version "1.2.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" + integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== + +mkdirp@^0.5.1: + version "0.5.6" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6" + integrity sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw== + dependencies: + minimist "^1.2.6" + +mocha@^9.0.3: + version "9.2.2" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-9.2.2.tgz#d70db46bdb93ca57402c809333e5a84977a88fb9" + integrity sha512-L6XC3EdwT6YrIk0yXpavvLkn8h+EU+Y5UcCHKECyMbdUIxyMuZj4bX4U9e1nvnvUUvQVsV2VHQr5zLdcUkhW/g== + dependencies: + "@ungap/promise-all-settled" "1.1.2" + ansi-colors "4.1.1" + browser-stdout "1.3.1" + chokidar "3.5.3" + debug "4.3.3" + diff "5.0.0" + escape-string-regexp "4.0.0" + find-up "5.0.0" + glob "7.2.0" + growl "1.10.5" + he "1.2.0" + js-yaml "4.1.0" + log-symbols "4.1.0" + minimatch "4.2.1" + ms "2.1.3" + nanoid "3.3.1" + serialize-javascript "6.0.0" + strip-json-comments "3.1.1" + supports-color "8.1.1" + which "2.0.2" + workerpool "6.2.0" + yargs "16.2.0" + yargs-parser "20.2.4" + yargs-unparser "2.0.0" + +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +ms@2.1.3, ms@^2.0.0: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + +nanoid@3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.1.tgz#6347a18cac88af88f58af0b3594b723d5e99bb35" + integrity sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw== + +node-fetch@^2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" + integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== + dependencies: + whatwg-url "^5.0.0" + +node-gyp-build@^4.3.0: + version "4.8.1" + resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.8.1.tgz#976d3ad905e71b76086f4f0b0d3637fe79b6cda5" + integrity sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw== + +normalize-path@^3.0.0, normalize-path@~3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" + integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== + dependencies: + wrappy "1" + +p-limit@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" + integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== + dependencies: + yocto-queue "^0.1.0" + +p-locate@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834" + integrity sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw== + dependencies: + p-limit "^3.0.2" + +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg== + +pathval@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d" + integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ== + +picomatch@^2.0.4, picomatch@^2.2.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" + integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== + +randombytes@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" + integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== + dependencies: + safe-buffer "^5.1.0" + +readdirp@~3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" + integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== + dependencies: + picomatch "^2.2.1" + +regenerator-runtime@^0.14.0: + version "0.14.1" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f" + integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw== + +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" + integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q== + +rpc-websockets@^9.0.2: + version "9.0.2" + resolved "https://registry.yarnpkg.com/rpc-websockets/-/rpc-websockets-9.0.2.tgz#4c1568d00b8100f997379a363478f41f8f4b242c" + integrity sha512-YzggvfItxMY3Lwuax5rC18inhbjJv9Py7JXRHxTIi94JOLrqBsSsUUc5bbl5W6c11tXhdfpDPK0KzBhoGe8jjw== + dependencies: + "@swc/helpers" "^0.5.11" + "@types/uuid" "^8.3.4" + "@types/ws" "^8.2.2" + buffer "^6.0.3" + eventemitter3 "^5.0.1" + uuid "^8.3.2" + ws "^8.5.0" + optionalDependencies: + bufferutil "^4.0.1" + utf-8-validate "^5.0.2" + +safe-buffer@^5.0.1, safe-buffer@^5.1.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + +serialize-javascript@6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" + integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== + dependencies: + randombytes "^2.1.0" + +solana-bankrun-darwin-arm64@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/solana-bankrun-darwin-arm64/-/solana-bankrun-darwin-arm64-0.3.0.tgz#749ce9858bf61c4244a06c4e6d99338daa154909" + integrity sha512-+NbDncf0U6l3knuacRBiqpjZ2DSp+5lZaAU518gH7/x6qubbui/d000STaIBK+uNTPBS/AL/bCN+7PkXqmA3lA== + +solana-bankrun-darwin-universal@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/solana-bankrun-darwin-universal/-/solana-bankrun-darwin-universal-0.3.0.tgz#2d2932282bb1fe719430f2f53060cad3104ebb26" + integrity sha512-1/F0xdMa4qvc5o6z16FCCbZ5jbdvKvxpx5kyPcMWRiRPwyvi+zltMxciPAYMlg3wslQqGz88uFhrBEzq2eTumQ== + +solana-bankrun-darwin-x64@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/solana-bankrun-darwin-x64/-/solana-bankrun-darwin-x64-0.3.0.tgz#c814a13702a12ba085c32b20a66a063cffbe74a1" + integrity sha512-U6CANjkmMl+lgNA7UH0GKs5V7LtVIUDzJBZefGGqLfqUNv3EjA/PrrToM0hAOWJgkxSwdz6zW+p5sw5FmnbXtg== + +solana-bankrun-linux-x64-gnu@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/solana-bankrun-linux-x64-gnu/-/solana-bankrun-linux-x64-gnu-0.3.0.tgz#5c5dec2d4e01f755c9cf8fe9f791a8085bf94f51" + integrity sha512-qJSkCFs0k2n4XtTnyxGMiZsuqO2TiqTYgWjQ+3mZhGNUAMys/Vq8bd7/SyBm6RR7EfVuRXRxZvh+F8oKZ77V4w== + +solana-bankrun-linux-x64-musl@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/solana-bankrun-linux-x64-musl/-/solana-bankrun-linux-x64-musl-0.3.0.tgz#0df9434f03d1aa704b085f82e40cc6129b8eea09" + integrity sha512-xsS2CS2xb1Sw4ivNXM0gPz/qpW9BX0neSvt/pnok5L330Nu9xlTnKAY8FhzzqOP9P9sJlGRM787Y6d0yYwt6xQ== + +solana-bankrun@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/solana-bankrun/-/solana-bankrun-0.3.0.tgz#1183af008e00c565d6708f0c051588589e315d1c" + integrity sha512-YkH7sa8TB/AoRPzG17CXJtYsRIQHEkEqGLz1Vwc13taXhDBkjO7z6NI5JYw7n0ybRymDHwMYTc7sd+5J40TyVQ== + dependencies: + "@solana/web3.js" "^1.68.0" + bs58 "^4.0.1" + optionalDependencies: + solana-bankrun-darwin-arm64 "0.3.0" + solana-bankrun-darwin-universal "0.3.0" + solana-bankrun-darwin-x64 "0.3.0" + solana-bankrun-linux-x64-gnu "0.3.0" + solana-bankrun-linux-x64-musl "0.3.0" + +source-map-support@^0.5.6: + version "0.5.21" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" + integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + +source-map@^0.6.0: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + +string-width@^4.1.0, string-width@^4.2.0: + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" + integrity sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA== + +strip-json-comments@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" + integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== + +superstruct@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-2.0.2.tgz#3f6d32fbdc11c357deff127d591a39b996300c54" + integrity sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A== + +supports-color@8.1.1: + version "8.1.1" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +text-encoding-utf-8@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/text-encoding-utf-8/-/text-encoding-utf-8-1.0.2.tgz#585b62197b0ae437e3c7b5d0af27ac1021e10d13" + integrity sha512-8bw4MY9WjdsD2aMtO0OzOCY3pXGYNx2d2FfHRVUKkiCPDWjKuOlhLVASS+pD7VkLTVjW268LYJHwsnPFlBpbAg== + +"through@>=2.2.7 <3": + version "2.3.8" + resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" + integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg== + +to-regex-range@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4" + integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ== + dependencies: + is-number "^7.0.0" + +tr46@~0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== + +ts-mocha@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/ts-mocha/-/ts-mocha-10.0.0.tgz#41a8d099ac90dbbc64b06976c5025ffaebc53cb9" + integrity sha512-VRfgDO+iiuJFlNB18tzOfypJ21xn2xbuZyDvJvqpTbWgkAgD17ONGr8t+Tl8rcBtOBdjXp5e/Rk+d39f7XBHRw== + dependencies: + ts-node "7.0.1" + optionalDependencies: + tsconfig-paths "^3.5.0" + +ts-node@7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-7.0.1.tgz#9562dc2d1e6d248d24bc55f773e3f614337d9baf" + integrity sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw== + dependencies: + arrify "^1.0.0" + buffer-from "^1.1.0" + diff "^3.1.0" + make-error "^1.1.1" + minimist "^1.2.0" + mkdirp "^0.5.1" + source-map-support "^0.5.6" + yn "^2.0.0" + +tsconfig-paths@^3.5.0: + version "3.15.0" + resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz#5299ec605e55b1abb23ec939ef15edaf483070d4" + integrity sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg== + dependencies: + "@types/json5" "^0.0.29" + json5 "^1.0.2" + minimist "^1.2.6" + strip-bom "^3.0.0" + +tslib@^2.4.0: + version "2.6.3" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" + integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== + +type-detect@^4.0.0, type-detect@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.1.0.tgz#deb2453e8f08dcae7ae98c626b13dddb0155906c" + integrity sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw== + +typescript@^4.3.5: + version "4.9.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" + integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== + +undici-types@~6.19.2: + version "6.19.8" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" + integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== + +utf-8-validate@^5.0.2: + version "5.0.10" + resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.10.tgz#d7d10ea39318171ca982718b6b96a8d2442571a2" + integrity sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ== + dependencies: + node-gyp-build "^4.3.0" + +uuid@^8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + +webidl-conversions@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== + +whatwg-url@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" + integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw== + dependencies: + tr46 "~0.0.3" + webidl-conversions "^3.0.0" + +which@2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" + integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== + dependencies: + isexe "^2.0.0" + +workerpool@6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.0.tgz#827d93c9ba23ee2019c3ffaff5c27fccea289e8b" + integrity sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A== + +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== + +ws@^7.5.10: + version "7.5.10" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9" + integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ== + +ws@^8.5.0: + version "8.18.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc" + integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw== + +y18n@^5.0.5: + version "5.0.8" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" + integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== + +yargs-parser@20.2.4: + version "20.2.4" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54" + integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA== + +yargs-parser@^20.2.2: + version "20.2.9" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" + integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== + +yargs-unparser@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb" + integrity sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA== + dependencies: + camelcase "^6.0.0" + decamelize "^4.0.0" + flat "^5.0.2" + is-plain-obj "^2.1.0" + +yargs@16.2.0: + version "16.2.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" + integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== + dependencies: + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.0" + y18n "^5.0.5" + yargs-parser "^20.2.2" + +yn@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a" + integrity sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ== + +yocto-queue@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== diff --git a/jolt-types/Cargo.toml b/jolt-types/Cargo.toml new file mode 100644 index 000000000..71d5bec83 --- /dev/null +++ b/jolt-types/Cargo.toml @@ -0,0 +1,42 @@ +[package] +name = "jolt-types" +version = "0.1.0" +edition = "2021" + +[dependencies] +ark-bn254 = "0.4.0" +ark-ec = { version = "0.4.2", default-features = false } +ark-ff = { version = "0.4.2", default-features = false } +ark-serialize = { version = "0.4.2", default-features = false, features = [ + "derive", +] } +ark-std = { version = "0.4.0", default-features = false } +sha3 = "0.10.8" +thiserror = "1.0.63" +itertools = "0.13.0" + +[target.'cfg(not(target_os = "solana"))'.dependencies] +rand = "0.7.3" +tracing = "0.1.40" +rand_chacha = { version = "0.3.0", default-features = false } +rand_core = { version = "0.6.4", default-features = false } +rayon = { version = "^1.8.0", optional = true } +memory-stats = "1.0.0" +lazy_static = "1.4.0" + +[lib] +name = "jolt_types" +path = "src/lib.rs" + +[features] +default = [ + "ark-ec/parallel", + "ark-ff/parallel", + "ark-std/parallel", + "ark-ff/asm", + "rayon", +] + +# Handle the unexpected cfg warnings when not building for solana +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } \ No newline at end of file diff --git a/jolt-core/src/field/ark.rs b/jolt-types/src/field/ark.rs similarity index 88% rename from jolt-core/src/field/ark.rs rename to jolt-types/src/field/ark.rs index eecb9d7b9..3b5ac0f40 100644 --- a/jolt-core/src/field/ark.rs +++ b/jolt-types/src/field/ark.rs @@ -1,4 +1,6 @@ -use ark_ff::{PrimeField, UniformRand}; +#[cfg(not(target_os = "solana"))] +use ark_ff::UniformRand; +use ark_ff::{BigInt, PrimeField}; use ark_std::Zero; use super::{FieldOps, JoltField}; @@ -10,12 +12,13 @@ impl<'b> FieldOps<&'b ark_bn254::Fr, ark_bn254::Fr> for ark_bn254::Fr {} impl JoltField for ark_bn254::Fr { const NUM_BYTES: usize = 32; + #[cfg(not(target_os = "solana"))] fn random(rng: &mut R) -> Self { ::rand(rng) } fn from_u64(n: u64) -> Option { - ::from_u64(n) + ::from_bigint(BigInt::from(n)) } fn from_i64(val: i64) -> Self { diff --git a/jolt-types/src/field/mod.rs b/jolt-types/src/field/mod.rs new file mode 100644 index 000000000..0275e9975 --- /dev/null +++ b/jolt-types/src/field/mod.rs @@ -0,0 +1,93 @@ +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: + Add + + Sub + + Mul + + Div +{ +} + +pub trait JoltField: + 'static + + Sized + + Zero + + One + + Neg + + FieldOps + + for<'a> FieldOps<&'a Self, Self> + + AddAssign + + SubAssign + + MulAssign + + core::iter::Sum + + for<'a> core::iter::Sum<&'a Self> + + core::iter::Product + + for<'a> core::iter::Product<&'a Self> + + Eq + + Copy + + Sync + + Send + + Debug + + Default + + CanonicalSerialize + + CanonicalDeserialize +{ + const NUM_BYTES: usize; + #[cfg(not(target_os = "solana"))] + fn random(rng: &mut R) -> Self; + + fn from_u64(n: u64) -> Option; + fn from_i64(val: i64) -> Self; + fn square(&self) -> Self; + fn from_bytes(bytes: &[u8]) -> Self; + fn inverse(&self) -> Option; + fn to_u64(&self) -> Option { + unimplemented!("conversion to u64 not implemented"); + } +} + +pub trait OptimizedMul: Sized + Mul { + 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 OptimizedMul 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; diff --git a/jolt-types/src/lib.rs b/jolt-types/src/lib.rs new file mode 100644 index 000000000..9d0f12bd0 --- /dev/null +++ b/jolt-types/src/lib.rs @@ -0,0 +1,4 @@ +pub mod field; +pub mod poly; +#[allow(non_snake_case)] +pub mod utils; diff --git a/jolt-types/src/poly/commitment/hyperkzg/mod.rs b/jolt-types/src/poly/commitment/hyperkzg/mod.rs new file mode 100644 index 000000000..6dc49d112 --- /dev/null +++ b/jolt-types/src/poly/commitment/hyperkzg/mod.rs @@ -0,0 +1,18 @@ +use crate::poly::commitment::kzg::KZGVerifierKey; +use ark_ec::pairing::Pairing; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; + +#[derive(Copy, Clone, CanonicalSerialize, CanonicalDeserialize, Debug)] +pub struct HyperKZGVerifierKey { + pub kzg_vk: KZGVerifierKey

, +} + +#[derive(Clone, CanonicalSerialize, CanonicalDeserialize, Debug)] +pub struct HyperKZGProof { + pub com: Vec, + pub w: Vec, + pub v: Vec>, +} + +#[derive(Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize)] +pub struct HyperKZGCommitment(pub P::G1Affine); diff --git a/jolt-types/src/poly/commitment/kzg.rs b/jolt-types/src/poly/commitment/kzg.rs new file mode 100644 index 000000000..529fde5d2 --- /dev/null +++ b/jolt-types/src/poly/commitment/kzg.rs @@ -0,0 +1,9 @@ +use ark_ec::pairing::Pairing; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; + +#[derive(Clone, Copy, Debug, CanonicalSerialize, CanonicalDeserialize)] +pub struct KZGVerifierKey { + pub g1: P::G1Affine, + pub g2: P::G2Affine, + pub beta_g2: P::G2Affine, +} diff --git a/jolt-types/src/poly/commitment/mod.rs b/jolt-types/src/poly/commitment/mod.rs new file mode 100644 index 000000000..1ebfdd370 --- /dev/null +++ b/jolt-types/src/poly/commitment/mod.rs @@ -0,0 +1,2 @@ +pub mod hyperkzg; +pub mod kzg; diff --git a/jolt-types/src/poly/mod.rs b/jolt-types/src/poly/mod.rs new file mode 100644 index 000000000..1f9123814 --- /dev/null +++ b/jolt-types/src/poly/mod.rs @@ -0,0 +1 @@ +pub mod commitment; diff --git a/jolt-core/src/utils/errors.rs b/jolt-types/src/utils/errors.rs similarity index 100% rename from jolt-core/src/utils/errors.rs rename to jolt-types/src/utils/errors.rs diff --git a/jolt-core/src/utils/math.rs b/jolt-types/src/utils/math.rs similarity index 100% rename from jolt-core/src/utils/math.rs rename to jolt-types/src/utils/math.rs diff --git a/jolt-types/src/utils/mod.rs b/jolt-types/src/utils/mod.rs new file mode 100644 index 000000000..24fd18a6a --- /dev/null +++ b/jolt-types/src/utils/mod.rs @@ -0,0 +1,133 @@ +#![allow(dead_code)] +use crate::field::JoltField; + +#[cfg(not(target_os = "solana"))] +use ark_std::test_rng; +#[cfg(not(target_os = "solana"))] +use rayon::prelude::*; +pub mod errors; +pub mod math; +pub mod transcript; + +/// Converts an integer value to a bitvector (all values {0,1}) of field elements. +/// Note: ordering has the MSB in the highest index. All of the following represent the integer 1: +/// - [1] +/// - [0, 0, 1] +/// - [0, 0, 0, 0, 0, 0, 0, 1] +/// ```ignore +/// use jolt_core::utils::index_to_field_bitvector; +/// # use ark_bn254::Fr; +/// # use ark_std::{One, Zero}; +/// let zero = Fr::zero(); +/// let one = Fr::one(); +/// +/// assert_eq!(index_to_field_bitvector::(1, 1), vec![one]); +/// assert_eq!(index_to_field_bitvector::(1, 3), vec![zero, zero, one]); +/// assert_eq!(index_to_field_bitvector::(1, 7), vec![zero, zero, zero, zero, zero, zero, one]); +/// ``` +pub fn index_to_field_bitvector(value: usize, bits: usize) -> Vec { + assert!(value < 1 << bits); + + let mut bitvector: Vec = Vec::with_capacity(bits); + + for i in (0..bits).rev() { + if (value >> i) & 1 == 1 { + bitvector.push(F::one()); + } else { + bitvector.push(F::zero()); + } + } + bitvector +} + +#[cfg(not(target_os = "solana"))] +#[tracing::instrument(skip_all)] +pub fn compute_dotproduct(a: &[F], b: &[F]) -> F { + a.par_iter() + .zip_eq(b.par_iter()) + .map(|(a_i, b_i)| *a_i * *b_i) + .sum() +} + +/// Compute dotproduct optimized for values being 0 / 1 +#[cfg(not(target_os = "solana"))] +#[tracing::instrument(skip_all)] +pub fn compute_dotproduct_low_optimized(a: &[F], b: &[F]) -> F { + a.par_iter() + .zip_eq(b.par_iter()) + .map(|(a_i, b_i)| mul_0_1_optimized(a_i, b_i)) + .sum() +} + +#[inline(always)] +pub fn mul_0_1_optimized(a: &F, b: &F) -> F { + if a.is_zero() || b.is_zero() { + F::zero() + } else if a.is_one() { + *b + } else if b.is_one() { + *a + } else { + *a * *b + } +} + +#[inline(always)] +pub fn mul_0_optimized(likely_zero: &F, x: &F) -> F { + if likely_zero.is_zero() { + F::zero() + } else { + *likely_zero * *x + } +} + +/// Checks if `num` is a power of 2. +pub fn is_power_of_two(num: usize) -> bool { + num != 0 && (num & (num - 1)) == 0 +} + +/// Take the first two `num_bits` chunks of `item` (from the right / LSB) and return them as a tuple `(high_chunk, low_chunk)`. +/// +/// If `item` is shorter than `2 * num_bits`, the remaining bits are zero-padded. +/// +/// If `item` is longer than `2 * num_bits`, the remaining bits are discarded. +/// +/// # Examples +/// +/// ``` +/// use jolt_types::utils::split_bits; +/// +/// assert_eq!(split_bits(0b101000, 2), (0b10, 0b00)); +/// assert_eq!(split_bits(0b101000, 3), (0b101, 0b000)); +/// assert_eq!(split_bits(0b101000, 4), (0b0010, 0b1000)); +/// ``` +pub fn split_bits(item: usize, num_bits: usize) -> (usize, usize) { + let max_value = (1 << num_bits) - 1; // Calculate the maximum value that can be represented with num_bits + + let low_chunk = item & max_value; // Extract the lower bits + let high_chunk = (item >> num_bits) & max_value; // Shift the item to the right and extract the next set of bits + + (high_chunk, low_chunk) +} + +/// Generate a random point with `memory_bits` field elements. +#[cfg(not(target_os = "solana"))] +pub fn gen_random_point(memory_bits: usize) -> Vec { + let mut rng = test_rng(); + let mut r_i: Vec = Vec::with_capacity(memory_bits); + for _ in 0..memory_bits { + r_i.push(F::random(&mut rng)); + } + r_i +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn split() { + assert_eq!(split_bits(0b00_01, 2), (0, 1)); + assert_eq!(split_bits(0b10_01, 2), (2, 1)); + } +} diff --git a/jolt-core/src/utils/transcript.rs b/jolt-types/src/utils/transcript.rs similarity index 100% rename from jolt-core/src/utils/transcript.rs rename to jolt-types/src/utils/transcript.rs From c1f578438a726324f7ce267b6a0c26f4e6bb517e Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Fri, 23 Aug 2024 10:18:24 -0700 Subject: [PATCH 2/4] fix tests --- jolt-core/src/jolt/instruction/test.rs | 2 +- jolt-core/src/jolt/subtable/test.rs | 2 +- jolt-core/src/lasso/surge.rs | 2 +- jolt-core/src/poly/commitment/mock.rs | 3 ++- jolt-core/src/r1cs/key.rs | 3 +-- jolt-core/src/r1cs/test.rs | 2 +- jolt-sdk/Cargo.toml | 1 + jolt-sdk/src/host_utils.rs | 3 ++- 8 files changed, 10 insertions(+), 8 deletions(-) diff --git a/jolt-core/src/jolt/instruction/test.rs b/jolt-core/src/jolt/instruction/test.rs index 670e8b354..faedecf68 100644 --- a/jolt-core/src/jolt/instruction/test.rs +++ b/jolt-core/src/jolt/instruction/test.rs @@ -7,7 +7,7 @@ /// 4. Checks that the result equals the expected value, given by the `lookup_output` macro_rules! jolt_instruction_test { ($instr:expr) => { - use $crate::field::JoltField; + use jolt_types::field::JoltField; let subtable_lookup_indices = $instr.to_indices(C, ark_std::log2(M) as usize); diff --git a/jolt-core/src/jolt/subtable/test.rs b/jolt-core/src/jolt/subtable/test.rs index a424fc61f..4c6b5f953 100644 --- a/jolt-core/src/jolt/subtable/test.rs +++ b/jolt-core/src/jolt/subtable/test.rs @@ -14,7 +14,7 @@ macro_rules! subtable_materialize_mle_parity_test { for i in 0..M { assert_eq!( materialized[i], - subtable.evaluate_mle(&$crate::utils::index_to_field_bitvector(i, log_M)), + subtable.evaluate_mle(&jolt_types::utils::index_to_field_bitvector(i, log_M)), "MLE did not match materialized subtable at index {}", i ); diff --git a/jolt-core/src/lasso/surge.rs b/jolt-core/src/lasso/surge.rs index d8bfa9392..6fff57a9f 100644 --- a/jolt-core/src/lasso/surge.rs +++ b/jolt-core/src/lasso/surge.rs @@ -788,9 +788,9 @@ mod tests { jolt::instruction::xor::XORInstruction, lasso::surge::SurgeProof, poly::{commitment::hyrax::HyraxScheme, commitment::pedersen::PedersenGenerators}, - utils::transcript::ProofTranscript, }; use ark_bn254::{Fr, G1Projective}; + use jolt_types::utils::transcript::ProofTranscript; #[test] fn e2e() { diff --git a/jolt-core/src/poly/commitment/mock.rs b/jolt-core/src/poly/commitment/mock.rs index 59f443911..dd3f2a664 100644 --- a/jolt-core/src/poly/commitment/mock.rs +++ b/jolt-core/src/poly/commitment/mock.rs @@ -2,7 +2,8 @@ use std::marker::PhantomData; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use crate::{field::JoltField, poly::dense_mlpoly::DensePolynomial}; +use crate::poly::dense_mlpoly::DensePolynomial; +use jolt_types::field::JoltField; use jolt_types::utils::{ errors::ProofVerifyError, transcript::{AppendToTranscript, ProofTranscript}, diff --git a/jolt-core/src/r1cs/key.rs b/jolt-core/src/r1cs/key.rs index e8a86d08a..74676de56 100644 --- a/jolt-core/src/r1cs/key.rs +++ b/jolt-core/src/r1cs/key.rs @@ -439,9 +439,8 @@ mod test { materialize_full_uniform, simp_test_big_matrices, simp_test_builder_key, TestInputs, }, }, - utils::index_to_field_bitvector, }; - use jolt_types::utils::math::Math; + use jolt_types::utils::{index_to_field_bitvector, math::Math}; use strum::EnumCount; #[test] diff --git a/jolt-core/src/r1cs/test.rs b/jolt-core/src/r1cs/test.rs index a6b1c09b7..8067e7997 100644 --- a/jolt-core/src/r1cs/test.rs +++ b/jolt-core/src/r1cs/test.rs @@ -1,8 +1,8 @@ use crate::{ - field::JoltField, impl_r1cs_input_lc_conversions, r1cs::builder::{OffsetEqConstraint, R1CSBuilder, R1CSConstraintBuilder}, }; +use jolt_types::field::JoltField; use super::{ builder::CombinedUniformBuilder, diff --git a/jolt-sdk/Cargo.toml b/jolt-sdk/Cargo.toml index a3a6c7813..76389d657 100644 --- a/jolt-sdk/Cargo.toml +++ b/jolt-sdk/Cargo.toml @@ -42,5 +42,6 @@ ark-serialize = { version = "0.4.2", features = ["derive"], optional = true } jolt-sdk-macros = { path = "./macros" } jolt-core = { path = "../jolt-core", optional = true } +jolt-types = { path = "../jolt-types" } tracer = { path = "../tracer", optional = true } common = { path = "../common", optional = true } diff --git a/jolt-sdk/src/host_utils.rs b/jolt-sdk/src/host_utils.rs index a11c9b16b..b124cca16 100644 --- a/jolt-sdk/src/host_utils.rs +++ b/jolt-sdk/src/host_utils.rs @@ -1,6 +1,7 @@ pub use ark_bn254::{Fr as F, G1Projective as G}; pub use ark_ec::CurveGroup; -pub use jolt_core::{field::JoltField, poly::commitment::hyrax::HyraxScheme}; +pub use jolt_core::poly::commitment::hyrax::HyraxScheme; +pub use jolt_types::field::JoltField; pub use common::{ constants::MEMORY_OPS_PER_INSTRUCTION, From f859c1122d92f4d1077c88415379ef9226513cce Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Fri, 23 Aug 2024 14:59:16 -0700 Subject: [PATCH 3/4] fix evm-verifier and fmt --- jolt-evm-verifier/script/Cargo.toml | 1 + .../script/src/bin/autogenerate_r1cs.rs | 2 +- .../script/src/bin/grand_product_example.rs | 17 ++++++----------- .../script/src/bin/hyperkzg_batch_example.rs | 2 +- .../script/src/bin/hyperkzg_example.rs | 2 +- .../script/src/bin/transcript_example.rs | 2 +- jolt-sdk/Cargo.toml | 3 ++- jolt-svm-verifier/program/Cargo.toml | 2 -- 8 files changed, 13 insertions(+), 18 deletions(-) diff --git a/jolt-evm-verifier/script/Cargo.toml b/jolt-evm-verifier/script/Cargo.toml index 8ae8ca3ec..b9ab4b2c9 100644 --- a/jolt-evm-verifier/script/Cargo.toml +++ b/jolt-evm-verifier/script/Cargo.toml @@ -16,6 +16,7 @@ ark-serialize = "0.4.2" ark-ec = "0.4.2" ark-std = "0.4.0" jolt-core = { path = "../../jolt-core", package = "jolt-core"} +jolt-types = { path = "../../jolt-types" } rand_core = "0.6.4" rand_chacha = { version = "0.3.0", default-features = false } diff --git a/jolt-evm-verifier/script/src/bin/autogenerate_r1cs.rs b/jolt-evm-verifier/script/src/bin/autogenerate_r1cs.rs index 9137dd56c..aa8ab64e0 100644 --- a/jolt-evm-verifier/script/src/bin/autogenerate_r1cs.rs +++ b/jolt-evm-verifier/script/src/bin/autogenerate_r1cs.rs @@ -1,7 +1,7 @@ use alloy_primitives::hex; -use jolt_core::field::JoltField; use jolt_core::r1cs::key::SparseConstraints; use jolt_core::r1cs::key::SparseEqualityItem; +use jolt_types::field::JoltField; // This code is provided as an example of how to turn the sparse constraints into solidity, and was the base // for the code in R1CSMatrix, however because the key is not expected to change often full auto-generation is not diff --git a/jolt-evm-verifier/script/src/bin/grand_product_example.rs b/jolt-evm-verifier/script/src/bin/grand_product_example.rs index 4989a0eee..d51afb0f2 100644 --- a/jolt-evm-verifier/script/src/bin/grand_product_example.rs +++ b/jolt-evm-verifier/script/src/bin/grand_product_example.rs @@ -1,10 +1,9 @@ use jolt_core::{ - field::JoltField, poly::commitment::hyperkzg::HyperKZG, subprotocols::grand_product::{BatchedDenseGrandProduct, BatchedGrandProduct}, - utils::transcript::ProofTranscript, - utils::sol_types::GrandProductProof + utils::sol_types::GrandProductProof, }; +use jolt_types::{field::JoltField, utils::transcript::ProofTranscript}; use std::env; use alloy_primitives::{hex, U256}; @@ -20,10 +19,9 @@ fn get_proof_data(batched_circuit: &mut BatchedDenseGrandProduct) { Fr, HyperKZG, >>::prove_grand_product(batched_circuit, &mut transcript, None); - let claims = - as BatchedGrandProduct>>::claims( - batched_circuit, - ); + let claims = as BatchedGrandProduct>>::claims( + batched_circuit, + ); //encoding the proof into abi @@ -33,10 +31,7 @@ fn get_proof_data(batched_circuit: &mut BatchedDenseGrandProduct) { uint256[] r_prover; }); - let r_prover = r_prover - .iter() - .map(fr_to_uint256) - .collect::>(); + let r_prover = r_prover.iter().map(fr_to_uint256).collect::>(); let claims = claims.iter().map(fr_to_uint256).collect::>(); diff --git a/jolt-evm-verifier/script/src/bin/hyperkzg_batch_example.rs b/jolt-evm-verifier/script/src/bin/hyperkzg_batch_example.rs index f2dbd349e..27bb4411e 100644 --- a/jolt-evm-verifier/script/src/bin/hyperkzg_batch_example.rs +++ b/jolt-evm-verifier/script/src/bin/hyperkzg_batch_example.rs @@ -9,7 +9,7 @@ use ark_std::UniformRand; use jolt_core::poly::commitment::commitment_scheme::{BatchType, CommitmentScheme}; use jolt_core::poly::commitment::hyperkzg::*; use jolt_core::poly::dense_mlpoly::DensePolynomial; -use jolt_core::utils::transcript::ProofTranscript; +use jolt_types::utils::transcript::ProofTranscript; use rand_core::SeedableRng; use jolt_core::utils::sol_types::{HyperKZGProofSol, VK}; diff --git a/jolt-evm-verifier/script/src/bin/hyperkzg_example.rs b/jolt-evm-verifier/script/src/bin/hyperkzg_example.rs index 8e2ed2147..c3602f10b 100644 --- a/jolt-evm-verifier/script/src/bin/hyperkzg_example.rs +++ b/jolt-evm-verifier/script/src/bin/hyperkzg_example.rs @@ -8,7 +8,7 @@ use ark_ff::PrimeField; use ark_std::UniformRand; use jolt_core::poly::commitment::hyperkzg::*; use jolt_core::poly::dense_mlpoly::DensePolynomial; -use jolt_core::utils::transcript::ProofTranscript; +use jolt_types::utils::transcript::ProofTranscript; use rand_core::SeedableRng; use jolt_core::utils::sol_types::{HyperKZGProofSol, VK}; diff --git a/jolt-evm-verifier/script/src/bin/transcript_example.rs b/jolt-evm-verifier/script/src/bin/transcript_example.rs index 9e2847059..9dd5981ae 100644 --- a/jolt-evm-verifier/script/src/bin/transcript_example.rs +++ b/jolt-evm-verifier/script/src/bin/transcript_example.rs @@ -1,4 +1,4 @@ -use jolt_core::{field::JoltField, utils::transcript::ProofTranscript}; +use jolt_types::{field::JoltField, utils::transcript::ProofTranscript}; use ark_ff::{BigInteger, PrimeField}; diff --git a/jolt-sdk/Cargo.toml b/jolt-sdk/Cargo.toml index 76389d657..9cf6f04d6 100644 --- a/jolt-sdk/Cargo.toml +++ b/jolt-sdk/Cargo.toml @@ -17,6 +17,7 @@ host = [ "dep:tracer", "dep:common", "dep:jolt-core", + "dep:jolt-types", "dep:ark-ec", "dep:ark-ff", "dep:ark-bn254", @@ -42,6 +43,6 @@ ark-serialize = { version = "0.4.2", features = ["derive"], optional = true } jolt-sdk-macros = { path = "./macros" } jolt-core = { path = "../jolt-core", optional = true } -jolt-types = { path = "../jolt-types" } +jolt-types = { path = "../jolt-types", optional = true } tracer = { path = "../tracer", optional = true } common = { path = "../common", optional = true } diff --git a/jolt-svm-verifier/program/Cargo.toml b/jolt-svm-verifier/program/Cargo.toml index 4bdaf9369..f115b5c03 100644 --- a/jolt-svm-verifier/program/Cargo.toml +++ b/jolt-svm-verifier/program/Cargo.toml @@ -5,8 +5,6 @@ description = "SVM program to verify JOLT proofs" edition = "2021" [workspace] -members = [ -] [lib] crate-type = ["cdylib", "lib"] From 5f8baed291d5c1935bde66995855af685d7139ae Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Thu, 29 Aug 2024 10:45:37 -0700 Subject: [PATCH 4/4] feat: SVM support for GrandProduct --- jolt-core/Cargo.toml | 2 +- jolt-core/src/jolt/subtable/srl.rs | 2 +- jolt-core/src/jolt/vm/instruction_lookups.rs | 7 +- jolt-core/src/jolt/vm/read_write_memory.rs | 3 +- jolt-core/src/lasso/surge.rs | 3 +- jolt-core/src/poly/commitment/hyperkzg.rs | 3 +- jolt-core/src/poly/commitment/kzg.rs | 2 +- jolt-core/src/poly/commitment/zeromorph.rs | 6 +- jolt-core/src/poly/mod.rs | 1 - jolt-core/src/r1cs/spartan.rs | 8 +- jolt-core/src/subprotocols/grand_product.rs | 27 +- .../src/subprotocols/grand_product_quarks.rs | 3 +- jolt-core/src/subprotocols/sumcheck.rs | 129 +++++---- jolt-core/src/utils/mod.rs | 1 - jolt-core/src/utils/sol_types.rs | 4 +- jolt-svm-verifier/program/Cargo.toml | 2 +- jolt-svm-verifier/program/src/constants.rs | 104 -------- jolt-svm-verifier/program/src/instruction.rs | 17 ++ jolt-svm-verifier/program/src/lib.rs | 36 ++- .../program/src/subprotocols/grand_product.rs | 140 ++++++++++ .../program/src/subprotocols/mod.rs | 3 + .../program/src/test_constants.rs | 248 ++++++++++++++++++ jolt-svm-verifier/tests/jolt-verifier.ts | 23 +- jolt-types/Cargo.toml | 3 +- jolt-types/src/lib.rs | 1 + jolt-types/src/poly/mod.rs | 1 + {jolt-core => jolt-types}/src/poly/unipoly.rs | 77 ++++-- jolt-types/src/subprotocols/grand_product.rs | 25 ++ jolt-types/src/subprotocols/mod.rs | 2 + jolt-types/src/subprotocols/sumcheck.rs | 64 +++++ .../src/utils/gaussian_elimination.rs | 2 +- jolt-types/src/utils/mod.rs | 1 + 32 files changed, 700 insertions(+), 250 deletions(-) delete mode 100644 jolt-svm-verifier/program/src/constants.rs create mode 100644 jolt-svm-verifier/program/src/instruction.rs create mode 100644 jolt-svm-verifier/program/src/subprotocols/grand_product.rs create mode 100644 jolt-svm-verifier/program/src/test_constants.rs rename {jolt-core => jolt-types}/src/poly/unipoly.rs (87%) create mode 100644 jolt-types/src/subprotocols/grand_product.rs create mode 100644 jolt-types/src/subprotocols/mod.rs create mode 100644 jolt-types/src/subprotocols/sumcheck.rs rename {jolt-core => jolt-types}/src/utils/gaussian_elimination.rs (98%) diff --git a/jolt-core/Cargo.toml b/jolt-core/Cargo.toml index 0fd28a725..f6c673b2e 100644 --- a/jolt-core/Cargo.toml +++ b/jolt-core/Cargo.toml @@ -20,7 +20,7 @@ license-file = "LICENSE" keywords = ["SNARK", "cryptography", "proofs"] [dependencies] -jolt-types = { path = "../jolt-types" } +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 } diff --git a/jolt-core/src/jolt/subtable/srl.rs b/jolt-core/src/jolt/subtable/srl.rs index e1d8bbe65..185f97de5 100644 --- a/jolt-core/src/jolt/subtable/srl.rs +++ b/jolt-core/src/jolt/subtable/srl.rs @@ -1,6 +1,6 @@ use ark_std::log2; -use std::cmp::min; use jolt_types::field::JoltField; +use std::cmp::min; use std::marker::PhantomData; use super::LassoSubtable; diff --git a/jolt-core/src/jolt/vm/instruction_lookups.rs b/jolt-core/src/jolt/vm/instruction_lookups.rs index bb2ab31fd..fc4d501cb 100644 --- a/jolt-core/src/jolt/vm/instruction_lookups.rs +++ b/jolt-core/src/jolt/vm/instruction_lookups.rs @@ -1,3 +1,4 @@ +use super::JoltTraceStep; use crate::jolt::instruction::{JoltInstructionSet, SubtableIndices}; use crate::jolt::subtable::JoltSubtableSet; use crate::lasso::memory_checking::MultisetHashes; @@ -10,13 +11,13 @@ use crate::{ eq_poly::EqPolynomial, identity_poly::IdentityPolynomial, structured_poly::{StructuredCommitment, StructuredOpeningProof}, - unipoly::{CompressedUniPoly, UniPoly}, }, - subprotocols::sumcheck::SumcheckInstanceProof, }; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use itertools::{interleave, Itertools}; use jolt_types::field::JoltField; +use jolt_types::poly::unipoly::{CompressedUniPoly, UniPoly}; +use jolt_types::subprotocols::sumcheck::SumcheckInstanceProof; use jolt_types::utils::mul_0_1_optimized; use jolt_types::utils::{ errors::ProofVerifyError, @@ -28,8 +29,6 @@ use rayon::prelude::*; use std::marker::PhantomData; use tracing::trace_span; -use super::JoltTraceStep; - /// All polynomials associated with Jolt instruction lookups. pub struct InstructionPolynomials where diff --git a/jolt-core/src/jolt/vm/read_write_memory.rs b/jolt-core/src/jolt/vm/read_write_memory.rs index 304826359..d575f696b 100644 --- a/jolt-core/src/jolt/vm/read_write_memory.rs +++ b/jolt-core/src/jolt/vm/read_write_memory.rs @@ -12,6 +12,7 @@ use std::sync::{Arc, Mutex}; use super::JoltTraceStep; use super::{timestamp_range_check::TimestampValidityProof, JoltCommitments, JoltPolynomials}; use crate::poly::commitment::commitment_scheme::{BatchType, CommitShape, CommitmentScheme}; +use crate::subprotocols::sumcheck::SumcheckProve; use crate::{ lasso::memory_checking::{ MemoryCheckingProof, MemoryCheckingProver, MemoryCheckingVerifier, MultisetHashes, @@ -21,7 +22,6 @@ use crate::{ dense_mlpoly::DensePolynomial, eq_poly::EqPolynomial, identity_poly::IdentityPolynomial, structured_poly::StructuredOpeningProof, }, - subprotocols::sumcheck::SumcheckInstanceProof, }; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use common::constants::{ @@ -29,6 +29,7 @@ use common::constants::{ RAM_OPS_PER_INSTRUCTION, RAM_START_ADDRESS, REGISTER_COUNT, REG_OPS_PER_INSTRUCTION, }; use common::rv_trace::{JoltDevice, MemoryLayout, MemoryOp}; +use jolt_types::subprotocols::sumcheck::SumcheckInstanceProof; use jolt_types::utils::transcript::AppendToTranscript; use jolt_types::utils::{ errors::ProofVerifyError, math::Math, mul_0_optimized, transcript::ProofTranscript, diff --git a/jolt-core/src/lasso/surge.rs b/jolt-core/src/lasso/surge.rs index 6fff57a9f..cad73fed0 100644 --- a/jolt-core/src/lasso/surge.rs +++ b/jolt-core/src/lasso/surge.rs @@ -4,6 +4,7 @@ use jolt_types::field::JoltField; use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::marker::{PhantomData, Sync}; +use crate::subprotocols::sumcheck::SumcheckProve; use crate::{ jolt::instruction::JoltInstruction, lasso::memory_checking::{MemoryCheckingProof, MemoryCheckingProver, MemoryCheckingVerifier}, @@ -14,8 +15,8 @@ use crate::{ identity_poly::IdentityPolynomial, structured_poly::{StructuredCommitment, StructuredOpeningProof}, }, - subprotocols::sumcheck::SumcheckInstanceProof, }; +use jolt_types::subprotocols::sumcheck::SumcheckInstanceProof; use jolt_types::utils::{ errors::ProofVerifyError, math::Math, mul_0_1_optimized, transcript::ProofTranscript, }; diff --git a/jolt-core/src/poly/commitment/hyperkzg.rs b/jolt-core/src/poly/commitment/hyperkzg.rs index 86e089069..113fedce6 100644 --- a/jolt-core/src/poly/commitment/hyperkzg.rs +++ b/jolt-core/src/poly/commitment/hyperkzg.rs @@ -15,7 +15,7 @@ use crate::poly::commitment::commitment_scheme::CommitShape; use crate::utils::thread::unsafe_allocate_zero_vec; use crate::{ msm::VariableBaseMSM, - poly::{commitment::kzg::SRS, dense_mlpoly::DensePolynomial, unipoly::UniPoly}, + poly::{commitment::kzg::SRS, dense_mlpoly::DensePolynomial}, }; use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; @@ -36,6 +36,7 @@ use std::{marker::PhantomData, sync::Arc}; use tracing::trace_span; pub use jolt_types::poly::commitment::hyperkzg::{HyperKZGProof, HyperKZGVerifierKey}; +use jolt_types::poly::unipoly::UniPoly; pub struct HyperKZGSRS(Arc>); diff --git a/jolt-core/src/poly/commitment/kzg.rs b/jolt-core/src/poly/commitment/kzg.rs index e3798a16a..e3b592db9 100644 --- a/jolt-core/src/poly/commitment/kzg.rs +++ b/jolt-core/src/poly/commitment/kzg.rs @@ -1,10 +1,10 @@ use crate::msm::VariableBaseMSM; -use crate::poly::unipoly::UniPoly; use ark_ec::scalar_mul::fixed_base::FixedBase; use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup}; use ark_ff::PrimeField; use ark_std::{One, UniformRand, Zero}; use jolt_types::field::JoltField; +use jolt_types::poly::unipoly::UniPoly; use jolt_types::utils::errors::ProofVerifyError; use rand_core::{CryptoRng, RngCore}; use std::marker::PhantomData; diff --git a/jolt-core/src/poly/commitment/zeromorph.rs b/jolt-core/src/poly/commitment/zeromorph.rs index 13c5783be..61c873008 100644 --- a/jolt-core/src/poly/commitment/zeromorph.rs +++ b/jolt-core/src/poly/commitment/zeromorph.rs @@ -4,7 +4,7 @@ use std::{iter, marker::PhantomData}; use crate::msm::VariableBaseMSM; -use crate::poly::{dense_mlpoly::DensePolynomial, unipoly::UniPoly}; +use crate::poly::dense_mlpoly::DensePolynomial; use crate::utils::thread::unsafe_allocate_zero_vec; use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup}; use ark_ff::{batch_inversion, Field}; @@ -22,12 +22,12 @@ use rand_core::{CryptoRng, RngCore}; use std::sync::Arc; use tracing::trace_span; -use rayon::prelude::*; - use super::{ commitment_scheme::{BatchType, CommitShape, CommitmentScheme}, kzg::{KZGProverKey, KZGVerifierKey, UnivariateKZG, SRS}, }; +use jolt_types::poly::unipoly::UniPoly; +use rayon::prelude::*; pub struct ZeromorphSRS(Arc>); diff --git a/jolt-core/src/poly/mod.rs b/jolt-core/src/poly/mod.rs index d2480d420..bad28a2a5 100644 --- a/jolt-core/src/poly/mod.rs +++ b/jolt-core/src/poly/mod.rs @@ -3,4 +3,3 @@ pub mod dense_mlpoly; pub mod eq_poly; pub mod identity_poly; pub mod structured_poly; -pub mod unipoly; diff --git a/jolt-core/src/r1cs/spartan.rs b/jolt-core/src/r1cs/spartan.rs index c65f670ea..6e6841aec 100644 --- a/jolt-core/src/r1cs/spartan.rs +++ b/jolt-core/src/r1cs/spartan.rs @@ -14,13 +14,11 @@ use jolt_types::utils::transcript::ProofTranscript; use thiserror::Error; -use crate::{ - poly::{dense_mlpoly::DensePolynomial, eq_poly::EqPolynomial}, - subprotocols::sumcheck::SumcheckInstanceProof, -}; - use super::builder::CombinedUniformBuilder; use super::ops::ConstraintInput; +use crate::poly::{dense_mlpoly::DensePolynomial, eq_poly::EqPolynomial}; +use crate::subprotocols::sumcheck::SumcheckProve; +use jolt_types::subprotocols::sumcheck::SumcheckInstanceProof; #[derive(Clone, Debug, Eq, PartialEq, Error)] pub enum SpartanError { diff --git a/jolt-core/src/subprotocols/grand_product.rs b/jolt-core/src/subprotocols/grand_product.rs index 063f265a8..c772e461f 100644 --- a/jolt-core/src/subprotocols/grand_product.rs +++ b/jolt-core/src/subprotocols/grand_product.rs @@ -1,38 +1,19 @@ use super::grand_product_quarks::QuarkGrandProductProof; -use super::sumcheck::{BatchedCubicSumcheck, SumcheckInstanceProof}; +use super::sumcheck::BatchedCubicSumcheck; use crate::poly::commitment::commitment_scheme::CommitmentScheme; +use crate::poly::dense_mlpoly::DensePolynomial; use crate::poly::eq_poly::EqPolynomial; -use crate::poly::{dense_mlpoly::DensePolynomial, unipoly::UniPoly}; use crate::utils::thread::drop_in_background_thread; use ark_ff::Zero; use ark_serialize::*; use itertools::Itertools; use jolt_types::field::{JoltField, OptimizedMul}; +use jolt_types::poly::unipoly::UniPoly; +use jolt_types::subprotocols::grand_product::BatchedGrandProductLayerProof; use jolt_types::utils::math::Math; use jolt_types::utils::transcript::ProofTranscript; use rayon::prelude::*; -#[derive(CanonicalSerialize, CanonicalDeserialize)] -pub struct BatchedGrandProductLayerProof { - pub proof: SumcheckInstanceProof, - pub left_claims: Vec, - pub right_claims: Vec, -} - -impl BatchedGrandProductLayerProof { - pub fn verify( - &self, - claim: F, - num_rounds: usize, - degree_bound: usize, - transcript: &mut ProofTranscript, - ) -> (F, Vec) { - self.proof - .verify(claim, num_rounds, degree_bound, transcript) - .unwrap() - } -} - #[derive(CanonicalSerialize, CanonicalDeserialize)] pub struct BatchedGrandProductProof { pub layers: Vec>, diff --git a/jolt-core/src/subprotocols/grand_product_quarks.rs b/jolt-core/src/subprotocols/grand_product_quarks.rs index b724c91ea..82a67a08f 100644 --- a/jolt-core/src/subprotocols/grand_product_quarks.rs +++ b/jolt-core/src/subprotocols/grand_product_quarks.rs @@ -2,14 +2,15 @@ use super::grand_product::{ BatchedDenseGrandProductLayer, BatchedGrandProduct, BatchedGrandProductLayer, BatchedGrandProductProof, }; -use super::sumcheck::SumcheckInstanceProof; use crate::poly::commitment::commitment_scheme::{BatchType, CommitmentScheme}; use crate::poly::dense_mlpoly::DensePolynomial; use crate::poly::eq_poly::EqPolynomial; +use crate::subprotocols::sumcheck::SumcheckProve; use ark_serialize::*; use ark_std::{One, Zero}; use itertools::Itertools; use jolt_types::field::JoltField; +use jolt_types::subprotocols::sumcheck::SumcheckInstanceProof; use jolt_types::utils::math::Math; use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use rayon::prelude::*; diff --git a/jolt-core/src/subprotocols/sumcheck.rs b/jolt-core/src/subprotocols/sumcheck.rs index 747bc7590..908146adf 100644 --- a/jolt-core/src/subprotocols/sumcheck.rs +++ b/jolt-core/src/subprotocols/sumcheck.rs @@ -2,16 +2,68 @@ #![allow(clippy::type_complexity)] use crate::poly::dense_mlpoly::DensePolynomial; -use crate::poly::unipoly::{CompressedUniPoly, UniPoly}; use crate::r1cs::special_polys::{IndexablePoly, SparsePolynomial, SparseTripleIterator}; use crate::utils::thread::drop_in_background_thread; -use ark_serialize::*; use jolt_types::field::JoltField; -use jolt_types::utils::errors::ProofVerifyError; +use jolt_types::poly::unipoly::{CompressedUniPoly, UniPoly}; +use jolt_types::subprotocols::sumcheck::SumcheckInstanceProof; use jolt_types::utils::mul_0_optimized; use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; use rayon::prelude::*; +pub trait SumcheckProve { + fn prove_arbitrary( + claim: &F, + num_rounds: usize, + polys: &mut Vec>, + comb_func: Func, + combined_degree: usize, + transcript: &mut ProofTranscript, + ) -> (Self, Vec, Vec) + where + Func: Fn(&[F]) -> F + std::marker::Sync, + Self: Sized; + + fn compute_eval_points_spartan_cubic( + poly_eq: &DensePolynomial, + poly_A: &SparsePolynomial, + poly_B: &SparsePolynomial, + poly_C: &SparsePolynomial, + comb_func: &Func, + ) -> (F, F, F) + where + Func: Fn(&F, &F, &F, &F) -> F + Sync; + + fn prove_spartan_cubic( + claim: &F, + num_rounds: usize, + poly_eq: &mut DensePolynomial, + poly_A: &mut SparsePolynomial, + poly_B: &mut SparsePolynomial, + poly_C: &mut SparsePolynomial, + comb_func: Func, + transcript: &mut ProofTranscript, + ) -> (Self, Vec, Vec) + where + Func: Fn(&F, &F, &F, &F) -> F + Sync, + Self: Sized; + + fn prove_spartan_quadratic>( + claim: &F, + num_rounds: usize, + poly_A: &mut DensePolynomial, + W: &P, + transcript: &mut ProofTranscript, + ) -> (Self, Vec, Vec) + where + Self: Sized; + + fn compute_eval_points_spartan_quadratic( + poly_A: &DensePolynomial, + poly_B: &DensePolynomial, + ) -> (F, F); +} + /// Batched cubic sumcheck used in grand products pub trait BatchedCubicSumcheck: Sync { fn num_rounds(&self) -> usize; @@ -64,7 +116,7 @@ pub trait BatchedCubicSumcheck: Sync { } } -impl SumcheckInstanceProof { +impl SumcheckProve for SumcheckInstanceProof { /// Create a sumcheck proof for polynomial(s) of arbitrary degree. /// /// Params @@ -78,7 +130,7 @@ impl SumcheckInstanceProof { /// - `r_eval_point`: Final random point of evaluation /// - `final_evals`: Each of the polys evaluated at `r_eval_point` #[tracing::instrument(skip_all, name = "Sumcheck.prove")] - pub fn prove_arbitrary( + fn prove_arbitrary( _claim: &F, num_rounds: usize, polys: &mut Vec>, @@ -182,7 +234,7 @@ impl SumcheckInstanceProof { name = "Spartan2::sumcheck::compute_eval_points_spartan_cubic" )] /// Binds from the bottom rather than the top. - pub fn compute_eval_points_spartan_cubic( + fn compute_eval_points_spartan_cubic( poly_eq: &DensePolynomial, poly_A: &SparsePolynomial, poly_B: &SparsePolynomial, @@ -249,7 +301,7 @@ impl SumcheckInstanceProof { } #[tracing::instrument(skip_all, name = "Spartan2::sumcheck::prove_spartan_cubic")] - pub fn prove_spartan_cubic( + fn prove_spartan_cubic( claim: &F, num_rounds: usize, poly_eq: &mut DensePolynomial, @@ -322,7 +374,7 @@ impl SumcheckInstanceProof { // passing them in as a single `MultilinearPolynomial`, which would require // an expensive concatenation. We defer the actual instantation of a // `MultilinearPolynomial` to the end of the 0th round. - pub fn prove_spartan_quadratic>( + fn prove_spartan_quadratic>( claim: &F, num_rounds: usize, poly_A: &mut DensePolynomial, @@ -454,7 +506,7 @@ impl SumcheckInstanceProof { #[inline] #[tracing::instrument(skip_all, name = "Sumcheck::compute_eval_points_spartan_quadratic")] - pub fn compute_eval_points_spartan_quadratic( + fn compute_eval_points_spartan_quadratic( poly_A: &DensePolynomial, poly_B: &DensePolynomial, ) -> (F, F) { @@ -483,62 +535,3 @@ impl SumcheckInstanceProof { .reduce(|| (F::zero(), F::zero()), |a, b| (a.0 + b.0, a.1 + b.1)) } } - -#[derive(CanonicalSerialize, CanonicalDeserialize, Debug)] -pub struct SumcheckInstanceProof { - pub compressed_polys: Vec>, -} - -impl SumcheckInstanceProof { - pub fn new(compressed_polys: Vec>) -> SumcheckInstanceProof { - SumcheckInstanceProof { compressed_polys } - } - - /// Verify this sumcheck proof. - /// Note: Verification does not execute the final check of sumcheck protocol: g_v(r_v) = oracle_g(r), - /// as the oracle is not passed in. Expected that the caller will implement. - /// - /// Params - /// - `claim`: Claimed evaluation - /// - `num_rounds`: Number of rounds of sumcheck, or number of variables to bind - /// - `degree_bound`: Maximum allowed degree of the combined univariate polynomial - /// - `transcript`: Fiat-shamir transcript - /// - /// Returns (e, r) - /// - `e`: Claimed evaluation at random point - /// - `r`: Evaluation point - pub fn verify( - &self, - claim: F, - num_rounds: usize, - degree_bound: usize, - transcript: &mut ProofTranscript, - ) -> Result<(F, Vec), ProofVerifyError> { - let mut e = claim; - let mut r: Vec = Vec::new(); - - // verify that there is a univariate polynomial for each round - assert_eq!(self.compressed_polys.len(), num_rounds); - for i in 0..self.compressed_polys.len() { - // verify degree bound - if self.compressed_polys[i].degree() != degree_bound { - return Err(ProofVerifyError::InvalidInputLength( - degree_bound, - self.compressed_polys[i].degree(), - )); - } - - // append the prover's message to the transcript - self.compressed_polys[i].append_to_transcript(transcript); - - //derive the verifier's challenge for the next round - let r_i = transcript.challenge_scalar(); - r.push(r_i); - - // evaluate the claimed degree-ell polynomial at r_i using the hint - e = self.compressed_polys[i].eval_from_hint(&e, &r_i); - } - - Ok((e, r)) - } -} diff --git a/jolt-core/src/utils/mod.rs b/jolt-core/src/utils/mod.rs index 57881a121..d469a0a68 100644 --- a/jolt-core/src/utils/mod.rs +++ b/jolt-core/src/utils/mod.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -pub mod gaussian_elimination; pub mod instruction_utils; pub mod profiling; pub mod sol_types; diff --git a/jolt-core/src/utils/sol_types.rs b/jolt-core/src/utils/sol_types.rs index a1272092e..93661fe3a 100644 --- a/jolt-core/src/utils/sol_types.rs +++ b/jolt-core/src/utils/sol_types.rs @@ -4,15 +4,15 @@ use ark_ff::PrimeField; use crate::poly::commitment::hyperkzg::{HyperKZG, HyperKZGProof, HyperKZGVerifierKey}; use crate::r1cs::spartan::UniformSpartanProof; -use crate::subprotocols::grand_product::BatchedGrandProductLayerProof; use crate::subprotocols::grand_product::BatchedGrandProductProof; -use crate::subprotocols::sumcheck::SumcheckInstanceProof; use alloy_primitives::U256; use alloy_sol_types::sol; use ark_bn254::FrConfig; use ark_ff::Fp; use ark_ff::MontBackend; use jolt_types::field::JoltField; +use jolt_types::subprotocols::grand_product::BatchedGrandProductLayerProof; +use jolt_types::subprotocols::sumcheck::SumcheckInstanceProof; sol!(struct HyperKZGProofSol { uint256[] com; // G1 points represented pairwise diff --git a/jolt-svm-verifier/program/Cargo.toml b/jolt-svm-verifier/program/Cargo.toml index f115b5c03..9556254a3 100644 --- a/jolt-svm-verifier/program/Cargo.toml +++ b/jolt-svm-verifier/program/Cargo.toml @@ -20,4 +20,4 @@ solana-program = "2.0.6" jolt-types = { path = "../../jolt-types", default-features = false } [target.'cfg(not(target_os = "solana"))'.dependencies] -jolt-types = { path = "../../jolt-types" } \ No newline at end of file +jolt-types = { path = "../../jolt-types" } diff --git a/jolt-svm-verifier/program/src/constants.rs b/jolt-svm-verifier/program/src/constants.rs deleted file mode 100644 index a3f43e229..000000000 --- a/jolt-svm-verifier/program/src/constants.rs +++ /dev/null @@ -1,104 +0,0 @@ -pub const POINT_BYTES: [u8; 72] = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -]; -pub const EVAL_BYTES: [u8; 32] = [ - 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -]; -pub const V_POS_BYTES: [u8; 88] = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x30, 0x53, 0x70, 0xf2, 0xee, 0x18, 0x3d, 0x60, 0x13, 0xea, 0x65, 0xf4, 0xf7, 0x30, 0xe2, 0xc7, - 0xbf, 0xd4, 0x62, 0xdf, 0x8a, 0xbe, 0xec, 0x65, 0xed, 0x4b, 0x2d, 0x07, 0xb5, 0x3a, 0xa0, 0x2c, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x74, 0xff, 0x04, 0x17, 0x29, 0xa5, 0xfc, - 0x30, 0xdb, 0x03, 0x9a, 0xf9, 0x27, 0x09, 0xf5, 0x7d, 0x8b, 0xef, 0x3d, 0x2e, 0xa9, 0x3e, 0xb5, - 0x8d, 0x1c, 0x6b, 0x41, 0x2c, 0x89, 0x5e, 0x0a, -]; -pub const V_NEG_BYTES: [u8; 88] = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2a, 0xc2, 0x7a, 0x75, 0xb5, 0x1e, 0xee, 0xeb, 0x16, 0x03, 0x6a, 0x51, 0x48, 0x2f, 0x6b, 0x84, - 0x38, 0x06, 0x98, 0x53, 0xfa, 0xcd, 0xa8, 0xda, 0xd1, 0x46, 0xb9, 0xfb, 0xa2, 0xe5, 0xe2, 0xdf, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xef, 0x4f, 0x6e, 0xca, 0x07, 0xfa, 0x2d, - 0x87, 0x75, 0x42, 0x1b, 0x88, 0x5a, 0x4e, 0x67, 0xaa, 0xa7, 0xf9, 0x0b, 0x4b, 0x10, 0x31, 0xdb, - 0xb6, 0xc5, 0x8a, 0x52, 0xc3, 0x76, 0xa1, 0xff, -]; -pub const V_BYTES: [u8; 88] = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x16, 0x18, 0x28, 0xe8, 0x11, 0x24, 0x9d, 0x95, 0x63, 0x4f, 0x95, 0x32, 0x9a, 0x15, 0x85, 0x5c, - 0xe4, 0x71, 0xf5, 0x68, 0xcf, 0x1e, 0x74, 0xfc, 0x27, 0x8c, 0x54, 0x57, 0x34, 0x5c, 0x60, 0x7f, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xe6, 0xd7, 0x01, 0x45, 0x55, 0x3c, 0x00, - 0x56, 0xd2, 0x9d, 0xf4, 0xaf, 0x55, 0x6c, 0x35, 0x6d, 0x73, 0xbd, 0x75, 0x54, 0x39, 0xf5, 0x28, - 0x55, 0xe7, 0xe0, 0xdd, 0x48, 0xa2, 0x8f, 0x28, -]; -pub const COM_BYTES: [u8; 88] = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x30, 0x5c, 0xed, 0x4c, 0xc9, 0x17, 0xf4, 0x0f, 0xeb, 0x65, 0xc7, 0x54, 0xd3, 0xfd, 0xeb, - 0xd4, 0x24, 0x13, 0xb9, 0x14, 0xaa, 0xb1, 0x7d, 0x76, 0xcf, 0xfa, 0x1a, 0x78, 0x5b, 0xba, 0x43, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x84, 0xf6, 0x8e, 0xb3, 0x25, 0xcc, - 0x83, 0x49, 0x24, 0xc0, 0x22, 0x3b, 0x78, 0xaa, 0x96, 0xcf, 0xbb, 0xdb, 0x70, 0xb1, 0x63, 0x9c, - 0x01, 0x3b, 0xa7, 0xe0, 0xb7, 0xd9, 0x8d, 0x3f, -]; -pub const W_BYTES: [u8; 248] = [ - 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0xd2, 0xe8, 0x06, 0x57, 0x75, 0x3a, 0xfb, 0x56, 0x14, 0x51, 0xef, 0x2e, 0x78, 0x6d, 0xc2, - 0x60, 0x39, 0x60, 0xb7, 0x97, 0x43, 0xb2, 0xed, 0xde, 0x40, 0x43, 0x4d, 0x1b, 0x6b, 0x71, 0x62, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0xfc, 0x07, 0x22, 0x98, 0x06, 0x25, 0xf3, - 0xda, 0x20, 0x33, 0x2a, 0x05, 0x83, 0xc5, 0x96, 0xa7, 0x57, 0x53, 0xea, 0xef, 0xed, 0x07, 0x90, - 0x91, 0xbc, 0xa1, 0x6f, 0xdd, 0xd9, 0xed, 0xa9, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x06, 0x16, 0x19, 0x67, 0x88, 0x05, 0xd9, 0x72, 0xd4, 0xd5, 0x48, 0xfb, 0xd9, 0xa5, 0xdc, - 0x8f, 0x8a, 0x7d, 0xf8, 0x06, 0x19, 0x09, 0x84, 0x0e, 0x11, 0xa0, 0xdc, 0x66, 0x5a, 0xd9, 0xfa, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x14, 0xa3, 0x0b, 0x0c, 0x63, 0x61, 0x47, - 0xc4, 0xb9, 0x04, 0x22, 0x7b, 0x86, 0x71, 0x21, 0x0a, 0x0f, 0x65, 0x5a, 0x89, 0x49, 0x98, 0xaa, - 0xdb, 0x8e, 0x8a, 0x3a, 0x58, 0x61, 0xdc, 0xf8, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x22, 0x7b, 0x59, 0x7d, 0x14, 0x15, 0x7a, 0xce, 0x59, 0x3e, 0xfe, 0xe8, 0xb2, 0xf1, 0xac, 0xff, - 0x36, 0x98, 0x40, 0x0d, 0xa6, 0x2c, 0x2a, 0x6b, 0x1f, 0x8e, 0x8d, 0x0e, 0xdd, 0xd5, 0xb0, 0x02, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x0d, 0xa6, 0xcc, 0x2e, 0xfa, 0x24, 0x81, - 0xa5, 0x7d, 0x98, 0x29, 0x08, 0x29, 0x22, 0x97, 0x2a, 0x08, 0xa3, 0xe1, 0xf0, 0x3d, 0xb5, 0x40, - 0x6f, 0xb8, 0x44, 0x7f, 0x31, 0xdc, 0x18, 0x62, -]; - -pub const VK_G1_BYTES: [u8; 88] = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x2f, 0x77, 0x0c, 0x9d, 0x84, 0x4c, 0x3c, 0xd5, 0x51, 0xdf, 0x50, 0x87, 0xb9, 0xa8, 0x4d, - 0xd9, 0xec, 0x15, 0xd6, 0x43, 0x81, 0x40, 0x41, 0xe1, 0x8f, 0x82, 0xe0, 0x12, 0x80, 0xcf, 0x6f, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x09, 0x2d, 0x55, 0xb8, 0x9a, 0xe5, 0xf5, - 0xd7, 0xf5, 0x70, 0xbc, 0xa0, 0xbf, 0x03, 0x69, 0x70, 0x05, 0x1c, 0x33, 0xf1, 0x49, 0x4a, 0xcf, - 0x7c, 0x30, 0xc1, 0xc5, 0xa4, 0xf2, 0x80, 0xbb, -]; -pub const VK_G2_BYTES: [u8; 168] = [ - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x08, 0xae, 0xe6, 0xcc, 0xe7, 0xb7, 0x43, 0xa7, 0xa8, 0xc2, 0x94, 0x64, 0xf0, 0x50, 0x19, - 0xc1, 0x96, 0x46, 0xc2, 0x8f, 0xbb, 0x2e, 0xe0, 0xe7, 0x6f, 0x07, 0x1a, 0x19, 0x0a, 0x6a, 0x38, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x84, 0xdf, 0xa0, 0x52, 0x5d, 0x1e, 0x79, - 0xea, 0x6a, 0x64, 0xf6, 0x2b, 0x1c, 0x6a, 0x2d, 0xb2, 0x9f, 0x10, 0xce, 0xb3, 0x90, 0x82, 0x37, - 0xa5, 0xcb, 0x40, 0xc8, 0x01, 0x77, 0x89, 0x07, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x20, 0x22, 0x01, 0x8f, 0x06, 0x83, 0x8c, 0x43, 0xd4, 0x16, 0x35, 0x5e, 0x1e, 0xfb, 0x7f, 0xe9, - 0x77, 0xf4, 0x8f, 0x36, 0x56, 0x50, 0x24, 0xf3, 0x47, 0x22, 0x92, 0x34, 0x90, 0x23, 0x31, 0xe2, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0xce, 0xbd, 0x47, 0x4d, 0xaa, 0xc3, 0xfb, - 0x13, 0x4e, 0x80, 0x1a, 0x53, 0xd1, 0xbb, 0x05, 0x79, 0xc0, 0x0c, 0xdb, 0x9c, 0x5d, 0xb5, 0x92, - 0x42, 0xd7, 0xb1, 0x76, 0x69, 0x27, 0x8d, 0x17, -]; -pub const VK_BETA_G2_BYTES: [u8; 168] = [ - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x26, 0x65, 0xdb, 0x07, 0x85, 0xd0, 0xac, 0x2f, 0x22, 0xfc, 0x48, 0xa9, 0xb0, 0x04, 0x9e, - 0xe2, 0x85, 0xd1, 0xaf, 0xd1, 0x95, 0xde, 0x3e, 0x52, 0x74, 0xbf, 0x30, 0xa4, 0x9d, 0x0a, 0xfc, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x32, 0x86, 0x7e, 0xcc, 0x64, 0xd2, 0xa4, - 0xae, 0x27, 0x06, 0x39, 0xa1, 0x5b, 0x79, 0xd2, 0xb1, 0xef, 0xc2, 0xaf, 0x94, 0x1f, 0x92, 0xff, - 0xd2, 0x6b, 0xd4, 0xf2, 0x07, 0x48, 0x18, 0xd2, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x64, 0xf0, 0xaf, 0x8c, 0xfc, 0x2c, 0xd3, 0x34, 0x1a, 0xb1, 0xfb, 0x76, 0xca, 0xbb, 0x26, - 0xab, 0x32, 0xd3, 0x17, 0x70, 0x18, 0x76, 0x66, 0x40, 0x7b, 0xa1, 0x1b, 0xea, 0x26, 0xab, 0x99, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc8, 0x05, 0x58, 0xa2, 0x02, 0x32, 0x91, - 0x3a, 0x32, 0xc5, 0xd5, 0x06, 0x52, 0x2c, 0x6d, 0xfa, 0x89, 0xdd, 0x24, 0xd2, 0x0b, 0x3c, 0x82, - 0x7a, 0x85, 0xf9, 0xc3, 0xcf, 0x72, 0xb4, 0x8c, -]; -pub const C_G1_BYTES: [u8; 88] = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x28, 0x4b, 0xcb, 0xcf, 0x4a, 0xe1, 0xfc, 0xc5, 0x81, 0x65, 0x4a, 0x7a, 0x33, 0x77, 0xdf, 0xe5, - 0x93, 0x4a, 0xf9, 0x7d, 0x89, 0x34, 0x9c, 0x54, 0x25, 0x7f, 0x0b, 0x6a, 0x33, 0x7f, 0x4c, 0x24, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0xbf, 0x39, 0x12, 0x4f, 0xab, 0xa4, 0x50, - 0xaa, 0x56, 0xf4, 0x53, 0x6b, 0x78, 0x52, 0x0a, 0xb1, 0x84, 0xaf, 0xa3, 0xc6, 0xde, 0x91, 0x96, - 0x38, 0x71, 0xc2, 0x38, 0xc8, 0x79, 0x0f, 0xb0, -]; diff --git a/jolt-svm-verifier/program/src/instruction.rs b/jolt-svm-verifier/program/src/instruction.rs new file mode 100644 index 000000000..f8b6e4f76 --- /dev/null +++ b/jolt-svm-verifier/program/src/instruction.rs @@ -0,0 +1,17 @@ +use solana_program::program_error::ProgramError; + +pub enum VerifierInstruction { + VerifyHyperKZG, + VerifySumcheck, +} + +impl VerifierInstruction { + pub fn unpack(input: &[u8]) -> Result { + let (&tag, _rest) = input.split_first().ok_or(ProgramError::InvalidInstructionData)?; + Ok(match tag { + 0 => VerifierInstruction::VerifyHyperKZG, + 1 => VerifierInstruction::VerifySumcheck, + _ => return Err(ProgramError::InvalidInstructionData), + }) + } +} \ No newline at end of file diff --git a/jolt-svm-verifier/program/src/lib.rs b/jolt-svm-verifier/program/src/lib.rs index 46a313f50..1df2d921d 100644 --- a/jolt-svm-verifier/program/src/lib.rs +++ b/jolt-svm-verifier/program/src/lib.rs @@ -1,10 +1,11 @@ #![allow(non_snake_case)] -mod constants; +mod test_constants; mod subprotocols; mod utils; +mod instruction; -use constants::*; +use test_constants::*; use crate::subprotocols::hyperkzg; use ark_bn254::{Bn254, Fq, Fq2, Fr, G1Affine, G2Affine}; @@ -18,19 +19,46 @@ use jolt_types::utils::transcript::ProofTranscript; use solana_program::{ account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey, }; +use solana_program::program_error::ProgramError; +use crate::instruction::VerifierInstruction; +use crate::subprotocols::grand_product::{verify_grand_product, GrandProductProof}; entrypoint!(process_instruction); fn process_instruction( _program_id: &Pubkey, _accounts: &[AccountInfo], - _instruction_data: &[u8], + instruction_data: &[u8], ) -> ProgramResult { msg!("Solana WIP Jolt Verifier!"); - verify_hyperKZG_JOLT(); + + let instruction = VerifierInstruction::unpack(instruction_data)?; + + match instruction { + VerifierInstruction::VerifyHyperKZG => { + msg!("Running verify_hyperKZG_JOLT"); + verify_hyperKZG_JOLT(); + } + VerifierInstruction::VerifySumcheck => { + msg!("Running verify_sumcheck"); + verify_sumcheck(); + } + } + Ok(()) } +fn verify_sumcheck() { + let proof: GrandProductProof = CanonicalDeserialize::deserialize_uncompressed(&GRAND_PRODUCT_BATCH_PROOFS[..]).unwrap(); + let claims: Vec = CanonicalDeserialize::deserialize_uncompressed(&GRAND_PRODUCT_CLAIMS[..]).unwrap(); + let mut transcript = ProofTranscript::new(b"test_transcript"); + let r_grand_product = verify_grand_product(&proof, &claims, &mut transcript); + let expected_r_grand_product: Vec = + CanonicalDeserialize::deserialize_uncompressed(&GRAND_PRODUCT_R_PROVER[..]).unwrap(); + + assert_eq!(expected_r_grand_product, r_grand_product); +} + fn verify_hyperKZG_JOLT() { let eval: Fr = CanonicalDeserialize::deserialize_uncompressed(&EVAL_BYTES[..]).unwrap(); let point: Vec = CanonicalDeserialize::deserialize_uncompressed(&POINT_BYTES[..]).unwrap(); diff --git a/jolt-svm-verifier/program/src/subprotocols/grand_product.rs b/jolt-svm-verifier/program/src/subprotocols/grand_product.rs new file mode 100644 index 000000000..1dcea4932 --- /dev/null +++ b/jolt-svm-verifier/program/src/subprotocols/grand_product.rs @@ -0,0 +1,140 @@ +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use solana_program::msg; +use jolt_types::field::JoltField; +use jolt_types::subprotocols::grand_product::BatchedGrandProductLayerProof; +use jolt_types::utils::transcript::ProofTranscript; + +// Defining a solana specific version of this as a trade-off between pulling apart significant parts +// of jolt-core and keeping the changes minimal. +// This implementation follows the solidity implementation closely. +#[derive(CanonicalSerialize, CanonicalDeserialize)] +pub struct GrandProductProof { + layers: Vec> +} + +fn eval_eq_mle(r_grand_product: &[F], r_sumcheck: &[F]) -> F { + r_grand_product + .iter() + .zip(r_sumcheck.iter().rev()) + .map(|(&r_gp, &r_sc)| { + r_gp * r_sc + (F::one() - r_gp) * (F::one() - r_sc) + }) + .product() +} + +pub fn verify_sumcheck_claim( + layer_proof: &BatchedGrandProductLayerProof, + coeffs: &[F], + sumcheck_claim: F, + eq_eval: F, + r_grand_product: &mut Vec, + transcript: &mut ProofTranscript, +) -> (Vec, Vec) { + let expected_sumcheck_claim: F = coeffs + .iter() + .zip(layer_proof.left_claims.iter().zip(layer_proof.right_claims.iter())) + .map(|(&coeff, (&left, &right))| coeff * left * right * eq_eval) + .sum(); + msg!("expected sumcheck calculated"); + + assert_eq!(expected_sumcheck_claim, sumcheck_claim, "Sumcheck claim mismatch"); + + let r_layer = transcript.challenge_scalar(); + + let new_claims: Vec = layer_proof + .left_claims + .iter() + .zip(layer_proof.right_claims.iter()) + .map(|(&left, &right)| left + r_layer * (right - left)) + .collect(); + msg!("new claims done"); + + r_grand_product.push(r_layer); + + (new_claims, r_grand_product.clone()) +} + +pub fn verify_grand_product( + proof: &GrandProductProof, + claims: &[F], + transcript: &mut ProofTranscript, +) -> Vec { + let mut r_grand_product = Vec::new(); + let mut claims_to_verify = claims.to_vec(); + msg!("Proof layers: {:?}", proof.layers.len()); + + for layer in &proof.layers { + let coeffs: Vec = transcript.challenge_vector(claims_to_verify.len()); + + let joined_claim: F = claims_to_verify + .iter() + .zip(coeffs.iter()) + .map(|(&claim, &coeff)| claim * coeff) + .sum(); + + assert_eq!(claims.len(), layer.left_claims.len()); + assert_eq!(claims.len(), layer.right_claims.len()); + + let (sumcheck_claim, r_sumcheck) = layer.verify( + joined_claim, + r_grand_product.len(), + 3, + transcript, + ); + + for (&left, &right) in layer.left_claims.iter().zip(layer.right_claims.iter()) { + transcript.append_scalar(&left); + transcript.append_scalar(&right); + } + msg!("Transcript appened scalars"); + + assert_eq!(r_grand_product.len(), r_sumcheck.len()); + + let eq_eval = eval_eq_mle(&r_grand_product, &r_sumcheck); + + r_grand_product = r_sumcheck.into_iter().rev().collect(); + msg!("Going to verify sumcheck"); + + let (new_claims, new_r_grand_product) = verify_sumcheck_claim( + layer, + &coeffs, + sumcheck_claim, + eq_eval, + &mut r_grand_product, + transcript, + ); + + claims_to_verify = new_claims; + r_grand_product = new_r_grand_product; + } + + r_grand_product +} + +#[cfg(test)] +mod tests { + use super::*; + use ark_serialize::CanonicalDeserialize; + use ark_bn254::Fr; + use jolt_types::utils::transcript::ProofTranscript; + use crate::test_constants::{GRAND_PRODUCT_BATCH_PROOFS, GRAND_PRODUCT_CLAIMS, GRAND_PRODUCT_R_PROVER}; + + #[test] + fn test_grand_product() { + // let proof_bytes = include_bytes!("../../test_vectors/grand_product_proof.bytes"); + let proof: GrandProductProof = CanonicalDeserialize::deserialize_uncompressed(&GRAND_PRODUCT_BATCH_PROOFS[..]).unwrap(); + + // let claims_bytes = include_bytes!("../../test_vectors/grand_product_claims.bytes"); + let claims: Vec = CanonicalDeserialize::deserialize_uncompressed(&GRAND_PRODUCT_CLAIMS[..]).unwrap(); + + let mut transcript = ProofTranscript::new(b"test_transcript"); + let r_grand_product = verify_grand_product(&proof, &claims, &mut transcript); + + // let expected_r_grand_product_bytes = + // include_bytes!("../../test_vectors/grand_product_r_grand_product.bytes"); + let expected_r_grand_product: Vec = + CanonicalDeserialize::deserialize_uncompressed(&GRAND_PRODUCT_R_PROVER[..]).unwrap(); + + assert_eq!(expected_r_grand_product, r_grand_product); + } +} diff --git a/jolt-svm-verifier/program/src/subprotocols/mod.rs b/jolt-svm-verifier/program/src/subprotocols/mod.rs index bbb221ef1..ed925dfde 100644 --- a/jolt-svm-verifier/program/src/subprotocols/mod.rs +++ b/jolt-svm-verifier/program/src/subprotocols/mod.rs @@ -1 +1,4 @@ pub mod hyperkzg; + +#[allow(dead_code)] +pub mod grand_product; diff --git a/jolt-svm-verifier/program/src/test_constants.rs b/jolt-svm-verifier/program/src/test_constants.rs new file mode 100644 index 000000000..9c2035f10 --- /dev/null +++ b/jolt-svm-verifier/program/src/test_constants.rs @@ -0,0 +1,248 @@ +// Generated from HyperKZG small tests. +pub const POINT_BYTES: [u8; 72] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +]; +pub const EVAL_BYTES: [u8; 32] = [ + 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +]; +pub const V_POS_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x53, 0x70, 0xf2, 0xee, 0x18, 0x3d, 0x60, 0x13, 0xea, 0x65, 0xf4, 0xf7, 0x30, 0xe2, 0xc7, + 0xbf, 0xd4, 0x62, 0xdf, 0x8a, 0xbe, 0xec, 0x65, 0xed, 0x4b, 0x2d, 0x07, 0xb5, 0x3a, 0xa0, 0x2c, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x74, 0xff, 0x04, 0x17, 0x29, 0xa5, 0xfc, + 0x30, 0xdb, 0x03, 0x9a, 0xf9, 0x27, 0x09, 0xf5, 0x7d, 0x8b, 0xef, 0x3d, 0x2e, 0xa9, 0x3e, 0xb5, + 0x8d, 0x1c, 0x6b, 0x41, 0x2c, 0x89, 0x5e, 0x0a, +]; +pub const V_NEG_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2a, 0xc2, 0x7a, 0x75, 0xb5, 0x1e, 0xee, 0xeb, 0x16, 0x03, 0x6a, 0x51, 0x48, 0x2f, 0x6b, 0x84, + 0x38, 0x06, 0x98, 0x53, 0xfa, 0xcd, 0xa8, 0xda, 0xd1, 0x46, 0xb9, 0xfb, 0xa2, 0xe5, 0xe2, 0xdf, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xef, 0x4f, 0x6e, 0xca, 0x07, 0xfa, 0x2d, + 0x87, 0x75, 0x42, 0x1b, 0x88, 0x5a, 0x4e, 0x67, 0xaa, 0xa7, 0xf9, 0x0b, 0x4b, 0x10, 0x31, 0xdb, + 0xb6, 0xc5, 0x8a, 0x52, 0xc3, 0x76, 0xa1, 0xff, +]; +pub const V_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x18, 0x28, 0xe8, 0x11, 0x24, 0x9d, 0x95, 0x63, 0x4f, 0x95, 0x32, 0x9a, 0x15, 0x85, 0x5c, + 0xe4, 0x71, 0xf5, 0x68, 0xcf, 0x1e, 0x74, 0xfc, 0x27, 0x8c, 0x54, 0x57, 0x34, 0x5c, 0x60, 0x7f, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xe6, 0xd7, 0x01, 0x45, 0x55, 0x3c, 0x00, + 0x56, 0xd2, 0x9d, 0xf4, 0xaf, 0x55, 0x6c, 0x35, 0x6d, 0x73, 0xbd, 0x75, 0x54, 0x39, 0xf5, 0x28, + 0x55, 0xe7, 0xe0, 0xdd, 0x48, 0xa2, 0x8f, 0x28, +]; +pub const COM_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x30, 0x5c, 0xed, 0x4c, 0xc9, 0x17, 0xf4, 0x0f, 0xeb, 0x65, 0xc7, 0x54, 0xd3, 0xfd, 0xeb, + 0xd4, 0x24, 0x13, 0xb9, 0x14, 0xaa, 0xb1, 0x7d, 0x76, 0xcf, 0xfa, 0x1a, 0x78, 0x5b, 0xba, 0x43, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x84, 0xf6, 0x8e, 0xb3, 0x25, 0xcc, + 0x83, 0x49, 0x24, 0xc0, 0x22, 0x3b, 0x78, 0xaa, 0x96, 0xcf, 0xbb, 0xdb, 0x70, 0xb1, 0x63, 0x9c, + 0x01, 0x3b, 0xa7, 0xe0, 0xb7, 0xd9, 0x8d, 0x3f, +]; +pub const W_BYTES: [u8; 248] = [ + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xd2, 0xe8, 0x06, 0x57, 0x75, 0x3a, 0xfb, 0x56, 0x14, 0x51, 0xef, 0x2e, 0x78, 0x6d, 0xc2, + 0x60, 0x39, 0x60, 0xb7, 0x97, 0x43, 0xb2, 0xed, 0xde, 0x40, 0x43, 0x4d, 0x1b, 0x6b, 0x71, 0x62, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0xfc, 0x07, 0x22, 0x98, 0x06, 0x25, 0xf3, + 0xda, 0x20, 0x33, 0x2a, 0x05, 0x83, 0xc5, 0x96, 0xa7, 0x57, 0x53, 0xea, 0xef, 0xed, 0x07, 0x90, + 0x91, 0xbc, 0xa1, 0x6f, 0xdd, 0xd9, 0xed, 0xa9, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x06, 0x16, 0x19, 0x67, 0x88, 0x05, 0xd9, 0x72, 0xd4, 0xd5, 0x48, 0xfb, 0xd9, 0xa5, 0xdc, + 0x8f, 0x8a, 0x7d, 0xf8, 0x06, 0x19, 0x09, 0x84, 0x0e, 0x11, 0xa0, 0xdc, 0x66, 0x5a, 0xd9, 0xfa, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x14, 0xa3, 0x0b, 0x0c, 0x63, 0x61, 0x47, + 0xc4, 0xb9, 0x04, 0x22, 0x7b, 0x86, 0x71, 0x21, 0x0a, 0x0f, 0x65, 0x5a, 0x89, 0x49, 0x98, 0xaa, + 0xdb, 0x8e, 0x8a, 0x3a, 0x58, 0x61, 0xdc, 0xf8, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x22, 0x7b, 0x59, 0x7d, 0x14, 0x15, 0x7a, 0xce, 0x59, 0x3e, 0xfe, 0xe8, 0xb2, 0xf1, 0xac, 0xff, + 0x36, 0x98, 0x40, 0x0d, 0xa6, 0x2c, 0x2a, 0x6b, 0x1f, 0x8e, 0x8d, 0x0e, 0xdd, 0xd5, 0xb0, 0x02, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x0d, 0xa6, 0xcc, 0x2e, 0xfa, 0x24, 0x81, + 0xa5, 0x7d, 0x98, 0x29, 0x08, 0x29, 0x22, 0x97, 0x2a, 0x08, 0xa3, 0xe1, 0xf0, 0x3d, 0xb5, 0x40, + 0x6f, 0xb8, 0x44, 0x7f, 0x31, 0xdc, 0x18, 0x62, +]; + +pub const VK_G1_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x2f, 0x77, 0x0c, 0x9d, 0x84, 0x4c, 0x3c, 0xd5, 0x51, 0xdf, 0x50, 0x87, 0xb9, 0xa8, 0x4d, + 0xd9, 0xec, 0x15, 0xd6, 0x43, 0x81, 0x40, 0x41, 0xe1, 0x8f, 0x82, 0xe0, 0x12, 0x80, 0xcf, 0x6f, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x09, 0x2d, 0x55, 0xb8, 0x9a, 0xe5, 0xf5, + 0xd7, 0xf5, 0x70, 0xbc, 0xa0, 0xbf, 0x03, 0x69, 0x70, 0x05, 0x1c, 0x33, 0xf1, 0x49, 0x4a, 0xcf, + 0x7c, 0x30, 0xc1, 0xc5, 0xa4, 0xf2, 0x80, 0xbb, +]; +pub const VK_G2_BYTES: [u8; 168] = [ + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0xae, 0xe6, 0xcc, 0xe7, 0xb7, 0x43, 0xa7, 0xa8, 0xc2, 0x94, 0x64, 0xf0, 0x50, 0x19, + 0xc1, 0x96, 0x46, 0xc2, 0x8f, 0xbb, 0x2e, 0xe0, 0xe7, 0x6f, 0x07, 0x1a, 0x19, 0x0a, 0x6a, 0x38, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x84, 0xdf, 0xa0, 0x52, 0x5d, 0x1e, 0x79, + 0xea, 0x6a, 0x64, 0xf6, 0x2b, 0x1c, 0x6a, 0x2d, 0xb2, 0x9f, 0x10, 0xce, 0xb3, 0x90, 0x82, 0x37, + 0xa5, 0xcb, 0x40, 0xc8, 0x01, 0x77, 0x89, 0x07, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x22, 0x01, 0x8f, 0x06, 0x83, 0x8c, 0x43, 0xd4, 0x16, 0x35, 0x5e, 0x1e, 0xfb, 0x7f, 0xe9, + 0x77, 0xf4, 0x8f, 0x36, 0x56, 0x50, 0x24, 0xf3, 0x47, 0x22, 0x92, 0x34, 0x90, 0x23, 0x31, 0xe2, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0xce, 0xbd, 0x47, 0x4d, 0xaa, 0xc3, 0xfb, + 0x13, 0x4e, 0x80, 0x1a, 0x53, 0xd1, 0xbb, 0x05, 0x79, 0xc0, 0x0c, 0xdb, 0x9c, 0x5d, 0xb5, 0x92, + 0x42, 0xd7, 0xb1, 0x76, 0x69, 0x27, 0x8d, 0x17, +]; +pub const VK_BETA_G2_BYTES: [u8; 168] = [ + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x26, 0x65, 0xdb, 0x07, 0x85, 0xd0, 0xac, 0x2f, 0x22, 0xfc, 0x48, 0xa9, 0xb0, 0x04, 0x9e, + 0xe2, 0x85, 0xd1, 0xaf, 0xd1, 0x95, 0xde, 0x3e, 0x52, 0x74, 0xbf, 0x30, 0xa4, 0x9d, 0x0a, 0xfc, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x32, 0x86, 0x7e, 0xcc, 0x64, 0xd2, 0xa4, + 0xae, 0x27, 0x06, 0x39, 0xa1, 0x5b, 0x79, 0xd2, 0xb1, 0xef, 0xc2, 0xaf, 0x94, 0x1f, 0x92, 0xff, + 0xd2, 0x6b, 0xd4, 0xf2, 0x07, 0x48, 0x18, 0xd2, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2a, 0x64, 0xf0, 0xaf, 0x8c, 0xfc, 0x2c, 0xd3, 0x34, 0x1a, 0xb1, 0xfb, 0x76, 0xca, 0xbb, 0x26, + 0xab, 0x32, 0xd3, 0x17, 0x70, 0x18, 0x76, 0x66, 0x40, 0x7b, 0xa1, 0x1b, 0xea, 0x26, 0xab, 0x99, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc8, 0x05, 0x58, 0xa2, 0x02, 0x32, 0x91, + 0x3a, 0x32, 0xc5, 0xd5, 0x06, 0x52, 0x2c, 0x6d, 0xfa, 0x89, 0xdd, 0x24, 0xd2, 0x0b, 0x3c, 0x82, + 0x7a, 0x85, 0xf9, 0xc3, 0xcf, 0x72, 0xb4, 0x8c, +]; +pub const C_G1_BYTES: [u8; 88] = [ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x4b, 0xcb, 0xcf, 0x4a, 0xe1, 0xfc, 0xc5, 0x81, 0x65, 0x4a, 0x7a, 0x33, 0x77, 0xdf, 0xe5, + 0x93, 0x4a, 0xf9, 0x7d, 0x89, 0x34, 0x9c, 0x54, 0x25, 0x7f, 0x0b, 0x6a, 0x33, 0x7f, 0x4c, 0x24, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0xbf, 0x39, 0x12, 0x4f, 0xab, 0xa4, 0x50, + 0xaa, 0x56, 0xf4, 0x53, 0x6b, 0x78, 0x52, 0x0a, 0xb1, 0x84, 0xaf, 0xa3, 0xc6, 0xde, 0x91, 0x96, + 0x38, 0x71, 0xc2, 0x38, 0xc8, 0x79, 0x0f, 0xb0, +]; + +// Grand Product Sumcheck generated from Grand Product tests +// const LAYER_SIZE: usize = 1 << 4; +// const BATCH_SIZE: usize = 1; +// Can't compile this because of a conflict with solana-program. +// use rand_core::RngCore; +// use crate::poly::commitment::hyperkzg::HyperKZG; +// +// #[test] +// fn prove_verify_hyperkzg() { +// const LAYER_SIZE: usize = 1 << 4; +// const BATCH_SIZE: usize = 1; +// let mut rng = test_rng(); +// let leaves: Vec> = std::iter::repeat_with(|| { +// std::iter::repeat_with(|| Fr::random(&mut rng)) +// .take(LAYER_SIZE) +// .collect() +// }) +// .take(BATCH_SIZE) +// .collect(); +// +// let mut batched_circuit = as BatchedGrandProduct< +// Fr, +// HyperKZG, +// >>::construct(leaves); +// +// let mut transcript: ProofTranscript = ProofTranscript::new(b"test_transcript"); +// +// let (proof, r_prover) = as BatchedGrandProduct< +// Fr, +// HyperKZG, +// >>::prove_grand_product(&mut batched_circuit, &mut transcript, None); +// let claims = +// as BatchedGrandProduct>>::claims( +// &mut batched_circuit, +// ); +// +// serialize_and_print_hex("GRAND_PRODUCT_BATCH_PROOFS", &proof.layers); +// serialize_and_print_hex("GRAND_PRODUCT_CLAIMS", &claims); +// serialize_and_print_hex("GRAND_PRODUCT_R_PROVER", &r_prover); +// } +// +// fn serialize_and_print_hex(name: &str, value: &T) { +// let compress: bool = false; +// let mut bytes = Vec::new(); +// if compress { +// value.serialize_compressed(&mut bytes).unwrap() +// } else { +// value.serialize_uncompressed(&mut bytes).unwrap(); +// } +// print_hex_array(name, &bytes); +// } +// +// fn print_hex_array(name: &str, bytes: &[u8]) { +// print!("pub const {}: [u8; {}] = [", name, bytes.len()); +// for (i, byte) in bytes.iter().enumerate() { +// if i % 16 == 0 { +// print!("\n "); +// } +// print!("0x{:02x}, ", byte); +// } +// println!("\n];"); +// } +pub const GRAND_PRODUCT_BATCH_PROOFS: [u8; 984] = [ + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x66, 0xd1, 0x83, 0x42, 0x99, 0x78, 0x5b, + 0x20, 0xf0, 0x34, 0xea, 0x5d, 0xcf, 0x58, 0xe5, 0xdf, 0x26, 0xdc, 0x82, 0x24, 0x9d, 0xa8, 0x9e, + 0x4e, 0x35, 0x70, 0x48, 0x45, 0x2e, 0xd6, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xed, 0x53, 0x08, 0x59, 0x68, 0xe0, 0x26, 0xda, 0xac, 0x49, 0x3d, 0xea, 0x7f, 0x93, 0x0d, 0xe2, + 0x72, 0x72, 0x23, 0xe3, 0xcc, 0xad, 0x87, 0x97, 0x32, 0x2d, 0x00, 0xcb, 0x23, 0x50, 0xbd, 0x0d, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x52, 0xe7, 0x65, 0x2c, 0xc2, 0xfc, 0xb3, 0x2e, 0x07, 0x49, 0x33, 0x72, 0x1f, 0xf8, 0xf0, 0xf7, + 0xe1, 0x1e, 0xed, 0xd8, 0xe2, 0xd9, 0xfb, 0x84, 0x01, 0x67, 0xac, 0xde, 0x2d, 0x0d, 0x46, 0x04, + 0x8f, 0xdf, 0x4c, 0xfb, 0x63, 0xce, 0x20, 0xd1, 0xa0, 0xb5, 0x07, 0xe6, 0x6c, 0x04, 0x9f, 0x7f, + 0x1b, 0xb5, 0xfd, 0xd6, 0xc1, 0x04, 0xab, 0xcb, 0x12, 0x0b, 0x92, 0x55, 0x42, 0x07, 0x05, 0x1f, + 0xfa, 0x2a, 0x97, 0x1a, 0x9e, 0xd9, 0x4b, 0xf9, 0x2a, 0x8a, 0x88, 0x6b, 0x74, 0xcc, 0x56, 0xa6, + 0xcd, 0x34, 0x36, 0xa8, 0xc9, 0x38, 0x5b, 0xc0, 0x19, 0x73, 0x51, 0x20, 0xca, 0xee, 0x4f, 0x2f, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x62, 0x69, 0x76, 0x70, 0x1b, 0xdb, 0x3f, + 0xc6, 0xae, 0xcc, 0x35, 0xad, 0xd5, 0x8f, 0xc7, 0x11, 0x08, 0x44, 0xf2, 0x4f, 0x6f, 0x22, 0x62, + 0x3d, 0xbd, 0xd3, 0x2f, 0x47, 0x5c, 0x3b, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x56, 0x49, 0x29, 0x21, 0xcd, 0x7b, 0x75, 0x24, 0x74, 0xb8, 0x9b, 0x36, 0xa9, 0xcd, 0xa8, 0x4a, + 0x92, 0x60, 0x18, 0x23, 0xb9, 0x7c, 0xd1, 0xa3, 0xc6, 0x3c, 0x24, 0x10, 0x7e, 0x4a, 0x0d, 0x17, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc6, 0xf3, 0x49, 0x43, 0xfd, 0x3e, 0x6b, 0xbe, 0xc9, 0x5c, 0xca, 0x03, 0xa6, 0x89, 0xc8, 0x41, + 0x03, 0x0e, 0x6d, 0x40, 0xb5, 0x10, 0x2a, 0xb7, 0x8e, 0x3e, 0x03, 0x92, 0x2c, 0x35, 0x6a, 0x28, + 0x9d, 0x1c, 0xf7, 0x9b, 0x12, 0x5c, 0x76, 0x48, 0xa0, 0x8b, 0x3e, 0x8b, 0xfb, 0x97, 0xe6, 0x03, + 0xd4, 0xe5, 0x23, 0x67, 0x98, 0xfe, 0xdc, 0x5c, 0xc7, 0x42, 0x16, 0xd8, 0x78, 0xca, 0x9e, 0x05, + 0x08, 0x12, 0x84, 0xd1, 0x58, 0x9f, 0xe0, 0x9d, 0xa0, 0x33, 0x8b, 0x45, 0xd7, 0xfb, 0xa5, 0xdb, + 0x8a, 0x2b, 0x92, 0xec, 0xe2, 0x49, 0x9f, 0x94, 0x66, 0xda, 0x8a, 0xf1, 0x48, 0x82, 0x77, 0x1c, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x8a, 0xe0, 0x82, 0x39, 0x66, 0xe2, 0xf9, + 0xdf, 0x80, 0xb9, 0x7a, 0xf0, 0x55, 0xf7, 0x30, 0x66, 0x0c, 0x2a, 0xe6, 0x9f, 0xe7, 0xe8, 0xb7, + 0x56, 0xf2, 0x66, 0x82, 0x48, 0xed, 0x85, 0x27, 0x0b, 0xe6, 0x66, 0xd5, 0xf2, 0x5b, 0xad, 0x7c, + 0x65, 0xc4, 0xc7, 0xad, 0x24, 0x2c, 0x3b, 0x6c, 0x26, 0x01, 0x5c, 0xf9, 0x1b, 0xe3, 0x5c, 0x29, + 0x0c, 0xd4, 0x24, 0x2a, 0xda, 0x01, 0x9a, 0x1f, 0x1d, 0x1a, 0x4d, 0x7f, 0x18, 0xdf, 0x13, 0xab, + 0xf0, 0x32, 0x01, 0xbb, 0x43, 0x6d, 0xde, 0x59, 0x6a, 0x87, 0x13, 0x06, 0xc3, 0x11, 0xea, 0x5b, + 0xcf, 0x45, 0x33, 0x52, 0xc5, 0xa7, 0xcc, 0x23, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x79, 0x88, 0xbb, 0x24, 0x82, 0xbc, 0x6b, 0x85, 0xad, 0x7d, 0x28, 0x78, 0xef, 0xcf, 0x0f, 0x95, + 0x47, 0x64, 0x5b, 0xc6, 0xeb, 0xb9, 0xa5, 0xab, 0xdf, 0x8a, 0x21, 0x24, 0x4e, 0x6f, 0xac, 0x15, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x4f, 0xcf, 0x60, 0xf6, 0x15, 0x7f, 0xbc, + 0x47, 0x6e, 0x01, 0x84, 0x79, 0x29, 0x40, 0x82, 0x86, 0xf4, 0xd8, 0xc3, 0xd8, 0xdf, 0x9d, 0xcb, + 0xf5, 0x60, 0x95, 0x50, 0x6e, 0x4b, 0x11, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x90, 0x42, 0xfe, 0x0a, 0x6f, 0x52, 0xff, + 0x65, 0x1b, 0x96, 0x0f, 0x19, 0x66, 0xda, 0x5d, 0x57, 0x71, 0x05, 0x7a, 0x61, 0xb7, 0x34, 0x67, + 0x0c, 0xf6, 0x39, 0xd5, 0xef, 0xb7, 0x04, 0x17, 0xcc, 0x09, 0x9d, 0xd6, 0x98, 0xf7, 0xf0, 0xe6, + 0xdf, 0x81, 0x93, 0xd8, 0x27, 0x89, 0xa8, 0x69, 0x60, 0x6c, 0x74, 0xcc, 0x2b, 0x73, 0x41, 0xf4, + 0xfd, 0x1d, 0x68, 0x68, 0x57, 0x4a, 0x95, 0x1c, 0x0d, 0x8a, 0x81, 0x2a, 0xee, 0xcc, 0x2c, 0xa9, + 0x68, 0x18, 0x03, 0x6a, 0xf1, 0xbe, 0x34, 0x3f, 0x99, 0x1a, 0x7b, 0x65, 0xee, 0x73, 0x2f, 0xcc, + 0xff, 0x1d, 0x26, 0xba, 0xc9, 0x17, 0x10, 0x1c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x07, 0x74, 0x57, 0xc2, 0xc5, 0x57, 0x0e, 0xa2, 0x79, 0xca, 0x5c, 0x04, 0x4f, 0xc7, 0x71, + 0x8e, 0xd7, 0xde, 0x6b, 0xc2, 0x7a, 0x0c, 0x81, 0x6a, 0x33, 0xc8, 0x11, 0x2a, 0xe4, 0x42, 0x08, + 0x4c, 0xa9, 0x8f, 0x8b, 0xda, 0xcd, 0x8f, 0x44, 0xff, 0xd9, 0x24, 0xe5, 0xca, 0x2c, 0x00, 0x2d, + 0xcd, 0x12, 0x8d, 0x9e, 0x49, 0xd0, 0x6c, 0x68, 0xfa, 0x93, 0x8f, 0x88, 0xe4, 0x8a, 0x71, 0x07, + 0x2f, 0xea, 0x0f, 0x64, 0xde, 0x72, 0xa4, 0x41, 0xfa, 0xc7, 0x29, 0x05, 0xcf, 0x3c, 0x06, 0x33, + 0x09, 0xe1, 0x69, 0x68, 0x2a, 0xdc, 0x47, 0xd4, 0xb5, 0x6f, 0xb4, 0x4e, 0x09, 0xb9, 0xdc, 0x20, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0xc2, 0xb5, 0x13, 0x2e, 0xa0, 0xc2, 0xd3, + 0xd1, 0x1c, 0x79, 0x62, 0x29, 0x10, 0x60, 0xc6, 0xa9, 0x56, 0x98, 0x77, 0x8b, 0xef, 0xe4, 0x08, + 0xd7, 0x7d, 0x38, 0x3f, 0xfa, 0x83, 0x95, 0x22, 0x98, 0x67, 0xf9, 0x72, 0xc7, 0x14, 0x9b, 0x94, + 0x2f, 0x36, 0x9e, 0xcb, 0x39, 0x26, 0x8b, 0x5e, 0xd7, 0xa2, 0xb8, 0x30, 0xab, 0x67, 0x21, 0x2a, + 0x23, 0x2c, 0xff, 0x5e, 0x75, 0xe0, 0x13, 0x03, 0xa5, 0x14, 0xad, 0x78, 0x66, 0xa8, 0x9f, 0x92, + 0x45, 0x08, 0xb5, 0x57, 0xd4, 0xb0, 0x32, 0x0f, 0x85, 0x6c, 0x95, 0xd6, 0x72, 0x9b, 0xc9, 0x55, + 0xef, 0xd1, 0x01, 0x1c, 0x7e, 0x8e, 0xd8, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x68, 0xba, 0xd4, 0xb5, 0x4b, 0xf7, 0x34, 0xa5, 0x20, 0x86, 0x13, 0x24, 0x44, 0x35, 0xfa, + 0x51, 0xd9, 0xaf, 0xa2, 0x4e, 0x71, 0x5f, 0x35, 0x43, 0x2c, 0x12, 0xe7, 0x1d, 0xa7, 0x39, 0x06, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0xca, 0x8f, 0x12, 0x81, 0x39, 0x9e, 0xbc, + 0x63, 0xf1, 0x83, 0x83, 0x55, 0xc7, 0xa9, 0x3d, 0xf9, 0xd5, 0x5b, 0x62, 0x89, 0x7e, 0x63, 0xb6, + 0xc4, 0xe4, 0x43, 0x95, 0xc0, 0x22, 0x79, 0x1d, +]; +pub const GRAND_PRODUCT_CLAIMS: [u8; 40] = [ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0xe5, 0x34, 0xce, 0x21, 0x19, 0x4a, 0x4f, + 0xe1, 0xe7, 0x6d, 0xf8, 0x87, 0x5b, 0xbc, 0x82, 0x71, 0x05, 0x63, 0xd8, 0x66, 0x66, 0x19, 0x03, + 0xc7, 0x71, 0x9d, 0x54, 0x0a, 0x62, 0x9b, 0x27, +]; +pub const GRAND_PRODUCT_R_PROVER: [u8; 136] = [ + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x02, 0xe7, 0x9d, 0x26, 0x1b, 0xcb, 0xc9, + 0x7a, 0xf0, 0xc3, 0x36, 0xa9, 0x21, 0x05, 0xfa, 0xcc, 0xb4, 0xa1, 0x66, 0xcf, 0x64, 0x6a, 0xd4, + 0xff, 0x71, 0xd2, 0x5f, 0x58, 0xf3, 0xc0, 0x00, 0xc0, 0x33, 0xb8, 0x95, 0x1c, 0x7e, 0xab, 0x1a, + 0xa5, 0x63, 0x9a, 0xc9, 0x97, 0x73, 0xa4, 0xcb, 0xfa, 0xb8, 0x46, 0x46, 0xcc, 0x96, 0x97, 0x03, + 0xe4, 0xc2, 0xd7, 0x01, 0x43, 0xcd, 0xf9, 0x12, 0xe6, 0x1b, 0x46, 0x25, 0xc4, 0x02, 0x1d, 0x61, + 0x3c, 0xdf, 0x46, 0x14, 0xc8, 0xaa, 0xde, 0xcc, 0x25, 0x1e, 0xf0, 0xef, 0x04, 0xab, 0x27, 0xfa, + 0xa7, 0x02, 0xb0, 0xec, 0xc0, 0x14, 0x0e, 0x11, 0x8b, 0x26, 0x50, 0xeb, 0xce, 0x47, 0x74, 0xad, + 0x74, 0x6f, 0x61, 0x19, 0x84, 0x23, 0x3f, 0x44, 0x24, 0x91, 0x30, 0x92, 0x01, 0x11, 0xea, 0x56, + 0xfc, 0xb0, 0x78, 0x2c, 0x21, 0x33, 0x23, 0x2e, +]; diff --git a/jolt-svm-verifier/tests/jolt-verifier.ts b/jolt-svm-verifier/tests/jolt-verifier.ts index 7b99f742f..c494f4b2c 100644 --- a/jolt-svm-verifier/tests/jolt-verifier.ts +++ b/jolt-svm-verifier/tests/jolt-verifier.ts @@ -17,14 +17,33 @@ describe('jolt-verifier', async () => { const client = context.banksClient; const payer = context.payer; - test('test basic', async () => { + test('test HyperKZG', async () => { const blockhash = context.lastBlockhash; const compute_ix = ComputeBudgetProgram.setComputeUnitLimit({units: 1_400_000}); // We setup our instruction. const ix = new TransactionInstruction({ keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }], programId: PROGRAM_ID, - data: Buffer.alloc(0), // No data + data: Buffer.from([0]), // hyperkzg instruction + }); + + const tx = new Transaction(); + tx.recentBlockhash = blockhash; + tx.add(compute_ix); + tx.add(ix).sign(payer); + + // Now we process the transaction + const transaction = await client.processTransaction(tx); + }); + + test('test Grand Product', async () => { + const blockhash = context.lastBlockhash; + const compute_ix = ComputeBudgetProgram.setComputeUnitLimit({units: 1_400_000}); + // We setup our instruction. + const ix = new TransactionInstruction({ + keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }], + programId: PROGRAM_ID, + data: Buffer.from([1]), // sumcheck instruction }); const tx = new Transaction(); diff --git a/jolt-types/Cargo.toml b/jolt-types/Cargo.toml index 71d5bec83..21eafd479 100644 --- a/jolt-types/Cargo.toml +++ b/jolt-types/Cargo.toml @@ -17,7 +17,7 @@ itertools = "0.13.0" [target.'cfg(not(target_os = "solana"))'.dependencies] rand = "0.7.3" -tracing = "0.1.40" +tracing = { version = "0.1.40", optional = true } rand_chacha = { version = "0.3.0", default-features = false } rand_core = { version = "0.6.4", default-features = false } rayon = { version = "^1.8.0", optional = true } @@ -35,6 +35,7 @@ default = [ "ark-std/parallel", "ark-ff/asm", "rayon", + "tracing", ] # Handle the unexpected cfg warnings when not building for solana diff --git a/jolt-types/src/lib.rs b/jolt-types/src/lib.rs index 9d0f12bd0..b8f913a0b 100644 --- a/jolt-types/src/lib.rs +++ b/jolt-types/src/lib.rs @@ -1,4 +1,5 @@ pub mod field; pub mod poly; +pub mod subprotocols; #[allow(non_snake_case)] pub mod utils; diff --git a/jolt-types/src/poly/mod.rs b/jolt-types/src/poly/mod.rs index 1f9123814..095d11c4c 100644 --- a/jolt-types/src/poly/mod.rs +++ b/jolt-types/src/poly/mod.rs @@ -1 +1,2 @@ pub mod commitment; +pub mod unipoly; diff --git a/jolt-core/src/poly/unipoly.rs b/jolt-types/src/poly/unipoly.rs similarity index 87% rename from jolt-core/src/poly/unipoly.rs rename to jolt-types/src/poly/unipoly.rs index e145ce1be..96d6523d0 100644 --- a/jolt-core/src/poly/unipoly.rs +++ b/jolt-types/src/poly/unipoly.rs @@ -1,12 +1,14 @@ #![allow(dead_code)] -use jolt_types::field::JoltField; +use crate::field::JoltField; use std::cmp::Ordering; use std::ops::{AddAssign, Index, IndexMut, Mul, MulAssign}; use crate::utils::gaussian_elimination::gaussian_elimination; +use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; use ark_serialize::*; -use jolt_types::utils::transcript::{AppendToTranscript, ProofTranscript}; +#[cfg(not(target_os = "solana"))] use rand_core::{CryptoRng, RngCore}; +#[cfg(not(target_os = "solana"))] use rayon::iter::{IntoParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; // ax^2 + bx + c stored as vec![c,b,a] @@ -57,7 +59,10 @@ impl UniPoly { /// Divide self by another polynomial, and returns the /// quotient and remainder. - #[tracing::instrument(skip_all, name = "UniPoly::divide_with_remainder")] + #[cfg_attr( + feature = "tracing", + tracing::instrument(skip_all, name = "UniPoly::divide_with_remainder") + )] pub fn divide_with_remainder(&self, divisor: &Self) -> Option<(Self, Self)> { if self.is_zero() { Some((Self::zero(), Self::zero())) @@ -115,7 +120,10 @@ impl UniPoly { (0..self.coeffs.len()).map(|i| self.coeffs[i]).sum() } - #[tracing::instrument(skip_all, name = "UniPoly::evaluate")] + #[cfg_attr( + feature = "tracing", + tracing::instrument(skip_all, name = "UniPoly::evaluate") + )] pub fn evaluate(&self, r: &F) -> F { let mut eval = self.coeffs[0]; let mut power = *r; @@ -134,6 +142,7 @@ impl UniPoly { } } + #[cfg(not(target_os = "solana"))] pub fn random(num_vars: usize, mut rng: &mut R) -> Self { Self::from_coeff( std::iter::from_fn(|| Some(F::random(&mut rng))) @@ -143,17 +152,16 @@ impl UniPoly { } pub fn shift_coefficients(&mut self, rhs: &F) { - self.coeffs.par_iter_mut().for_each(|c| *c += *rhs); - } -} - -/* -impl AddAssign<&F> for UniPoly { - fn add_assign(&mut self, rhs: &F) { - self.coeffs.par_iter_mut().for_each(|c| *c += rhs); + #[cfg(not(target_os = "solana"))] + { + self.coeffs.par_iter_mut().for_each(|c| *c += *rhs); + } + #[cfg(target_os = "solana")] + { + self.coeffs.iter_mut().for_each(|c| *c += *rhs); + } } } -*/ impl AddAssign<&Self> for UniPoly { fn add_assign(&mut self, rhs: &Self) { @@ -173,8 +181,16 @@ impl Mul for UniPoly { type Output = Self; fn mul(self, rhs: F) -> Self { - let iter = self.coeffs.into_par_iter(); - Self::from_coeff(iter.map(|c| c * rhs).collect::>()) + #[cfg(not(target_os = "solana"))] + { + let iter = self.coeffs.into_par_iter(); + Self::from_coeff(iter.map(|c| c * rhs).collect::>()) + } + #[cfg(target_os = "solana")] + { + let iter = self.coeffs.into_iter(); + Self::from_coeff(iter.map(|c| c * rhs).collect::>()) + } } } @@ -182,8 +198,29 @@ impl Mul<&F> for UniPoly { type Output = Self; fn mul(self, rhs: &F) -> Self { - let iter = self.coeffs.into_par_iter(); - Self::from_coeff(iter.map(|c| c * *rhs).collect::>()) + #[cfg(not(target_os = "solana"))] + { + let iter = self.coeffs.into_par_iter(); + Self::from_coeff(iter.map(|c| c * *rhs).collect::>()) + } + #[cfg(target_os = "solana")] + { + let iter = self.coeffs.into_iter(); + Self::from_coeff(iter.map(|c| c * *rhs).collect::>()) + } + } +} + +impl MulAssign<&F> for UniPoly { + fn mul_assign(&mut self, rhs: &F) { + #[cfg(not(target_os = "solana"))] + { + self.coeffs.par_iter_mut().for_each(|c| *c *= *rhs); + } + #[cfg(target_os = "solana")] + { + self.coeffs.iter_mut().for_each(|c| *c *= *rhs); + } } } @@ -201,12 +238,6 @@ impl IndexMut for UniPoly { } } -impl MulAssign<&F> for UniPoly { - fn mul_assign(&mut self, rhs: &F) { - self.coeffs.par_iter_mut().for_each(|c| *c *= *rhs); - } -} - impl CompressedUniPoly { // we require eval(0) + eval(1) = hint, so we can solve for the linear term as: // linear_term = hint - 2 * constant_term - deg2 term - deg3 term diff --git a/jolt-types/src/subprotocols/grand_product.rs b/jolt-types/src/subprotocols/grand_product.rs new file mode 100644 index 000000000..e20edc263 --- /dev/null +++ b/jolt-types/src/subprotocols/grand_product.rs @@ -0,0 +1,25 @@ +use crate::field::JoltField; +use crate::subprotocols::sumcheck::SumcheckInstanceProof; +use crate::utils::transcript::ProofTranscript; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; + +#[derive(CanonicalSerialize, CanonicalDeserialize)] +pub struct BatchedGrandProductLayerProof { + pub proof: SumcheckInstanceProof, + pub left_claims: Vec, + pub right_claims: Vec, +} + +impl BatchedGrandProductLayerProof { + pub fn verify( + &self, + claim: F, + num_rounds: usize, + degree_bound: usize, + transcript: &mut ProofTranscript, + ) -> (F, Vec) { + self.proof + .verify(claim, num_rounds, degree_bound, transcript) + .unwrap() + } +} diff --git a/jolt-types/src/subprotocols/mod.rs b/jolt-types/src/subprotocols/mod.rs new file mode 100644 index 000000000..020897245 --- /dev/null +++ b/jolt-types/src/subprotocols/mod.rs @@ -0,0 +1,2 @@ +pub mod grand_product; +pub mod sumcheck; diff --git a/jolt-types/src/subprotocols/sumcheck.rs b/jolt-types/src/subprotocols/sumcheck.rs new file mode 100644 index 000000000..b4767cf04 --- /dev/null +++ b/jolt-types/src/subprotocols/sumcheck.rs @@ -0,0 +1,64 @@ +use crate::field::JoltField; +use crate::poly::unipoly::CompressedUniPoly; +use crate::utils::errors::ProofVerifyError; +use crate::utils::transcript::{AppendToTranscript, ProofTranscript}; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; + +#[derive(CanonicalSerialize, CanonicalDeserialize, Debug)] +pub struct SumcheckInstanceProof { + pub compressed_polys: Vec>, +} + +impl SumcheckInstanceProof { + pub fn new(compressed_polys: Vec>) -> SumcheckInstanceProof { + SumcheckInstanceProof { compressed_polys } + } + + /// Verify this sumcheck proof. + /// Note: Verification does not execute the final check of sumcheck protocol: g_v(r_v) = oracle_g(r), + /// as the oracle is not passed in. Expected that the caller will implement. + /// + /// Params + /// - `claim`: Claimed evaluation + /// - `num_rounds`: Number of rounds of sumcheck, or number of variables to bind + /// - `degree_bound`: Maximum allowed degree of the combined univariate polynomial + /// - `transcript`: Fiat-shamir transcript + /// + /// Returns (e, r) + /// - `e`: Claimed evaluation at random point + /// - `r`: Evaluation point + pub fn verify( + &self, + claim: F, + num_rounds: usize, + degree_bound: usize, + transcript: &mut ProofTranscript, + ) -> Result<(F, Vec), ProofVerifyError> { + let mut e = claim; + let mut r: Vec = Vec::new(); + + // verify that there is a univariate polynomial for each round + assert_eq!(self.compressed_polys.len(), num_rounds); + for i in 0..self.compressed_polys.len() { + // verify degree bound + if self.compressed_polys[i].degree() != degree_bound { + return Err(ProofVerifyError::InvalidInputLength( + degree_bound, + self.compressed_polys[i].degree(), + )); + } + + // append the prover's message to the transcript + self.compressed_polys[i].append_to_transcript(transcript); + + //derive the verifier's challenge for the next round + let r_i = transcript.challenge_scalar(); + r.push(r_i); + + // evaluate the claimed degree-ell polynomial at r_i using the hint + e = self.compressed_polys[i].eval_from_hint(&e, &r_i); + } + + Ok((e, r)) + } +} diff --git a/jolt-core/src/utils/gaussian_elimination.rs b/jolt-types/src/utils/gaussian_elimination.rs similarity index 98% rename from jolt-core/src/utils/gaussian_elimination.rs rename to jolt-types/src/utils/gaussian_elimination.rs index ba5ad8bd2..0bbe78f47 100644 --- a/jolt-core/src/utils/gaussian_elimination.rs +++ b/jolt-types/src/utils/gaussian_elimination.rs @@ -4,7 +4,7 @@ // Wikipedia reference: augmented matrix: https://en.wikipedia.org/wiki/Augmented_matrix // Wikipedia reference: algorithm: https://en.wikipedia.org/wiki/Gaussian_elimination -use jolt_types::field::JoltField; +use crate::field::JoltField; pub fn gaussian_elimination(matrix: &mut [Vec]) -> Vec { let size = matrix.len(); diff --git a/jolt-types/src/utils/mod.rs b/jolt-types/src/utils/mod.rs index 24fd18a6a..6aac83a9d 100644 --- a/jolt-types/src/utils/mod.rs +++ b/jolt-types/src/utils/mod.rs @@ -6,6 +6,7 @@ use ark_std::test_rng; #[cfg(not(target_os = "solana"))] use rayon::prelude::*; pub mod errors; +pub mod gaussian_elimination; pub mod math; pub mod transcript;