Browse Source

Add GHA and readme usage examples

main
arnaucube 1 year ago
parent
commit
ead8e36753
3 changed files with 71 additions and 20 deletions
  1. +14
    -0
      .github/workflows/test.yml
  2. +36
    -3
      README.md
  3. +21
    -17
      src/lib.rs

+ 14
- 0
.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

+ 36
- 3
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<Fr, DensePolynomial<Fr>, Keccak256Hash<Fr>>;
let deg = 31;
let p = DensePolynomial::<Fr>::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<Fr, DensePolynomial<Fr>, Keccak256Hash<Fr>>;
let deg = 31;
let mut rng = ark_std::test_rng();
let p = DensePolynomial::<Fr>::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);
```

+ 21
- 17
src/lib.rs

@ -238,7 +238,6 @@ pub struct FRI_PCS_Proof {
p_proof: LDTProof<F>,
g_proof: LDTProof<F>,
mtproof_y: Vec<F>,
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<F, H>) {
pub fn commit(p: &P) -> F {
let (cm, _) = Self::tree_from_domain_evals(p);
cm
}
fn tree_from_domain_evals(p: &P) -> (F, MerkleTree<F, H>) {
let d = p.degree();
let sub_order = d * rho1;
let eval_sub_domain: GeneralEvaluationDomain<F> =
@ -263,7 +267,7 @@ where
MerkleTree::<F, H>::commit(&subdomain_evaluations)
}
pub fn open(p: &P, commitment_mt: MerkleTree<F, H>, r: F) -> FRI_PCS_Proof<F> {
pub fn open(p: &P, r: F) -> (F, FRI_PCS_Proof<F>) {
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::<F, P, H>::prove(p);
let g_proof = FRI_LDT::<F, P, H>::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<F>, 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::<Fr>::rand(deg, &mut rng);
let p = DensePolynomial::<Fr>::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::<Fr>::rand(deg, &mut rng);
type PCS = FRI_PCS<Fr, DensePolynomial<Fr>, Keccak256Hash<Fr>>;
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);
}

Loading…
Cancel
Save