Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arkworks-rs/poly-commit
A Rust library for polynomial commitments
https://github.com/arkworks-rs/poly-commit
cryptography marlin pairings polynomial-commitments rust sonic
Last synced: 4 days ago
JSON representation
A Rust library for polynomial commitments
- Host: GitHub
- URL: https://github.com/arkworks-rs/poly-commit
- Owner: arkworks-rs
- License: apache-2.0
- Created: 2019-09-13T03:01:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T09:55:10.000Z (11 days ago)
- Last Synced: 2024-10-29T11:55:56.448Z (11 days ago)
- Topics: cryptography, marlin, pairings, polynomial-commitments, rust, sonic
- Language: Rust
- Homepage:
- Size: 656 KB
- Stars: 335
- Watchers: 24
- Forks: 131
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
- Codeowners: .github/CODEOWNERS
- Authors: AUTHORS
Awesome Lists containing this project
- awesome-ccamel - arkworks-rs/poly-commit - A Rust library for polynomial commitments (Rust)
README
Polynomial Commitments
`poly-commit` is a Rust library that implements *polynomial commitment schemes*. This library was initially developed as part of the [Marlin paper][marlin], and is released under the MIT License and the Apache v2 License (see [License](#license)).
**WARNING:** This is an academic prototype, and in particular has not received careful code review. This implementation is NOT ready for production use.
## Overview
A polynomial commitment scheme is a cryptographic primitive that enables a party to commit to a polynomial over a given finite field, and then, later on, to reveal desired evaluations of the polynomial along with cryptographic proofs attesting to their correctness.
This library provides various constructions of polynomial commitment schemes. These constructions support committing to multiple polynomials at a time with differing degree bounds, batching multiple evaluation proofs for the same evaluation point into a single one, and batch verification of proofs.
The key properties satisfied by the polynomial commitment schemes are **succinctness**, **extractability**, and **hiding**. See [the Marlin paper][marlin] for definitions of these properties.
[kzg10]: http://cacr.uwaterloo.ca/techreports/2010/cacr2010-10.pdf
## Build guide
The library compiles on the `stable` toolchain of the Rust compiler. To install the latest version of Rust, first install `rustup` by following the instructions [here](https://rustup.rs/), or via your platform's package manager. Once `rustup` is installed, install the Rust toolchain by invoking:
```bash
rustup install stable
```After that, use `cargo` (the standard Rust build tool) to build the library:
```bash
git clone https://github.com/scipr-lab/poly-commit.git
cd poly-commit
cargo build --release
```This library comes with some unit and integration tests. Run these tests with:
```bash
cargo test
```A benchmarking module is also provided for the `commit`, `open` and `verify` methods, as well as for computing the commitment and proof size. You can add a new benchmark for your scheme following the examples in the `pcs/benches` directory, or run the existing benchmarks with:
```bash
cargo bench
```Lastly, this library is instrumented with profiling infrastructure that prints detailed traces of execution time. To enable this, compile with `cargo build --features print-trace`.
## Usage
### [`PolynomialCommitment`](https://github.com/arkworks-rs/poly-commit/blob/master/src/lib.rs#L145)
This trait defines the interface for a polynomial commitment scheme. It is recommended to use the schemes from this crate that implement the `PolynomialCommitment` trait
(e.g. the [vanilla KZG scheme](./src/kzg10/mod.rs) does not implement this trait, but the [Marlin scheme](./src/marlin/mod.rs) which uses it under the hood, does).```rust
// In this example, we will commit to a single polynomial, open it first at one point, and then batched at two points, and finally verify the proofs.
// We will use the KZG10 polynomial commitment scheme, following the approach from Marlin.use ark_poly_commit::{Polynomial, marlin_pc::MarlinKZG10, LabeledPolynomial, PolynomialCommitment, QuerySet, Evaluations};
use ark_bls12_377::Bls12_377;
use ark_crypto_primitives::sponge::poseidon::{PoseidonSponge, PoseidonConfig};
use ark_crypto_primitives::sponge::CryptographicSponge;
use ark_ec::pairing::Pairing;
use ark_ff::UniformRand;
use ark_std::test_rng;
use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
use rand_chacha::ChaCha20Rng;
use ark_ff::PrimeField;type UniPoly_377 = DensePolynomial<::ScalarField>;
type PCS = MarlinKZG10;let rng = &mut test_rng();
let max_degree = 16; // max degree supported by the scheme with the given public parameters generated by the setup here.
// 1. PolynomialCommitment::setup
// The setup procedure in this example is for demonstration purposes only - typically a setup ceremony would be run to generate the public parameters.
let pp = PCS::setup(max_degree, None, rng).unwrap();let degree = 10; //degree of our polynomial
let secret_poly = UniPoly_377::rand(degree, rng);let point_1 = ::ScalarField::rand(rng);
let point_2 = ::ScalarField::rand(rng);let label = String::from("secret_poly");
let labeled_poly = LabeledPolynomial::new(
label.clone(),
secret_poly.clone(),
Some(degree),
Some(2), // we will open a univariate poly at two points
);// TODO: replace by https://github.com/arkworks-rs/crypto-primitives/issues/112.
fn test_sponge() -> PoseidonSponge {
let full_rounds = 8;
let partial_rounds = 31;
let alpha = 17;let mds = vec![
vec![F::one(), F::zero(), F::one()],
vec![F::one(), F::one(), F::zero()],
vec![F::zero(), F::one(), F::one()],
];let mut v = Vec::new();
let mut ark_rng = test_rng();for _ in 0..(full_rounds + partial_rounds) {
let mut res = Vec::new();for _ in 0..3 {
res.push(F::rand(&mut ark_rng));
}
v.push(res);
}
let config = PoseidonConfig::new(full_rounds, partial_rounds, alpha, mds, v, 2, 1);
PoseidonSponge::new(&config)
}
let mut test_sponge = test_sponge::<::ScalarField>();// 2. PolynomialCommitment::trim
// Since the setup produced pp with a max degree of 16, and our poly is of degree 10, we can trim the SRS to tailor it to this example.
let (ck, vk) = PCS::trim(&pp, degree, 2, Some(&[degree])).unwrap();// 3. PolynomialCommitment::commit
// The prover commits to the polynomial using their committer key `ck`.
let (comms, states) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();// 4a. PolynomialCommitment::open
// Opening proof at a single point.
let proof_single = PCS::open(&ck, [&labeled_poly], &comms, &point_1, &mut (test_sponge.clone()), &states, None).unwrap();// 5a. PolynomialCommitment::check
// Verifying the proof at a single point, given the commitment, the point, the claimed evaluation, and the proof.
assert!(PCS::check(&vk, &comms, &point_1, [secret_poly.evaluate(&point_1)], &proof_single, &mut (test_sponge.clone()), Some(rng)).unwrap());let mut query_set = QuerySet::new();
let mut values = Evaluations::new();
for (i, point) in [point_1, point_2].iter().enumerate() {
query_set.insert((label.clone(), (format!("{}", i), point.clone())));
let value = secret_poly.evaluate(&point);
values.insert((label.clone(), point.clone()), value);
}// 4b. PolynomialCommitment::batch_open
// Some schemes support batch opening proofs. Generate a single proof for opening the polynomial at multiple points.
let proof_batched = PCS::batch_open(
&ck,
[&labeled_poly],
&comms,
&query_set,
&mut (test_sponge.clone()),
&states,
Some(rng),
).unwrap();// 5b. PolynomialCommitment::batch_check
assert!(PCS::batch_check(
&vk,
&comms,
&query_set,
&values,
&proof_batched,
&mut (test_sponge.clone()),
rng,
).unwrap());
```## License
This library is licensed under either of the following licenses, at your discretion.
* [Apache License Version 2.0](LICENSE-APACHE)
* [MIT License](LICENSE-MIT)Unless you explicitly state otherwise, any contribution that you submit to this library shall be dual licensed as above (as defined in the Apache v2 License), without any additional terms or conditions.
[marlin]: https://ia.cr/2019/1047
[sonic]: https://ia.cr/2019/099
[aurora-light]: https://ia.cr/2019/601
[pcd-acc]: https://ia.cr/2020/499
[pst]: https://ia.cr/2011/587
[brakedown]: https://ia.cr/2021/1043
[ligero]: https://ia.cr/2022/1608
[hyrax]: https://eprint.iacr.org/2017/1132## Reference papers
[Polynomial Commitments][kzg10]
Aniket Kate, Gregory M. Zaverucha, Ian Goldberg
ASIACRYPT 2010[Sonic: Zero-Knowledge SNARKs from Linear-Size Universal and Updateable Structured Reference Strings][sonic]
Mary Maller, Sean Bowe, Markulf Kohlweiss, Sarah Meiklejohn
CCS 2019[AuroraLight: Improved Prover Efficiency and SRS Size in a Sonic-Like System][aurora-light]
Ariel Gabizon
ePrint, 2019[Marlin: Preprocessing zkSNARKs with Universal and Updatable SRS][marlin]
Alessandro Chiesa, Yuncong Hu, Mary Maller, [Pratyush Mishra](https://www.github.com/pratyush), Noah Vesely, [Nicholas Ward](https://www.github.com/npwardberkeley)
EUROCRYPT 2020[Proof-Carrying Data from Accumulation Schemes][pcd-acc]
Benedikt Bünz, Alessandro Chiesa, [Pratyush Mishra](https://www.github.com/pratyush), Nicholas Spooner
TCC 2020[Signatures of Correct Computation][pst]
Charalampos Papamanthou, Elaine Shi, Roberto Tamassia
TCC 2013[Ligero: Lightweight Sublinear Arguments Without a Trusted Setup][ligero]
Scott Ames, Carmit Hazay, Yuval Ishai, Muthuramakrishnan Venkitasubramaniam
CCS 2017[Doubly-efficient zkSNARKs without trusted setup][hyrax]
Riad S. Wahby, Ioanna Tzialla, abhi shelat, Justin Thaler, Michael Walfish
2018 IEEE Symposium on Security and Privacy[Brakedown: Linear-time and field-agnostic SNARKs for R1CS][brakedown]
Alexander Golovnev, Jonathan Lee, Srinath Setty, Justin Thaler, Riad S. Wahby
CRYPTO 2023## Acknowledgements
This work was supported by: an Engineering and Physical Sciences Research Council grant; a Google Faculty Award; the RISELab at UC Berkeley; and donations from the Ethereum Foundation and the Interchain Foundation.