Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JOLT-10] Do not merge, Linear test #60

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 71 additions & 3 deletions src/e2e_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use ark_curve25519::{EdwardsProjective as G1Projective, Fr};
use ark_ff::{BigInteger, BigInteger256};
use ark_std::log2;
use itertools::Itertools;
use merlin::Transcript;

use crate::{
Expand All @@ -7,11 +10,11 @@ use crate::{
surge::{SparsePolyCommitmentGens, SparsePolynomialEvaluationProof},
},
subtables::{
and::AndSubtableStrategy, lt::LTSubtableStrategy, range_check::RangeCheckSubtableStrategy,
SubtableStrategy,
and::AndSubtableStrategy, lt::LTSubtableStrategy, or::OrSubtableStrategy,
range_check::RangeCheckSubtableStrategy, SubtableStrategy,
},
utils::math::Math,
utils::random::RandomTape,
utils::{math::Math, test::gen_random_point},
};

macro_rules! e2e_test {
Expand Down Expand Up @@ -97,3 +100,68 @@ e2e_test!(
/* M= */ 256,
/* sparsity= */ 16
);

#[test]
fn and_e2e() {
const C: usize = 4;
const M: usize = 1 << 16;
const S: usize = 2;
type F = Fr;
type G = G1Projective;
type SubtableStrategy = AndSubtableStrategy;

let log_m = log2(M) as usize;

let r: Vec<F> = vec![F::from(0)];

// Elements are of the form [ x2 || y2, x1 || y1 ]
// So nz[0] is performing a lookup of AND(x, y) = AND(1110, 0011) = 0010
// nz[1] is unused; we just need s ≥ 2
let nz = vec![
[
0b0000111000000011,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
],
[
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
],
];

// Prove
let mut dense: DensifiedRepresentation<F, C> =
DensifiedRepresentation::from_lookup_indices(&nz, log_m);
let gens = SparsePolyCommitmentGens::<G>::new(b"gens_sparse_poly", C, S, C, log_m);
let commitment = dense.commit::<G>(&gens);
let mut random_tape = RandomTape::new(b"proof");
let mut prover_transcript = Transcript::new(b"example");
let proof = SparsePolynomialEvaluationProof::<G, C, M, SubtableStrategy>::prove(
&mut dense,
&r,
&gens,
&mut prover_transcript,
&mut random_tape,
);

// Need to make relevant struct fields `pub` for this to work
let eval: BigInteger256 = proof.primary_sumcheck.claimed_evaluation.into();

// Should print 0010
println!(
"{}",
eval
.to_bits_be()
.iter()
.map(|&b| if b { "1" } else { "0" })
.collect::<String>()
);

let mut verify_transcript = Transcript::new(b"example");
proof
.verify(&commitment, &r, &gens, &mut verify_transcript)
.expect("should verify");
}
6 changes: 3 additions & 3 deletions src/lasso/surge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ impl<G: CurveGroup> AppendToTranscript<G> for SparsePolynomialCommitment<G> {
}

#[derive(Debug, CanonicalSerialize, CanonicalDeserialize)]
struct PrimarySumcheck<G: CurveGroup, const ALPHA: usize> {
pub struct PrimarySumcheck<G: CurveGroup, const ALPHA: usize> {
proof: SumcheckInstanceProof<G::ScalarField>,
claimed_evaluation: G::ScalarField,
pub claimed_evaluation: G::ScalarField,
eval_derefs: [G::ScalarField; ALPHA],
proof_derefs: CombinedTableEvalProof<G, ALPHA>,
}
Expand All @@ -98,7 +98,7 @@ pub struct SparsePolynomialEvaluationProof<
[(); S::NUM_MEMORIES]: Sized,
{
comm_derefs: CombinedTableCommitment<G>,
primary_sumcheck: PrimarySumcheck<G, { S::NUM_MEMORIES }>,
pub primary_sumcheck: PrimarySumcheck<G, { S::NUM_MEMORIES }>,
memory_check: MemoryCheckingProof<G, C, M, S>,
}

Expand Down
Loading