From 686e83d28b46abc6b55f4b8f345135a037a83e42 Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya <68976082+irakliyk@users.noreply.github.com>
Date: Sat, 26 Oct 2024 13:01:41 -0700
Subject: [PATCH 01/19] fixed maybe-async dependency (#337)
---
README.md | 4 ++--
prover/Cargo.toml | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 4616bf5a5..230146c2b 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,8 @@
-
-
+
+
A STARK prover and verifier for arbitrary computations.
diff --git a/prover/Cargo.toml b/prover/Cargo.toml
index 85b5dbcd7..6dd616a1a 100644
--- a/prover/Cargo.toml
+++ b/prover/Cargo.toml
@@ -34,7 +34,7 @@ air = { version = "0.10", path = "../air", package = "winter-air", default-featu
crypto = { version = "0.10", path = "../crypto", package = "winter-crypto", default-features = false }
fri = { version = "0.10", path = '../fri', package = "winter-fri", default-features = false }
math = { version = "0.10", path = "../math", package = "winter-math", default-features = false }
-maybe_async = { path = "../utils/maybe_async" , package = "winter-maybe-async" }
+maybe_async = { version = "0.10", path = "../utils/maybe_async" , package = "winter-maybe-async" }
tracing = { version = "0.1", default-features = false, features = ["attributes"]}
utils = { version = "0.10", path = "../utils/core", package = "winter-utils", default-features = false }
From be61c26a537e85a9d9fde7d77379ae2211074b68 Mon Sep 17 00:00:00 2001
From: Al-Kindi-0 <82364884+Al-Kindi-0@users.noreply.github.com>
Date: Wed, 30 Oct 2024 15:57:27 +0100
Subject: [PATCH 02/19] Fix partition hashing (#338)
---
air/src/options.rs | 4 ++++
prover/src/lib.rs | 1 +
prover/src/matrix/row_matrix.rs | 2 +-
verifier/src/channel.rs | 2 +-
4 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/air/src/options.rs b/air/src/options.rs
index a831bdad7..01599489c 100644
--- a/air/src/options.rs
+++ b/air/src/options.rs
@@ -377,7 +377,11 @@ impl PartitionOptions {
/// Returns the size of each partition used when committing to the main and auxiliary traces as
/// well as the constraint evaluation trace.
+ /// The returned size is given in terms of number of columns in the field `E`.
pub fn partition_size(&self, num_columns: usize) -> usize {
+ if self.num_partitions == 1 && self.min_partition_size == 1 {
+ return num_columns;
+ }
let base_elements_per_partition = cmp::max(
(num_columns * E::EXTENSION_DEGREE).div_ceil(self.num_partitions as usize),
self.min_partition_size as usize,
diff --git a/prover/src/lib.rs b/prover/src/lib.rs
index 035d6c655..1a2e157ea 100644
--- a/prover/src/lib.rs
+++ b/prover/src/lib.rs
@@ -219,6 +219,7 @@ pub trait Prover {
/// Builds and returns the auxiliary trace.
#[allow(unused_variables)]
#[maybe_async]
+ #[instrument(skip_all)]
fn build_aux_trace(
&self,
main_trace: &Self::Trace,
diff --git a/prover/src/matrix/row_matrix.rs b/prover/src/matrix/row_matrix.rs
index 85b43122e..6cb9ef60c 100644
--- a/prover/src/matrix/row_matrix.rs
+++ b/prover/src/matrix/row_matrix.rs
@@ -188,7 +188,7 @@ impl RowMatrix {
// allocate vector to store row hashes
let mut row_hashes = unsafe { uninit_vector::(self.num_rows()) };
- if partition_size == self.num_cols() * E::EXTENSION_DEGREE {
+ if partition_size == self.num_cols() {
// iterate though matrix rows, hashing each row
batch_iter_mut!(
&mut row_hashes,
diff --git a/verifier/src/channel.rs b/verifier/src/channel.rs
index 9d7dbc426..e6c511cd8 100644
--- a/verifier/src/channel.rs
+++ b/verifier/src/channel.rs
@@ -442,7 +442,7 @@ where
E: FieldElement,
H: ElementHasher,
{
- if partition_size == row.len() * E::EXTENSION_DEGREE {
+ if partition_size == row.len() {
H::hash_elements(row)
} else {
let mut buffer = vec![H::Digest::default(); partition_size];
From 616892e9fe5f65b0399f58872fc36d3da6303c98 Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya
Date: Wed, 30 Oct 2024 08:04:47 -0700
Subject: [PATCH 03/19] incremented crate versions to 0.10.1 and updated
changelog
---
CHANGELOG.md | 3 +++
air/Cargo.toml | 4 ++--
crypto/Cargo.toml | 4 ++--
examples/Cargo.toml | 2 +-
fri/Cargo.toml | 4 ++--
math/Cargo.toml | 4 ++--
prover/Cargo.toml | 4 ++--
utils/core/Cargo.toml | 4 ++--
utils/rand/Cargo.toml | 4 ++--
verifier/Cargo.toml | 4 ++--
winterfell/Cargo.toml | 4 ++--
11 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f783b5e7..78563dabf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog
+## 0.10.1 (2024-10-30)
+- Fixed partition hashing and add logging to aux trace building (#338).
+
## 0.10.0 (2024-10-25)
- [BREAKING] Refactored maybe-async macro into simpler maybe-async and maybe-await macros (#283).
- [BREAKING] Introduce `VectorCommitment` abstraction (#285).
diff --git a/air/Cargo.toml b/air/Cargo.toml
index 12c56cd72..c3bf02c86 100644
--- a/air/Cargo.toml
+++ b/air/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-air"
-version = "0.10.0"
+version = "0.10.1"
description = "AIR components for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-air/0.10.0"
+documentation = "https://docs.rs/winter-air/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "arithmetization", "air"]
edition = "2021"
diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml
index 23f985fee..026c01d30 100644
--- a/crypto/Cargo.toml
+++ b/crypto/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-crypto"
-version = "0.10.0"
+version = "0.10.1"
description = "Cryptographic library for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-crypto/0.10.0"
+documentation = "https://docs.rs/winter-crypto/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "merkle-tree", "hash"]
edition = "2021"
diff --git a/examples/Cargo.toml b/examples/Cargo.toml
index f86e9ad50..5a4dbc5ab 100644
--- a/examples/Cargo.toml
+++ b/examples/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "examples"
-version = "0.10.0"
+version = "0.10.1"
description = "Examples of using Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
diff --git a/fri/Cargo.toml b/fri/Cargo.toml
index 2e3d1b20b..96a13d1a9 100644
--- a/fri/Cargo.toml
+++ b/fri/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-fri"
-version = "0.10.0"
+version = "0.10.1"
description = "Implementation of FRI protocol for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-fri/0.10.0"
+documentation = "https://docs.rs/winter-fri/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "polynomial", "commitments"]
edition = "2021"
diff --git a/math/Cargo.toml b/math/Cargo.toml
index 061c2d52f..1490d1e63 100644
--- a/math/Cargo.toml
+++ b/math/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-math"
-version = "0.10.0"
+version = "0.10.1"
description = "Math library for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-math/0.10.0"
+documentation = "https://docs.rs/winter-math/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "finite-fields", "polynomials", "fft"]
edition = "2021"
diff --git a/prover/Cargo.toml b/prover/Cargo.toml
index 6dd616a1a..3193bee0c 100644
--- a/prover/Cargo.toml
+++ b/prover/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-prover"
-version = "0.10.0"
+version = "0.10.1"
description = "Winterfell STARK prover"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-prover/0.10.0"
+documentation = "https://docs.rs/winter-prover/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "prover"]
edition = "2021"
diff --git a/utils/core/Cargo.toml b/utils/core/Cargo.toml
index c606caa08..b8f2724e8 100644
--- a/utils/core/Cargo.toml
+++ b/utils/core/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-utils"
-version = "0.10.0"
+version = "0.10.1"
description = "Utilities for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-utils/0.10.0"
+documentation = "https://docs.rs/winter-utils/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["serialization", "transmute"]
edition = "2021"
diff --git a/utils/rand/Cargo.toml b/utils/rand/Cargo.toml
index 3e05c6437..759b02436 100644
--- a/utils/rand/Cargo.toml
+++ b/utils/rand/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-rand-utils"
-version = "0.10.0"
+version = "0.10.1"
description = "Random value generation utilities for Winterfell crates"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-rand-utils/0.10.0"
+documentation = "https://docs.rs/winter-rand-utils/0.10.1"
categories = ["cryptography"]
keywords = ["rand"]
edition = "2021"
diff --git a/verifier/Cargo.toml b/verifier/Cargo.toml
index 63d4b9c0f..1490e3e27 100644
--- a/verifier/Cargo.toml
+++ b/verifier/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-verifier"
-version = "0.10.0"
+version = "0.10.1"
description = "Winterfell STARK verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-verifier/0.10.0"
+documentation = "https://docs.rs/winter-verifier/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "verifier"]
edition = "2021"
diff --git a/winterfell/Cargo.toml b/winterfell/Cargo.toml
index cdeeb59ec..b37a07157 100644
--- a/winterfell/Cargo.toml
+++ b/winterfell/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winterfell"
-version = "0.10.0"
+version = "0.10.1"
description = "Winterfell STARK prover and verifier"
authors = ["winterfell contributors"]
readme = "../README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winterfell/0.10.0"
+documentation = "https://docs.rs/winterfell/0.10.1"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "prover", "verifier"]
edition = "2021"
From 0fe84bebc91e3a0f3ccdb47264bd94d92f3ed75d Mon Sep 17 00:00:00 2001
From: Philipp Gackstatter
Date: Mon, 18 Nov 2024 17:56:22 +0100
Subject: [PATCH 04/19] feat: implement `core::error::Error` for all error
types (#341)
---
CHANGELOG.md | 3 +++
air/src/errors.rs | 2 ++
crypto/src/errors.rs | 4 ++++
fri/src/errors.rs | 2 ++
prover/src/errors.rs | 2 ++
utils/core/src/errors.rs | 2 ++
utils/core/src/serde/mod.rs | 4 ++--
verifier/src/errors.rs | 2 ++
8 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 78563dabf..6ba38b967 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog
+## 0.10.2 (TBD)
+- Implement `core::error::Error` for error types (#341).
+
## 0.10.1 (2024-10-30)
- Fixed partition hashing and add logging to aux trace building (#338).
diff --git a/air/src/errors.rs b/air/src/errors.rs
index 2f0fa1665..38196ba7d 100644
--- a/air/src/errors.rs
+++ b/air/src/errors.rs
@@ -42,3 +42,5 @@ impl fmt::Display for AssertionError {
}
}
}
+
+impl core::error::Error for AssertionError {}
diff --git a/crypto/src/errors.rs b/crypto/src/errors.rs
index 5e4f3a6da..637b90c99 100644
--- a/crypto/src/errors.rs
+++ b/crypto/src/errors.rs
@@ -61,6 +61,8 @@ impl fmt::Display for MerkleTreeError {
}
}
+impl core::error::Error for MerkleTreeError {}
+
// RANDOM COIN ERROR
// ================================================================================================
@@ -89,3 +91,5 @@ impl fmt::Display for RandomCoinError {
}
}
}
+
+impl core::error::Error for RandomCoinError {}
diff --git a/fri/src/errors.rs b/fri/src/errors.rs
index 7961b8831..2947b17a8 100644
--- a/fri/src/errors.rs
+++ b/fri/src/errors.rs
@@ -73,3 +73,5 @@ impl fmt::Display for VerifierError {
}
}
}
+
+impl core::error::Error for VerifierError {}
diff --git a/prover/src/errors.rs b/prover/src/errors.rs
index a0d01a233..6fd560582 100644
--- a/prover/src/errors.rs
+++ b/prover/src/errors.rs
@@ -39,3 +39,5 @@ impl fmt::Display for ProverError {
}
}
}
+
+impl core::error::Error for ProverError {}
diff --git a/utils/core/src/errors.rs b/utils/core/src/errors.rs
index 52df2b007..1bba975bf 100644
--- a/utils/core/src/errors.rs
+++ b/utils/core/src/errors.rs
@@ -32,3 +32,5 @@ impl fmt::Display for DeserializationError {
}
}
}
+
+impl core::error::Error for DeserializationError {}
diff --git a/utils/core/src/serde/mod.rs b/utils/core/src/serde/mod.rs
index edf9ba1c8..90ac01b6d 100644
--- a/utils/core/src/serde/mod.rs
+++ b/utils/core/src/serde/mod.rs
@@ -344,7 +344,7 @@ impl Serializable for str {
}
fn get_size_hint(&self) -> usize {
- self.len().get_size_hint() + self.as_bytes().len()
+ self.len().get_size_hint() + self.len()
}
}
@@ -355,7 +355,7 @@ impl Serializable for String {
}
fn get_size_hint(&self) -> usize {
- self.len().get_size_hint() + self.as_bytes().len()
+ self.len().get_size_hint() + self.len()
}
}
diff --git a/verifier/src/errors.rs b/verifier/src/errors.rs
index e1b072db5..fadaee1fa 100644
--- a/verifier/src/errors.rs
+++ b/verifier/src/errors.rs
@@ -99,3 +99,5 @@ impl fmt::Display for VerifierError {
}
}
}
+
+impl core::error::Error for VerifierError {}
From 76c6db20e92fefea652236968e64438aabf28609 Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya
Date: Mon, 18 Nov 2024 21:00:10 -0800
Subject: [PATCH 05/19] update crate versions to v0.10.2
---
CHANGELOG.md | 2 +-
air/Cargo.toml | 4 ++--
crypto/Cargo.toml | 4 ++--
fri/Cargo.toml | 4 ++--
math/Cargo.toml | 4 ++--
prover/Cargo.toml | 4 ++--
verifier/Cargo.toml | 4 ++--
winterfell/Cargo.toml | 4 ++--
8 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ba38b967..3e2984822 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
# Changelog
-## 0.10.2 (TBD)
+## 0.10.2 (2024-11-18)
- Implement `core::error::Error` for error types (#341).
## 0.10.1 (2024-10-30)
diff --git a/air/Cargo.toml b/air/Cargo.toml
index c3bf02c86..0a363fd76 100644
--- a/air/Cargo.toml
+++ b/air/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-air"
-version = "0.10.1"
+version = "0.10.2"
description = "AIR components for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-air/0.10.1"
+documentation = "https://docs.rs/winter-air/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "arithmetization", "air"]
edition = "2021"
diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml
index 026c01d30..51d93574e 100644
--- a/crypto/Cargo.toml
+++ b/crypto/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-crypto"
-version = "0.10.1"
+version = "0.10.2"
description = "Cryptographic library for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-crypto/0.10.1"
+documentation = "https://docs.rs/winter-crypto/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "merkle-tree", "hash"]
edition = "2021"
diff --git a/fri/Cargo.toml b/fri/Cargo.toml
index 96a13d1a9..86c984442 100644
--- a/fri/Cargo.toml
+++ b/fri/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-fri"
-version = "0.10.1"
+version = "0.10.2"
description = "Implementation of FRI protocol for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-fri/0.10.1"
+documentation = "https://docs.rs/winter-fri/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "polynomial", "commitments"]
edition = "2021"
diff --git a/math/Cargo.toml b/math/Cargo.toml
index 1490d1e63..a2576ded4 100644
--- a/math/Cargo.toml
+++ b/math/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-math"
-version = "0.10.1"
+version = "0.10.2"
description = "Math library for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-math/0.10.1"
+documentation = "https://docs.rs/winter-math/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "finite-fields", "polynomials", "fft"]
edition = "2021"
diff --git a/prover/Cargo.toml b/prover/Cargo.toml
index 3193bee0c..c02905ca4 100644
--- a/prover/Cargo.toml
+++ b/prover/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-prover"
-version = "0.10.1"
+version = "0.10.2"
description = "Winterfell STARK prover"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-prover/0.10.1"
+documentation = "https://docs.rs/winter-prover/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "prover"]
edition = "2021"
diff --git a/verifier/Cargo.toml b/verifier/Cargo.toml
index 1490e3e27..4acf3d063 100644
--- a/verifier/Cargo.toml
+++ b/verifier/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-verifier"
-version = "0.10.1"
+version = "0.10.2"
description = "Winterfell STARK verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-verifier/0.10.1"
+documentation = "https://docs.rs/winter-verifier/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "verifier"]
edition = "2021"
diff --git a/winterfell/Cargo.toml b/winterfell/Cargo.toml
index b37a07157..6ade01023 100644
--- a/winterfell/Cargo.toml
+++ b/winterfell/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winterfell"
-version = "0.10.1"
+version = "0.10.2"
description = "Winterfell STARK prover and verifier"
authors = ["winterfell contributors"]
readme = "../README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winterfell/0.10.1"
+documentation = "https://docs.rs/winterfell/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "prover", "verifier"]
edition = "2021"
From f8e1216e54bd7fddaf26944c8f05ebaddc2f70e5 Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya
Date: Mon, 18 Nov 2024 21:06:25 -0800
Subject: [PATCH 06/19] update core-utils crate version to v0.10.2
---
utils/core/Cargo.toml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/utils/core/Cargo.toml b/utils/core/Cargo.toml
index b8f2724e8..7eb8f58d6 100644
--- a/utils/core/Cargo.toml
+++ b/utils/core/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-utils"
-version = "0.10.1"
+version = "0.10.2"
description = "Utilities for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-utils/0.10.1"
+documentation = "https://docs.rs/winter-utils/0.10.2"
categories = ["cryptography", "no-std"]
keywords = ["serialization", "transmute"]
edition = "2021"
From 86407151704a6e141c716a098dd0acafd1493b4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Grzegorz=20=C5=9Awirski?=
Date: Tue, 19 Nov 2024 23:18:03 +0100
Subject: [PATCH 07/19] Multi GPU partition fixes (#340)
---
air/src/options.rs | 115 ++++++++++++++++------
prover/src/lib.rs | 3 +-
prover/src/matrix/row_matrix.rs | 12 ++-
prover/src/trace/trace_lde/default/mod.rs | 18 ++--
verifier/src/channel.rs | 4 +-
5 files changed, 105 insertions(+), 47 deletions(-)
diff --git a/air/src/options.rs b/air/src/options.rs
index 01599489c..657a6381d 100644
--- a/air/src/options.rs
+++ b/air/src/options.rs
@@ -4,7 +4,7 @@
// LICENSE file in the root directory of this source tree.
use alloc::vec::Vec;
-use core::{cmp, ops::Div};
+use core::cmp;
use fri::FriOptions;
use math::{FieldElement, StarkField, ToElements};
@@ -76,16 +76,13 @@ pub enum FieldExtension {
/// collision resistance of the hash function used by the protocol. For example, if a hash function
/// with 128-bit collision resistance is used, soundness of a STARK proof cannot exceed 128 bits.
///
-/// In addition to the above, the parameter `num_partitions` is used in order to specify the number
-/// of partitions each of the traces committed to during proof generation is split into, and
-/// the parameter `min_partition_size` gives a lower bound on the size of each such partition.
-/// More precisely, and taking the main segment trace as an example, the prover will split the main
-/// segment trace into `num_partitions` parts each of size at least `min_partition_size`. The prover
-/// will then proceed to hash each part row-wise resulting in `num_partitions` digests per row of
-/// the trace. The prover finally combines the `num_partitions` digest (per row) into one digest
-/// (per row) and at this point the vector commitment scheme can be called.
-/// In the case when `num_partitions` is equal to `1` the prover will just hash each row in one go
-/// producing one digest per row of the trace.
+/// In addition, partition options (see [PartitionOptions]) can be provided to split traces during
+/// proving and distribute work across multiple devices. Taking the main segment trace as an example,
+/// the prover will split the main segment trace into `num_partitions` parts, and then proceed to hash
+/// each part row-wise resulting in `num_partitions` digests per row of the trace. Finally,
+/// `num_partitions` digests (per row) are combined into one digest (per row) and at this point
+/// a vector commitment scheme can be called. In the case when `num_partitions` is equal to `1` (default)
+/// the prover will hash each row in one go producing one digest per row of the trace.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ProofOptions {
num_queries: u8,
@@ -177,13 +174,13 @@ impl ProofOptions {
/// # Panics
/// Panics if:
/// - `num_partitions` is zero or greater than 16.
- /// - `min_partition_size` is zero or greater than 256.
+ /// - `hash_rate` is zero or greater than 256.
pub const fn with_partitions(
mut self,
num_partitions: usize,
- min_partition_size: usize,
+ hash_rate: usize,
) -> ProofOptions {
- self.partition_options = PartitionOptions::new(num_partitions, min_partition_size);
+ self.partition_options = PartitionOptions::new(num_partitions, hash_rate);
self
}
@@ -277,7 +274,7 @@ impl Serializable for ProofOptions {
target.write_u8(self.fri_folding_factor);
target.write_u8(self.fri_remainder_max_degree);
target.write_u8(self.partition_options.num_partitions);
- target.write_u8(self.partition_options.min_partition_size);
+ target.write_u8(self.partition_options.hash_rate);
}
}
@@ -347,31 +344,43 @@ impl Deserializable for FieldExtension {
// PARTITION OPTION IMPLEMENTATION
// ================================================================================================
-/// Defines the parameters used when committing to the traces generated during the protocol.
+/// Defines the parameters used to calculate partition size when committing to the traces
+/// generated during the protocol.
+///
+/// Using multiple partitions will change how vector commitments are calculated:
+/// - Input matrix columns are split into at most num_partitions partitions
+/// - For each matrix row, a hash is calculated for each partition separately
+/// - The results are merged together by one more hash iteration
+///
+/// This is especially useful when proving with multiple GPU cards where each device holds
+/// a subset of data and allows less data reshuffling when generating commitments.
+///
+/// Hash_rate parameter is used to find the optimal partition size to minimize the number
+/// of hash iterations. It specifies how many field elements are consumed by each hash iteration.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct PartitionOptions {
num_partitions: u8,
- min_partition_size: u8,
+ hash_rate: u8,
}
impl PartitionOptions {
/// Returns a new instance of `[PartitionOptions]`.
- pub const fn new(num_partitions: usize, min_partition_size: usize) -> Self {
+ pub const fn new(num_partitions: usize, hash_rate: usize) -> Self {
assert!(num_partitions >= 1, "number of partitions must be greater than or eqaul to 1");
assert!(num_partitions <= 16, "number of partitions must be smaller than or equal to 16");
assert!(
- min_partition_size >= 1,
- "smallest partition size must be greater than or equal to 1"
+ hash_rate >= 1,
+ "hash rate must be greater than or equal to 1"
);
assert!(
- min_partition_size <= 256,
- "smallest partition size must be smaller than or equal to 256"
+ hash_rate <= 256,
+ "hash rate must be smaller than or equal to 256"
);
Self {
num_partitions: num_partitions as u8,
- min_partition_size: min_partition_size as u8,
+ hash_rate: hash_rate as u8,
}
}
@@ -379,21 +388,30 @@ impl PartitionOptions {
/// well as the constraint evaluation trace.
/// The returned size is given in terms of number of columns in the field `E`.
pub fn partition_size(&self, num_columns: usize) -> usize {
- if self.num_partitions == 1 && self.min_partition_size == 1 {
+ if self.num_partitions == 1 {
return num_columns;
}
- let base_elements_per_partition = cmp::max(
- (num_columns * E::EXTENSION_DEGREE).div_ceil(self.num_partitions as usize),
- self.min_partition_size as usize,
- );
- base_elements_per_partition.div(E::EXTENSION_DEGREE)
+ // Don't separate columns that would fit inside one hash iteration. min_partition_size is
+ // the number of `E` elements that can be consumed in one hash iteration.
+ let min_partition_size = self.hash_rate as usize / E::EXTENSION_DEGREE;
+
+ cmp::max(
+ num_columns.div_ceil(self.num_partitions as usize),
+ min_partition_size,
+ )
+ }
+
+ /// The actual number of partitions, after the min partition size implied
+ /// by the hash rate is taken into account.
+ pub fn num_partitions(&self, num_columns: usize) -> usize {
+ num_columns.div_ceil(self.partition_size::(num_columns))
}
}
impl Default for PartitionOptions {
fn default() -> Self {
- Self { num_partitions: 1, min_partition_size: 1 }
+ Self { num_partitions: 1, hash_rate: 1 }
}
}
@@ -402,9 +420,9 @@ impl Default for PartitionOptions {
#[cfg(test)]
mod tests {
- use math::fields::f64::BaseElement;
+ use math::fields::{f64::BaseElement, CubeExtension};
- use super::{FieldExtension, ProofOptions, ToElements};
+ use super::{FieldExtension, PartitionOptions, ProofOptions, ToElements};
#[test]
fn proof_options_to_elements() {
@@ -438,4 +456,37 @@ mod tests {
);
assert_eq!(expected, options.to_elements());
}
+
+ #[test]
+ fn correct_partition_sizes() {
+ type E1 = BaseElement;
+ type E3 = CubeExtension;
+
+ let options = PartitionOptions::new(4, 8);
+ let columns = 7;
+ assert_eq!(8, options.partition_size::(columns));
+ assert_eq!(1, options.num_partitions::(columns));
+
+ let options = PartitionOptions::new(4, 8);
+ let columns = 70;
+ assert_eq!(18, options.partition_size::(columns));
+ assert_eq!(4, options.num_partitions::(columns));
+
+ let options = PartitionOptions::new(2, 8);
+ let columns = 7;
+ assert_eq!(4, options.partition_size::(columns));
+ assert_eq!(2, options.num_partitions::(columns));
+
+ let options: PartitionOptions = PartitionOptions::new(4, 8);
+ let columns = 7;
+ assert_eq!(2, options.partition_size::(columns));
+ assert_eq!(4, options.num_partitions::(columns));
+
+ // don't use all partitions if it would result in sizes smaller than
+ // a single hash iteration can handle
+ let options: PartitionOptions = PartitionOptions::new(4, 8);
+ let columns = 3;
+ assert_eq!(2, options.partition_size::(columns));
+ assert_eq!(2, options.num_partitions::(columns));
+ }
}
diff --git a/prover/src/lib.rs b/prover/src/lib.rs
index 1a2e157ea..c72c0c766 100644
--- a/prover/src/lib.rs
+++ b/prover/src/lib.rs
@@ -558,8 +558,7 @@ pub trait Prover {
.in_scope(|| {
let commitment = composed_evaluations.commit_to_rows::(
self.options()
- .partition_options()
- .partition_size::(num_constraint_composition_columns),
+ .partition_options(),
);
ConstraintCommitment::new(composed_evaluations, commitment)
});
diff --git a/prover/src/matrix/row_matrix.rs b/prover/src/matrix/row_matrix.rs
index 6cb9ef60c..ef146643e 100644
--- a/prover/src/matrix/row_matrix.rs
+++ b/prover/src/matrix/row_matrix.rs
@@ -3,6 +3,7 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
+use air::PartitionOptions;
use alloc::vec::Vec;
use crypto::{ElementHasher, VectorCommitment};
@@ -180,13 +181,14 @@ impl RowMatrix {
/// * A vector commitment is computed for the resulting vector using the specified vector
/// commitment scheme.
/// * The resulting vector commitment is returned as the commitment to the entire matrix.
- pub fn commit_to_rows(&self, partition_size: usize) -> V
+ pub fn commit_to_rows(&self, partition_options: PartitionOptions) -> V
where
H: ElementHasher,
V: VectorCommitment,
{
// allocate vector to store row hashes
let mut row_hashes = unsafe { uninit_vector::(self.num_rows()) };
+ let partition_size = partition_options.partition_size::(self.num_cols());
if partition_size == self.num_cols() {
// iterate though matrix rows, hashing each row
@@ -200,17 +202,21 @@ impl RowMatrix {
}
);
} else {
+ let num_partitions = partition_options.num_partitions::(self.num_cols());
+
// iterate though matrix rows, hashing each row
batch_iter_mut!(
&mut row_hashes,
128, // min batch size
|batch: &mut [H::Digest], batch_offset: usize| {
- let mut buffer = vec![H::Digest::default(); partition_size];
+ let mut buffer = vec![H::Digest::default(); num_partitions];
for (i, row_hash) in batch.iter_mut().enumerate() {
self.row(batch_offset + i)
.chunks(partition_size)
.zip(buffer.iter_mut())
- .for_each(|(chunk, buf)| *buf = H::hash_elements(chunk));
+ .for_each(|(chunk, buf)| {
+ *buf = H::hash_elements(chunk);
+ });
*row_hash = H::merge_many(&buffer);
}
}
diff --git a/prover/src/trace/trace_lde/default/mod.rs b/prover/src/trace/trace_lde/default/mod.rs
index 26b5e3916..850ce0d90 100644
--- a/prover/src/trace/trace_lde/default/mod.rs
+++ b/prover/src/trace/trace_lde/default/mod.rs
@@ -43,7 +43,7 @@ pub struct DefaultTraceLde<
aux_segment_oracles: Option,
blowup: usize,
trace_info: TraceInfo,
- partition_option: PartitionOptions,
+ partition_options: PartitionOptions,
_h: PhantomData,
}
@@ -64,16 +64,16 @@ where
trace_info: &TraceInfo,
main_trace: &ColMatrix,
domain: &StarkDomain,
- partition_option: PartitionOptions,
+ partition_options: PartitionOptions,
) -> (Self, TracePolyTable) {
// extend the main execution trace and build a commitment to the extended trace
let (main_segment_lde, main_segment_vector_com, main_segment_polys) =
build_trace_commitment::(
main_trace,
domain,
- partition_option.partition_size::(main_trace.num_cols()),
+ partition_options,
);
-
+
let trace_poly_table = TracePolyTable::new(main_segment_polys);
let trace_lde = DefaultTraceLde {
main_segment_lde,
@@ -82,7 +82,7 @@ where
aux_segment_oracles: None,
blowup: domain.trace_to_lde_blowup(),
trace_info: trace_info.clone(),
- partition_option,
+ partition_options,
_h: PhantomData,
};
@@ -151,9 +151,9 @@ where
build_trace_commitment::(
aux_trace,
domain,
- self.partition_option.partition_size::(aux_trace.num_cols()),
+ self.partition_options,
);
-
+
// check errors
assert!(
usize::from(self.aux_segment_lde.is_some()) < self.trace_info.num_aux_segments(),
@@ -276,7 +276,7 @@ where
fn build_trace_commitment(
trace: &ColMatrix,
domain: &StarkDomain,
- partition_size: usize,
+ partition_options: PartitionOptions,
) -> (RowMatrix, V, ColMatrix)
where
E: FieldElement,
@@ -306,7 +306,7 @@ where
// build trace commitment
let commitment_domain_size = trace_lde.num_rows();
let trace_vector_com = info_span!("compute_execution_trace_commitment", commitment_domain_size)
- .in_scope(|| trace_lde.commit_to_rows::(partition_size));
+ .in_scope(|| trace_lde.commit_to_rows::(partition_options));
assert_eq!(trace_vector_com.domain_len(), commitment_domain_size);
(trace_lde, trace_vector_com, trace_polys)
diff --git a/verifier/src/channel.rs b/verifier/src/channel.rs
index e6c511cd8..1425d86aa 100644
--- a/verifier/src/channel.rs
+++ b/verifier/src/channel.rs
@@ -445,7 +445,9 @@ where
if partition_size == row.len() {
H::hash_elements(row)
} else {
- let mut buffer = vec![H::Digest::default(); partition_size];
+ let num_partitions = row.len().div_ceil(partition_size);
+
+ let mut buffer = vec![H::Digest::default(); num_partitions];
row.chunks(partition_size)
.zip(buffer.iter_mut())
From aafc10d0374b0dac62c199feea1b054ceb1b0e99 Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya
Date: Tue, 19 Nov 2024 14:31:05 -0800
Subject: [PATCH 08/19] increment crate version to v0.10.3
---
CHANGELOG.md | 3 +++
air/Cargo.toml | 4 ++--
prover/Cargo.toml | 4 ++--
verifier/Cargo.toml | 4 ++--
4 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e2984822..74b7aec94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog
+## 0.10.3 (2024-11-19) - `air`, `prover`, and `verifier` crates only
+- Fix partition size calculations in `PartitionOptions` (#341).
+
## 0.10.2 (2024-11-18)
- Implement `core::error::Error` for error types (#341).
diff --git a/air/Cargo.toml b/air/Cargo.toml
index 0a363fd76..4365cd205 100644
--- a/air/Cargo.toml
+++ b/air/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-air"
-version = "0.10.2"
+version = "0.10.3"
description = "AIR components for the Winterfell STARK prover/verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-air/0.10.2"
+documentation = "https://docs.rs/winter-air/0.10.3"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "arithmetization", "air"]
edition = "2021"
diff --git a/prover/Cargo.toml b/prover/Cargo.toml
index c02905ca4..d3d299159 100644
--- a/prover/Cargo.toml
+++ b/prover/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-prover"
-version = "0.10.2"
+version = "0.10.3"
description = "Winterfell STARK prover"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-prover/0.10.2"
+documentation = "https://docs.rs/winter-prover/0.10.3"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "prover"]
edition = "2021"
diff --git a/verifier/Cargo.toml b/verifier/Cargo.toml
index 4acf3d063..0d766a53f 100644
--- a/verifier/Cargo.toml
+++ b/verifier/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winter-verifier"
-version = "0.10.2"
+version = "0.10.3"
description = "Winterfell STARK verifier"
authors = ["winterfell contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winter-verifier/0.10.2"
+documentation = "https://docs.rs/winter-verifier/0.10.3"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "verifier"]
edition = "2021"
From 548d9a557f8b56a3c8d84cf04ccc17997f95feca Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya
Date: Tue, 19 Nov 2024 14:31:24 -0800
Subject: [PATCH 09/19] fix lints
---
air/src/options.rs | 23 +++++++----------------
prover/src/lib.rs | 6 ++----
prover/src/matrix/row_matrix.rs | 4 ++--
prover/src/trace/trace_lde/default/mod.rs | 16 ++++------------
4 files changed, 15 insertions(+), 34 deletions(-)
diff --git a/air/src/options.rs b/air/src/options.rs
index 657a6381d..a043d70db 100644
--- a/air/src/options.rs
+++ b/air/src/options.rs
@@ -346,15 +346,15 @@ impl Deserializable for FieldExtension {
/// Defines the parameters used to calculate partition size when committing to the traces
/// generated during the protocol.
-///
+///
/// Using multiple partitions will change how vector commitments are calculated:
/// - Input matrix columns are split into at most num_partitions partitions
/// - For each matrix row, a hash is calculated for each partition separately
/// - The results are merged together by one more hash iteration
-///
+///
/// This is especially useful when proving with multiple GPU cards where each device holds
/// a subset of data and allows less data reshuffling when generating commitments.
-///
+///
/// Hash_rate parameter is used to find the optimal partition size to minimize the number
/// of hash iterations. It specifies how many field elements are consumed by each hash iteration.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
@@ -366,17 +366,11 @@ pub struct PartitionOptions {
impl PartitionOptions {
/// Returns a new instance of `[PartitionOptions]`.
pub const fn new(num_partitions: usize, hash_rate: usize) -> Self {
- assert!(num_partitions >= 1, "number of partitions must be greater than or eqaul to 1");
+ assert!(num_partitions >= 1, "number of partitions must be greater than or equal to 1");
assert!(num_partitions <= 16, "number of partitions must be smaller than or equal to 16");
- assert!(
- hash_rate >= 1,
- "hash rate must be greater than or equal to 1"
- );
- assert!(
- hash_rate <= 256,
- "hash rate must be smaller than or equal to 256"
- );
+ assert!(hash_rate >= 1, "hash rate must be greater than or equal to 1");
+ assert!(hash_rate <= 256, "hash rate must be smaller than or equal to 256");
Self {
num_partitions: num_partitions as u8,
@@ -396,10 +390,7 @@ impl PartitionOptions {
// the number of `E` elements that can be consumed in one hash iteration.
let min_partition_size = self.hash_rate as usize / E::EXTENSION_DEGREE;
- cmp::max(
- num_columns.div_ceil(self.num_partitions as usize),
- min_partition_size,
- )
+ cmp::max(num_columns.div_ceil(self.num_partitions as usize), min_partition_size)
}
/// The actual number of partitions, after the min partition size implied
diff --git a/prover/src/lib.rs b/prover/src/lib.rs
index c72c0c766..6854ae818 100644
--- a/prover/src/lib.rs
+++ b/prover/src/lib.rs
@@ -556,10 +556,8 @@ pub trait Prover {
log_domain_size = domain_size.ilog2()
)
.in_scope(|| {
- let commitment = composed_evaluations.commit_to_rows::(
- self.options()
- .partition_options(),
- );
+ let commitment = composed_evaluations
+ .commit_to_rows::(self.options().partition_options());
ConstraintCommitment::new(composed_evaluations, commitment)
});
diff --git a/prover/src/matrix/row_matrix.rs b/prover/src/matrix/row_matrix.rs
index ef146643e..91c5c04aa 100644
--- a/prover/src/matrix/row_matrix.rs
+++ b/prover/src/matrix/row_matrix.rs
@@ -3,9 +3,9 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
-use air::PartitionOptions;
use alloc::vec::Vec;
+use air::PartitionOptions;
use crypto::{ElementHasher, VectorCommitment};
use math::{fft, FieldElement, StarkField};
#[cfg(feature = "concurrent")]
@@ -203,7 +203,7 @@ impl RowMatrix {
);
} else {
let num_partitions = partition_options.num_partitions::(self.num_cols());
-
+
// iterate though matrix rows, hashing each row
batch_iter_mut!(
&mut row_hashes,
diff --git a/prover/src/trace/trace_lde/default/mod.rs b/prover/src/trace/trace_lde/default/mod.rs
index 850ce0d90..afc3734a6 100644
--- a/prover/src/trace/trace_lde/default/mod.rs
+++ b/prover/src/trace/trace_lde/default/mod.rs
@@ -68,12 +68,8 @@ where
) -> (Self, TracePolyTable) {
// extend the main execution trace and build a commitment to the extended trace
let (main_segment_lde, main_segment_vector_com, main_segment_polys) =
- build_trace_commitment::(
- main_trace,
- domain,
- partition_options,
- );
-
+ build_trace_commitment::(main_trace, domain, partition_options);
+
let trace_poly_table = TracePolyTable::new(main_segment_polys);
let trace_lde = DefaultTraceLde {
main_segment_lde,
@@ -148,12 +144,8 @@ where
) -> (ColMatrix, H::Digest) {
// extend the auxiliary trace segment and build a commitment to the extended trace
let (aux_segment_lde, aux_segment_oracles, aux_segment_polys) =
- build_trace_commitment::(
- aux_trace,
- domain,
- self.partition_options,
- );
-
+ build_trace_commitment::(aux_trace, domain, self.partition_options);
+
// check errors
assert!(
usize::from(self.aux_segment_lde.is_some()) < self.trace_info.num_aux_segments(),
From 1d3a54ec70519083b6c368099fe5db7b8b84e1e7 Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya
Date: Tue, 19 Nov 2024 14:32:47 -0800
Subject: [PATCH 10/19] increment crate versions v0.10.3
---
winterfell/Cargo.toml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/winterfell/Cargo.toml b/winterfell/Cargo.toml
index 6ade01023..bee4d0bc8 100644
--- a/winterfell/Cargo.toml
+++ b/winterfell/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "winterfell"
-version = "0.10.2"
+version = "0.10.3"
description = "Winterfell STARK prover and verifier"
authors = ["winterfell contributors"]
readme = "../README.md"
license = "MIT"
repository = "https://github.com/novifinancial/winterfell"
-documentation = "https://docs.rs/winterfell/0.10.2"
+documentation = "https://docs.rs/winterfell/0.10.3"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "zkp", "stark", "prover", "verifier"]
edition = "2021"
From ee2089a6c78b2b2d28fd872b85fcf35a8e3a8b18 Mon Sep 17 00:00:00 2001
From: Irakliy Khaburzaniya
Date: Tue, 19 Nov 2024 14:41:00 -0800
Subject: [PATCH 11/19] fix type in changelog
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 74b7aec94..59e740c42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,7 @@
# Changelog
## 0.10.3 (2024-11-19) - `air`, `prover`, and `verifier` crates only
-- Fix partition size calculations in `PartitionOptions` (#341).
+- Fix partition size calculations in `PartitionOptions` (#340).
## 0.10.2 (2024-11-18)
- Implement `core::error::Error` for error types (#341).
From 08be71c20ebf8b5f1696e7ba4dd5c810ef1eb336 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Grzegorz=20=C5=9Awirski?=
Date: Sun, 24 Nov 2024 23:01:40 +0100
Subject: [PATCH 12/19] Make `Prover` generic over the `ConstraintCommitment`
type (#343)
---
README.md | 18 +++
examples/src/fibonacci/fib2/prover.rs | 23 ++-
examples/src/fibonacci/fib8/prover.rs | 23 ++-
examples/src/fibonacci/fib_small/prover.rs | 23 ++-
examples/src/fibonacci/mulfib2/prover.rs | 23 ++-
examples/src/fibonacci/mulfib8/prover.rs | 23 ++-
examples/src/lamport/aggregate/prover.rs | 23 ++-
examples/src/lamport/threshold/prover.rs | 23 ++-
examples/src/merkle/prover.rs | 23 ++-
examples/src/rescue/prover.rs | 23 ++-
examples/src/rescue_raps/prover.rs | 22 ++-
examples/src/vdf/exempt/prover.rs | 23 ++-
examples/src/vdf/regular/prover.rs | 23 ++-
prover/README.md | 1 +
prover/benches/lagrange_kernel.rs | 22 ++-
prover/src/constraints/commitment.rs | 80 ----------
prover/src/constraints/commitment/default.rs | 150 +++++++++++++++++++
prover/src/constraints/commitment/mod.rs | 37 +++++
prover/src/constraints/mod.rs | 2 +-
prover/src/lib.rs | 88 ++++-------
winterfell/src/lib.rs | 54 +++++--
winterfell/src/tests.rs | 18 +++
22 files changed, 559 insertions(+), 186 deletions(-)
delete mode 100644 prover/src/constraints/commitment.rs
create mode 100644 prover/src/constraints/commitment/default.rs
create mode 100644 prover/src/constraints/commitment/mod.rs
diff --git a/README.md b/README.md
index 230146c2b..396cdc5ec 100644
--- a/README.md
+++ b/README.md
@@ -270,6 +270,8 @@ impl Prover for WorkProver {
type TraceLde> = DefaultTraceLde;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, WorkAir, E>;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
// Our public inputs consist of the first and last value in the execution trace.
fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs {
@@ -300,6 +302,22 @@ impl Prover for WorkProver {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+ // We'll use the default constraint commitment.
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
+
fn options(&self) -> &ProofOptions {
&self.options
}
diff --git a/examples/src/fibonacci/fib2/prover.rs b/examples/src/fibonacci/fib2/prover.rs
index 99d48f004..28b0ebf53 100644
--- a/examples/src/fibonacci/fib2/prover.rs
+++ b/examples/src/fibonacci/fib2/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -60,6 +60,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -90,4 +92,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/fibonacci/fib8/prover.rs b/examples/src/fibonacci/fib8/prover.rs
index 64182978c..860eb60df 100644
--- a/examples/src/fibonacci/fib8/prover.rs
+++ b/examples/src/fibonacci/fib8/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -75,6 +75,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -105,4 +107,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/fibonacci/fib_small/prover.rs b/examples/src/fibonacci/fib_small/prover.rs
index 553988064..9d1ced901 100644
--- a/examples/src/fibonacci/fib_small/prover.rs
+++ b/examples/src/fibonacci/fib_small/prover.rs
@@ -3,9 +3,9 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -65,6 +65,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -95,4 +97,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/fibonacci/mulfib2/prover.rs b/examples/src/fibonacci/mulfib2/prover.rs
index 4c99187bf..67aebee70 100644
--- a/examples/src/fibonacci/mulfib2/prover.rs
+++ b/examples/src/fibonacci/mulfib2/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -56,6 +56,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -86,4 +88,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/fibonacci/mulfib8/prover.rs b/examples/src/fibonacci/mulfib8/prover.rs
index 1fb58bd1a..3cf93aed9 100644
--- a/examples/src/fibonacci/mulfib8/prover.rs
+++ b/examples/src/fibonacci/mulfib8/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -68,6 +68,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -98,4 +100,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/lamport/aggregate/prover.rs b/examples/src/lamport/aggregate/prover.rs
index 3927a20e6..983eee3fb 100644
--- a/examples/src/lamport/aggregate/prover.rs
+++ b/examples/src/lamport/aggregate/prover.rs
@@ -6,9 +6,9 @@
#[cfg(feature = "concurrent")]
use winterfell::iterators::*;
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -105,6 +105,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -134,6 +136,21 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
// TRACE INITIALIZATION
diff --git a/examples/src/lamport/threshold/prover.rs b/examples/src/lamport/threshold/prover.rs
index 87bd09bf6..c40f5a9f2 100644
--- a/examples/src/lamport/threshold/prover.rs
+++ b/examples/src/lamport/threshold/prover.rs
@@ -8,9 +8,9 @@ use std::collections::HashMap;
#[cfg(feature = "concurrent")]
use winterfell::iterators::*;
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -147,6 +147,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -176,6 +178,21 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
// TRACE INITIALIZATION
diff --git a/examples/src/merkle/prover.rs b/examples/src/merkle/prover.rs
index b1164ff83..4a86cc90a 100644
--- a/examples/src/merkle/prover.rs
+++ b/examples/src/merkle/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -109,6 +109,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -141,4 +143,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/rescue/prover.rs b/examples/src/rescue/prover.rs
index e8ca93757..98d725eec 100644
--- a/examples/src/rescue/prover.rs
+++ b/examples/src/rescue/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -75,6 +75,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -108,4 +110,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/rescue_raps/prover.rs b/examples/src/rescue_raps/prover.rs
index b8b21b1f3..7b04f98b9 100644
--- a/examples/src/rescue_raps/prover.rs
+++ b/examples/src/rescue_raps/prover.rs
@@ -5,9 +5,9 @@
use core_utils::uninit_vector;
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable,
};
use super::{
@@ -105,6 +105,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -141,6 +143,20 @@ where
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
fn build_aux_trace(
&self,
trace: &Self::Trace,
diff --git a/examples/src/vdf/exempt/prover.rs b/examples/src/vdf/exempt/prover.rs
index 16a7b8169..f39e818d2 100644
--- a/examples/src/vdf/exempt/prover.rs
+++ b/examples/src/vdf/exempt/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -56,6 +56,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -91,4 +93,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/examples/src/vdf/regular/prover.rs b/examples/src/vdf/regular/prover.rs
index 20bdf7874..591dcc839 100644
--- a/examples/src/vdf/regular/prover.rs
+++ b/examples/src/vdf/regular/prover.rs
@@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.
use winterfell::{
- crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
- DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
- TracePolyTable, TraceTable,
+ crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, CompositionPoly, CompositionPolyTrace,
+ ConstraintCompositionCoefficients, DefaultConstraintCommitment, DefaultConstraintEvaluator,
+ DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo, TracePolyTable, TraceTable,
};
use super::{
@@ -53,6 +53,8 @@ where
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, Self::Air, E>;
@@ -86,4 +88,19 @@ where
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
+
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
}
diff --git a/prover/README.md b/prover/README.md
index 9c77a9e59..b95a73c0e 100644
--- a/prover/README.md
+++ b/prover/README.md
@@ -21,6 +21,7 @@ To define a prover for a computation, you'll need implement the `Prover` trait.
* `get_pub_inputs()`, which describes how a set of public inputs can be extracted from a given instance of an execution trace. These inputs will need to be shared with the verifier in order for them to verify the proof.
* `new_trace_lde()`, which constructs a new instance of trace low-degree extension. Unless your prover needs to implement specialized optimizations for performing low-degree extensions, this method can just return a default trace low-degree extension provided by Winterfell.
* `new_evaluator()`, which constructs a new instance of the AIR constraint evaluator. Unless your prover needs to implement specialized optimizations for evaluating constraints, this method can just return a default constraint evaluator provided by Winterfell.
+* `build_constraint_commitment()`, which constructs a new instance of constraint commitment. Unless your prover needs to implement specialized optimizations for committing to constraints, this method can just return a default constraint commitment provided by Winterfell.
* `options()`, which defines STARK protocol parameters to be used during proof generation. These parameters include number of queries, blowup factor, grinding factor, hash function to be used during proof generation etc.. Values of these parameters directly inform such metrics as proof generation time, proof size, and proof security level. See [air crate](../air) for more info.
A prover exposes a `prove()` method which can be used to generate a STARK proof using a given execution trace as a witness.
diff --git a/prover/benches/lagrange_kernel.rs b/prover/benches/lagrange_kernel.rs
index d6ab6a5bc..92bf54f5a 100644
--- a/prover/benches/lagrange_kernel.rs
+++ b/prover/benches/lagrange_kernel.rs
@@ -14,8 +14,9 @@ use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criteri
use crypto::{hashers::Blake3_256, DefaultRandomCoin, MerkleTree, RandomCoin};
use math::{fields::f64::BaseElement, ExtensionOf, FieldElement};
use winter_prover::{
- matrix::ColMatrix, DefaultConstraintEvaluator, DefaultTraceLde, Prover, ProverGkrProof,
- StarkDomain, Trace, TracePolyTable,
+ matrix::ColMatrix, CompositionPoly, CompositionPolyTrace, DefaultConstraintCommitment,
+ DefaultConstraintEvaluator, DefaultTraceLde, Prover, ProverGkrProof, StarkDomain, Trace,
+ TracePolyTable,
};
const TRACE_LENS: [usize; 2] = [2_usize.pow(16), 2_usize.pow(20)];
@@ -187,6 +188,8 @@ impl Prover for LagrangeProver {
type RandomCoin = DefaultRandomCoin;
type TraceLde> =
DefaultTraceLde;
+ type ConstraintCommitment> =
+ DefaultConstraintCommitment;
type ConstraintEvaluator<'a, E: FieldElement> =
DefaultConstraintEvaluator<'a, LagrangeKernelAir, E>;
@@ -210,6 +213,21 @@ impl Prover for LagrangeProver {
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option)
}
+ fn build_constraint_commitment>(
+ &self,
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self::ConstraintCommitment, CompositionPoly) {
+ DefaultConstraintCommitment::new(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ )
+ }
+
fn new_evaluator<'a, E>(
&self,
air: &'a Self::Air,
diff --git a/prover/src/constraints/commitment.rs b/prover/src/constraints/commitment.rs
deleted file mode 100644
index ac71fdc94..000000000
--- a/prover/src/constraints/commitment.rs
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) Facebook, Inc. and its affiliates.
-//
-// This source code is licensed under the MIT license found in the
-// LICENSE file in the root directory of this source tree.
-
-use alloc::vec::Vec;
-use core::marker::PhantomData;
-
-use air::proof::Queries;
-use crypto::{ElementHasher, VectorCommitment};
-use math::FieldElement;
-
-use super::RowMatrix;
-
-// CONSTRAINT COMMITMENT
-// ================================================================================================
-
-/// Constraint evaluation commitment.
-///
-/// The commitment consists of two components:
-/// * Evaluations of composition polynomial columns over the LDE domain.
-/// * Vector commitment where each vector element corresponds to the digest of a row in
-/// the composition polynomial evaluation matrix.
-pub struct ConstraintCommitment<
- E: FieldElement,
- H: ElementHasher,
- V: VectorCommitment,
-> {
- evaluations: RowMatrix,
- vector_commitment: V,
- _h: PhantomData,
-}
-
-impl ConstraintCommitment
-where
- E: FieldElement,
- H: ElementHasher,
- V: VectorCommitment,
-{
- /// Creates a new constraint evaluation commitment from the provided composition polynomial
- /// evaluations and the corresponding vector commitment.
- pub fn new(evaluations: RowMatrix, commitment: V) -> ConstraintCommitment {
- assert_eq!(
- evaluations.num_rows(),
- commitment.domain_len(),
- "number of rows in constraint evaluation matrix must be the same as the size \
- of the vector commitment domain"
- );
-
- ConstraintCommitment {
- evaluations,
- vector_commitment: commitment,
- _h: PhantomData,
- }
- }
-
- /// Returns the commitment.
- pub fn commitment(&self) -> H::Digest {
- self.vector_commitment.commitment()
- }
-
- /// Returns constraint evaluations at the specified positions along with a batch opening proof
- /// against the vector commitment.
- pub fn query(self, positions: &[usize]) -> Queries {
- // build batch opening proof to the leaves specified by positions
- let opening_proof = self
- .vector_commitment
- .open_many(positions)
- .expect("failed to generate a batch opening proof for constraint queries");
-
- // determine a set of evaluations corresponding to each position
- let mut evaluations = Vec::new();
- for &position in positions {
- let row = self.evaluations.row(position).to_vec();
- evaluations.push(row);
- }
-
- Queries::new::(opening_proof.1, evaluations)
- }
-}
diff --git a/prover/src/constraints/commitment/default.rs b/prover/src/constraints/commitment/default.rs
new file mode 100644
index 000000000..629c08cd3
--- /dev/null
+++ b/prover/src/constraints/commitment/default.rs
@@ -0,0 +1,150 @@
+// Copyright (c) Facebook, Inc. and its affiliates.
+//
+// This source code is licensed under the MIT license found in the
+// LICENSE file in the root directory of this source tree.
+
+use alloc::vec::Vec;
+use core::marker::PhantomData;
+
+use air::{proof::Queries, PartitionOptions};
+use crypto::{ElementHasher, VectorCommitment};
+use math::FieldElement;
+use tracing::info_span;
+
+use super::{ConstraintCommitment, RowMatrix};
+use crate::{CompositionPoly, CompositionPolyTrace, StarkDomain, DEFAULT_SEGMENT_WIDTH};
+
+// CONSTRAINT COMMITMENT
+// ================================================================================================
+
+/// Constraint evaluation commitment.
+///
+/// The commitment consists of two components:
+/// * Evaluations of composition polynomial columns over the LDE domain.
+/// * Vector commitment where each vector element corresponds to the digest of a row in
+/// the composition polynomial evaluation matrix.
+pub struct DefaultConstraintCommitment<
+ E: FieldElement,
+ H: ElementHasher,
+ V: VectorCommitment,
+> {
+ evaluations: RowMatrix,
+ vector_commitment: V,
+ _h: PhantomData,
+}
+
+impl DefaultConstraintCommitment
+where
+ E: FieldElement,
+ H: ElementHasher,
+ V: VectorCommitment,
+{
+ /// Creates a new constraint evaluation commitment from the provided composition polynomial
+ /// evaluations and the corresponding vector commitment.
+ pub fn new(
+ composition_poly_trace: CompositionPolyTrace,
+ num_constraint_composition_columns: usize,
+ domain: &StarkDomain,
+ partition_options: PartitionOptions,
+ ) -> (Self, CompositionPoly) {
+ // extend the main execution trace and build a commitment to the extended trace
+ let (evaluations, commitment, composition_poly) = build_constraint_commitment::(
+ composition_poly_trace,
+ num_constraint_composition_columns,
+ domain,
+ partition_options,
+ );
+
+ assert_eq!(
+ evaluations.num_rows(),
+ commitment.domain_len(),
+ "number of rows in constraint evaluation matrix must be the same as the size \
+ of the vector commitment domain"
+ );
+
+ let commitment = Self {
+ evaluations,
+ vector_commitment: commitment,
+ _h: PhantomData,
+ };
+
+ (commitment, composition_poly)
+ }
+}
+
+impl ConstraintCommitment for DefaultConstraintCommitment
+where
+ E: FieldElement,
+ H: ElementHasher + core::marker::Sync,
+ V: VectorCommitment + core::marker::Sync,
+{
+ type HashFn = H;
+ type VC = V;
+
+ /// Returns the commitment.
+ fn commitment(&self) -> H::Digest {
+ self.vector_commitment.commitment()
+ }
+
+ /// Returns constraint evaluations at the specified positions along with a batch opening proof
+ /// against the vector commitment.
+ fn query(self, positions: &[usize]) -> Queries {
+ // build batch opening proof to the leaves specified by positions
+ let opening_proof = self
+ .vector_commitment
+ .open_many(positions)
+ .expect("failed to generate a batch opening proof for constraint queries");
+
+ // determine a set of evaluations corresponding to each position
+ let mut evaluations = Vec::new();
+ for &position in positions {
+ let row = self.evaluations.row(position).to_vec();
+ evaluations.push(row);
+ }
+
+ Queries::new::(opening_proof.1, evaluations)
+ }
+}
+
+fn build_constraint_commitment(
+ composition_poly_trace: CompositionPolyTrace