Skip to content

Commit

Permalink
Implement for chapter 5 (#8)
Browse files Browse the repository at this point in the history
1. Implement Fiat-Shamir Abstraction
2. Implement non-interactive sumcheck.
  • Loading branch information
SuccinctPaul authored Aug 4, 2023
1 parent 584fa37 commit 8b7726a
Show file tree
Hide file tree
Showing 22 changed files with 1,120 additions and 51 deletions.
21 changes: 6 additions & 15 deletions 4_GKR/src/gkr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@
// when applied to a layered arithmetic circuit C of depth d and fan-in two on input x ∈ Fn.
// Throughout, ki denotes log2(Si) where Si is the number of gates at layer i of C.

mod verifier;
mod prover;
mod verifier;

struct GKR {}

struct GKR{


}

impl GKR{
impl GKR {
// Init with layer-circuit
fn init(){

}

fn run_protocol(){
fn init() {}

}

}
fn run_protocol() {}
}
24 changes: 5 additions & 19 deletions 4_GKR/src/gkr/prover.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
use bls12_381::Scalar;

pub struct Prover{

}
pub struct Prover {}

impl Prover {


// At the start of the protocol, P sends a function D: {0,1}k0 → F claimed to equal W0
// (the function mapping output gate labels to output values).
pub fn proof(&self) -> () {

}
pub fn proof(&self) -> () {}

pub fn round_1(&self) -> () {
todo!()
}


// total d round: i=0,1,...,d−1
pub fn round_i(&self) -> () {
pub fn round_i(&self) -> () {
todo!()
}


// Define the (2ki+1)-variate polynomial
pub fn gen_f_ri(){

}




}
pub fn gen_f_ri() {}
}
17 changes: 4 additions & 13 deletions 4_GKR/src/gkr/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
use rand_core::{OsRng, RngCore};

pub struct Verifier{

}

impl Verifier{
pub struct Verifier {}

impl Verifier {
// generate r1, r2, ..., rv
fn gen_challenge() -> usize {
let k = OsRng.next_u32() % 1000;
k as usize
}

// picks a random r0∈Fk0 and lets m0←D ̃(r0).
fn round_i(){

}

fn round_i() {}

// V checks m_d = W_d (r_d )
fn check(){

}

fn check() {}
}
3 changes: 0 additions & 3 deletions 4_GKR/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

mod gkr;




#[cfg(test)]
mod test {
#[test]
Expand Down
1 change: 1 addition & 0 deletions 4_sumcheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sumcheck"
version = "0.1.0"
edition = "2021"
description = "interactive sumcheck"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 0 additions & 1 deletion 4_sumcheck/src/sumcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ mod test {

let mut sumcheck = SumCheck::new(mpoly);

// todo! meet error
sumcheck.run_protocol();
}
}
15 changes: 15 additions & 0 deletions 5_Fiat_Shamir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "Fiat_Shamir"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sha3 = "0.10.6"

[dev-dependencies]
ff = "0.13.0"
bls12_381 = "0.8.0"
rand = "0.8.5"
rand_core = { version = "0.6.4", default-features = false, features = ["std"] }
57 changes: 57 additions & 0 deletions 5_Fiat_Shamir/src/default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::Transcript;
use sha3::{Digest, Keccak256};

pub struct Keccak256Transcript {
hasher: Keccak256,
}

impl Transcript for Keccak256Transcript {
fn append(&mut self, new_data: &[u8]) {
self.hasher.update(&mut new_data.to_owned());
}

fn challenge(&mut self) -> [u8; 32] {
let mut result_hash = [0_u8; 32];
result_hash.copy_from_slice(&self.hasher.finalize_reset());
result_hash.reverse();
self.hasher.update(result_hash);
result_hash
}
}

impl Default for Keccak256Transcript {
fn default() -> Self {
Self {
hasher: Keccak256::new(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use bls12_381::Scalar;
use ff::Field;
use rand_core::OsRng;

#[test]
fn test() {
let mut rng = OsRng;
let s_one = Scalar::random(rng);
let s_two = Scalar::random(rng);

let mut transcript1 = Keccak256Transcript::default();
transcript1.append(&s_one.to_bytes());
transcript1.append(&s_two.to_bytes());

let challenge_1 = transcript1.challenge();

let mut transcript2 = Keccak256Transcript::default();
transcript2.append(&s_one.to_bytes());
transcript2.append(&s_two.to_bytes());

let challenge_2 = transcript2.challenge();

assert_eq!(challenge_1, challenge_2);
}
}
7 changes: 7 additions & 0 deletions 5_Fiat_Shamir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![allow(non_snake_case)]
pub mod default;

pub trait Transcript {
fn append(&mut self, new_data: &[u8]);
fn challenge(&mut self) -> [u8; 32];
}
16 changes: 16 additions & 0 deletions 5_ni_sumcheck/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "ni_sumcheck"
version = "0.1.0"
edition = "2021"
description = "non-interactive sumcheck"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ff = "0.13.0"
bls12_381 = "0.8.0"
rand = "0.8.5"
rand_core = { version = "0.6.4", default-features = false, features = ["std"] }
rayon = "1.7.0"
log = "0.4.19"
sha3 = "0.10.6"
6 changes: 6 additions & 0 deletions 5_ni_sumcheck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(non_snake_case)]

mod poly;
mod sumcheck;
mod transcript;
mod utils;
2 changes: 2 additions & 0 deletions 5_ni_sumcheck/src/poly.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod multivar_poly;
pub mod univar_poly;
Loading

0 comments on commit 8b7726a

Please sign in to comment.