mirror of
https://github.com/arnaucube/fri-commitment.git
synced 2026-01-12 00:41:30 +01:00
Add GHA and readme usage examples
This commit is contained in:
14
.github/workflows/test.yml
vendored
Normal file
14
.github/workflows/test.yml
vendored
Normal file
@@ -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
|
||||||
39
README.md
39
README.md
@@ -1,8 +1,41 @@
|
|||||||
# fri-commitment
|
# fri-commitment [](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.
|
> *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);
|
||||||
|
```
|
||||||
|
|||||||
38
src/lib.rs
38
src/lib.rs
@@ -238,7 +238,6 @@ pub struct FRI_PCS_Proof<F: PrimeField> {
|
|||||||
p_proof: LDTProof<F>,
|
p_proof: LDTProof<F>,
|
||||||
g_proof: LDTProof<F>,
|
g_proof: LDTProof<F>,
|
||||||
mtproof_y: Vec<F>,
|
mtproof_y: Vec<F>,
|
||||||
claimed_y: F,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FRI_PCS implements the FRI Polynomial Commitment
|
// FRI_PCS implements the FRI Polynomial Commitment
|
||||||
@@ -252,7 +251,12 @@ impl<F: PrimeField, P: DenseUVPolynomial<F>, H: Hash<F>> FRI_PCS<F, P, H>
|
|||||||
where
|
where
|
||||||
for<'a, 'b> &'a P: Div<&'b P, Output = P>,
|
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 d = p.degree();
|
||||||
let sub_order = d * rho1;
|
let sub_order = d * rho1;
|
||||||
let eval_sub_domain: GeneralEvaluationDomain<F> =
|
let eval_sub_domain: GeneralEvaluationDomain<F> =
|
||||||
@@ -263,7 +267,7 @@ where
|
|||||||
MerkleTree::<F, H>::commit(&subdomain_evaluations)
|
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 = p.evaluate(&r);
|
||||||
let y_poly: P = P::from_coefficients_vec(vec![y]);
|
let y_poly: P = P::from_coefficients_vec(vec![y]);
|
||||||
let mut p_y: P = p.clone();
|
let mut p_y: P = p.clone();
|
||||||
@@ -279,18 +283,22 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO proof for commitment
|
// 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 y_eval_index = F::from(3_u32); // TODO find y in subdomain_evaluations
|
||||||
let mtproof_y = commitment_mt.open(y_eval_index);
|
let mtproof_y = commitment_mt.open(y_eval_index);
|
||||||
|
|
||||||
let p_proof = FRI_LDT::<F, P, H>::prove(p);
|
let p_proof = FRI_LDT::<F, P, H>::prove(p);
|
||||||
let g_proof = FRI_LDT::<F, P, H>::prove(&g);
|
let g_proof = FRI_LDT::<F, P, H>::prove(&g);
|
||||||
|
|
||||||
FRI_PCS_Proof {
|
(
|
||||||
p_proof,
|
y,
|
||||||
g_proof,
|
FRI_PCS_Proof {
|
||||||
mtproof_y,
|
p_proof,
|
||||||
claimed_y: y,
|
g_proof,
|
||||||
}
|
mtproof_y,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify(commitment: F, proof: FRI_PCS_Proof<F>, r: F, y: F) -> bool {
|
pub fn verify(commitment: F, proof: FRI_PCS_Proof<F>, r: F, y: F) -> bool {
|
||||||
@@ -363,10 +371,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prove() {
|
fn test_prove() {
|
||||||
let mut rng = ark_std::test_rng();
|
|
||||||
|
|
||||||
let deg = 31;
|
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);
|
assert_eq!(p.degree(), deg);
|
||||||
// println!("p {:?}", p);
|
// println!("p {:?}", p);
|
||||||
|
|
||||||
@@ -383,21 +389,19 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_polynomial_commitment() {
|
fn test_polynomial_commitment() {
|
||||||
let mut rng = ark_std::test_rng();
|
|
||||||
|
|
||||||
let deg = 31;
|
let deg = 31;
|
||||||
|
let mut rng = ark_std::test_rng();
|
||||||
let p = DensePolynomial::<Fr>::rand(deg, &mut rng);
|
let p = DensePolynomial::<Fr>::rand(deg, &mut rng);
|
||||||
|
|
||||||
type PCS = FRI_PCS<Fr, DensePolynomial<Fr>, Keccak256Hash<Fr>>;
|
type PCS = FRI_PCS<Fr, DensePolynomial<Fr>, Keccak256Hash<Fr>>;
|
||||||
|
|
||||||
let (commitment, commitment_mt) = PCS::commit(&p);
|
let commitment = PCS::commit(&p);
|
||||||
|
|
||||||
// Verifier
|
// Verifier
|
||||||
let r = Fr::rand(&mut rng);
|
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);
|
let v = PCS::verify(commitment, proof, r, claimed_y);
|
||||||
assert!(v);
|
assert!(v);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user