diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fa79d12 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,14 @@ +name: Test +on: [push, pull_request] +env: + CARGO_TERM_COLOR: always +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --verbose + - name: Run tests + run: | + cargo test --verbose diff --git a/README.md b/README.md index cc8ac98..3377a47 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,41 @@ -# fri-commitment +# fri-commitment [![Test](https://github.com/arnaucube/fri-commitment/workflows/Test/badge.svg)](https://github.com/arnaucube/fri-commitment/actions?query=workflow%3ATest) -FRI implemented on arkworks libraries. +FRI low degree testing & FRI polynomial commitment using [[VP19]](https://eprint.iacr.org/2019/1020)'s trick. Implementation using arkworks libraries. > *Note*: done in my free time to learn about FRI, do not use in production. -Thanks to [Vincenzo Iovino](https://sites.google.com/site/vincenzoiovinoit/) for explainations on [FRI](https://eccc.weizmann.ac.il/report/2017/134/). +Thanks to [Vincenzo Iovino](https://sites.google.com/site/vincenzoiovinoit/) for explainations on [FRI](https://eccc.weizmann.ac.il/report/2017/134/) & [[VP19]](https://eprint.iacr.org/2019/1020). + +## Usage + +FRI-LDT: +```rust +type LDT = FRI_LDT, Keccak256Hash>; + +let deg = 31; +let p = DensePolynomial::::rand(deg, &mut ark_std::test_rng()); + +let proof = LDT::prove(&p); + +let v = LDT::verify(proof, deg); +assert!(v); +``` + +FRI-PCS: +```rust +type PCS = FRI_PCS, Keccak256Hash>; + +let deg = 31; +let mut rng = ark_std::test_rng(); +let p = DensePolynomial::::rand(deg, &mut rng); + +let commitment = PCS::commit(&p); + +let r = Fr::rand(&mut rng); + +let (proof, claimed_y) = PCS::open(&p, r); + +let v = PCS::verify(commitment, proof, r, claimed_y); +assert!(v); +``` diff --git a/src/lib.rs b/src/lib.rs index 4ff5d82..2e21249 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -238,7 +238,6 @@ pub struct FRI_PCS_Proof { p_proof: LDTProof, g_proof: LDTProof, mtproof_y: Vec, - claimed_y: F, } // FRI_PCS implements the FRI Polynomial Commitment @@ -252,7 +251,12 @@ impl, H: Hash> FRI_PCS where for<'a, 'b> &'a P: Div<&'b P, Output = P>, { - pub fn commit(p: &P) -> (F, MerkleTree) { + pub fn commit(p: &P) -> F { + let (cm, _) = Self::tree_from_domain_evals(p); + cm + } + + fn tree_from_domain_evals(p: &P) -> (F, MerkleTree) { let d = p.degree(); let sub_order = d * rho1; let eval_sub_domain: GeneralEvaluationDomain = @@ -263,7 +267,7 @@ where MerkleTree::::commit(&subdomain_evaluations) } - pub fn open(p: &P, commitment_mt: MerkleTree, r: F) -> FRI_PCS_Proof { + pub fn open(p: &P, r: F) -> (F, FRI_PCS_Proof) { let y = p.evaluate(&r); let y_poly: P = P::from_coefficients_vec(vec![y]); let mut p_y: P = p.clone(); @@ -279,18 +283,22 @@ where } // TODO proof for commitment + // reconstruct commitment_mt + let (_, commitment_mt) = Self::tree_from_domain_evals(&p); let y_eval_index = F::from(3_u32); // TODO find y in subdomain_evaluations let mtproof_y = commitment_mt.open(y_eval_index); let p_proof = FRI_LDT::::prove(p); let g_proof = FRI_LDT::::prove(&g); - FRI_PCS_Proof { - p_proof, - g_proof, - mtproof_y, - claimed_y: y, - } + ( + y, + FRI_PCS_Proof { + p_proof, + g_proof, + mtproof_y, + }, + ) } pub fn verify(commitment: F, proof: FRI_PCS_Proof, r: F, y: F) -> bool { @@ -363,10 +371,8 @@ mod tests { #[test] fn test_prove() { - let mut rng = ark_std::test_rng(); - let deg = 31; - let p = DensePolynomial::::rand(deg, &mut rng); + let p = DensePolynomial::::rand(deg, &mut ark_std::test_rng()); assert_eq!(p.degree(), deg); // println!("p {:?}", p); @@ -383,21 +389,19 @@ mod tests { #[test] fn test_polynomial_commitment() { - let mut rng = ark_std::test_rng(); - let deg = 31; + let mut rng = ark_std::test_rng(); let p = DensePolynomial::::rand(deg, &mut rng); type PCS = FRI_PCS, Keccak256Hash>; - let (commitment, commitment_mt) = PCS::commit(&p); + let commitment = PCS::commit(&p); // Verifier let r = Fr::rand(&mut rng); - let proof = PCS::open(&p, commitment_mt, r); + let (claimed_y, proof) = PCS::open(&p, r); - let claimed_y = proof.claimed_y.clone(); // WIP let v = PCS::verify(commitment, proof, r, claimed_y); assert!(v); }