-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from sota-zk-labs/sot-175-kzg-example
feat: Add examples for KZG commiment
- Loading branch information
Showing
5 changed files
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use ark_bls12_381::Fr; | ||
use ark_poly::univariate::DensePolynomial; | ||
use ark_poly::{DenseUVPolynomial, Polynomial}; | ||
use kzg::scheme::KzgScheme; | ||
use kzg::srs::Srs; | ||
|
||
fn main() { | ||
// trusted setup | ||
let srs = Srs::new(10); | ||
let scheme = KzgScheme::new(srs); | ||
|
||
// polynomial x^3 + 3x + 5 | ||
|
||
let coeff = vec![Fr::from(5), Fr::from(3), Fr::from(0), Fr::from(1)]; | ||
let poly = DensePolynomial::from_coefficients_vec(coeff); | ||
let v = poly.evaluate(&Fr::from(1)); | ||
assert_eq!(v, Fr::from(9)); | ||
|
||
// commit poly | ||
let commitment = scheme.commit(&poly); | ||
// opening point at p = 4. | ||
let opening_pos = Fr::from(4); | ||
let opening = scheme.open(&poly, opening_pos); | ||
|
||
assert!(scheme.verify(&commitment, &opening, opening_pos)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters