Skip to content

Commit 6f63aa0

Browse files
Merge branch 'next' into mc/check-blob-overflow-inside-absorb-end-marker
2 parents 296d040 + 2094fd1 commit 6f63aa0

File tree

237 files changed

+774
-1648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+774
-1648
lines changed

.github/workflows/ensure-funded-environments.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ concurrency:
2525

2626
jobs:
2727
fund:
28-
continue-on-error: true
2928
strategy:
3029
# we can only run one funding operation at a time because all jobs fund from the same address
3130
max-parallel: 1

barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ template <class Curve> class CommitmentKey {
106106
};
107107
/**
108108
* @brief Batch commitment to multiple polynomials
109-
* @details Uses batch_multi_scalar_mul for more efficient processing when committing to multiple polynomials
109+
* @details Uses batch_multi_scalar_mul for more efficient processing when committing to multiple polynomials.
110+
* The input polynomials are not const because batch_mul modifies them and then restores them back.
110111
*
111112
* @param polynomials vector of polynomial spans to commit to
112113
* @return std::vector<Commitment> vector of commitments, one for each polynomial

barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace gemini {
7474
* @param num_powers
7575
* @return std::vector<Fr>
7676
*/
77-
template <class Fr> inline std::vector<Fr> powers_of_rho(const Fr rho, const size_t num_powers)
77+
template <class Fr> inline std::vector<Fr> powers_of_rho(const Fr& rho, const size_t num_powers)
7878
{
7979
std::vector<Fr> rhos = { Fr(1), rho };
8080
rhos.reserve(num_powers);
@@ -91,7 +91,7 @@ template <class Fr> inline std::vector<Fr> powers_of_rho(const Fr rho, const siz
9191
* @param num_squares The number of foldings
9292
* @return std::vector<typename Curve::ScalarField>
9393
*/
94-
template <class Fr> inline std::vector<Fr> powers_of_evaluation_challenge(const Fr r, const size_t num_squares)
94+
template <class Fr> inline std::vector<Fr> powers_of_evaluation_challenge(const Fr& r, const size_t num_squares)
9595
{
9696
std::vector<Fr> squares = { r };
9797
squares.reserve(num_squares);
@@ -301,7 +301,7 @@ template <typename Curve> class GeminiProver_ {
301301
const Fr& r_challenge);
302302

303303
template <typename Transcript>
304-
static std::vector<Claim> prove(const Fr circuit_size,
304+
static std::vector<Claim> prove(size_t circuit_size,
305305
PolynomialBatcher& polynomial_batcher,
306306
std::span<Fr> multilinear_challenge,
307307
const CommitmentKey<Curve>& commitment_key,

barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace bb {
4848
template <typename Curve>
4949
template <typename Transcript>
5050
std::vector<typename GeminiProver_<Curve>::Claim> GeminiProver_<Curve>::prove(
51-
Fr circuit_size,
51+
size_t circuit_size,
5252
PolynomialBatcher& polynomial_batcher,
5353
std::span<Fr> multilinear_challenge,
5454
const CommitmentKey<Curve>& commitment_key,
@@ -57,7 +57,7 @@ std::vector<typename GeminiProver_<Curve>::Claim> GeminiProver_<Curve>::prove(
5757
{
5858
// To achieve fixed proof size in Ultra and Mega, the multilinear opening challenge is be padded to a fixed size.
5959
const size_t virtual_log_n = multilinear_challenge.size();
60-
const size_t log_n = numeric::get_msb(static_cast<uint32_t>(circuit_size));
60+
const size_t log_n = numeric::get_msb(circuit_size);
6161

6262
// Get the batching challenge
6363
const Fr rho = transcript->template get_challenge<Fr>("rho");

barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplemini.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template <typename Curve> class ShpleminiProver_ {
3333
using PolynomialBatcher = GeminiProver::PolynomialBatcher;
3434

3535
template <typename Transcript>
36-
static OpeningClaim prove(const FF circuit_size,
36+
static OpeningClaim prove(size_t circuit_size,
3737
PolynomialBatcher& polynomial_batcher,
3838
std::span<FF> multilinear_challenge,
3939
const CommitmentKey<Curve>& commitment_key,
@@ -110,15 +110,15 @@ template <typename Curve> class ShpleminiProver_ {
110110
*
111111
*/
112112
static std::vector<OpeningClaim> compute_sumcheck_round_claims(
113-
const FF circuit_size,
113+
size_t circuit_size,
114114
std::span<FF> multilinear_challenge,
115115
const std::vector<Polynomial>& sumcheck_round_univariates,
116116
const std::vector<std::array<FF, 3>>& sumcheck_round_evaluations)
117117
{
118118
OpeningClaim new_claim;
119119
std::vector<OpeningClaim> sumcheck_round_claims = {};
120120

121-
const size_t log_n = numeric::get_msb(static_cast<uint32_t>(circuit_size));
121+
const size_t log_n = numeric::get_msb(circuit_size);
122122
for (size_t idx = 0; idx < log_n; idx++) {
123123
const std::vector<FF> evaluation_points = { FF(0), FF(1), multilinear_challenge[idx] };
124124
size_t eval_idx = 0;
@@ -135,6 +135,7 @@ template <typename Curve> class ShpleminiProver_ {
135135
return sumcheck_round_claims;
136136
}
137137
};
138+
138139
/**
139140
* \brief An efficient verifier for the evaluation proofs of multilinear polynomials and their shifts.
140141
*

barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ void MSM<Curve>::consume_point_schedule(std::span<const uint64_t> point_schedule
749749
* This is because this method will be able to dispatch equal work to all threads without splitting the input
750750
* msms up so much.
751751
* The Pippenger algorithm runtime is O(N/log(N)) so there will be slight gains as each inner-thread MSM will
752-
* have a larger N
752+
* have a larger N.
753+
* The input scalars are not const because the algorithm converts them out of Montgomery form and then back.
753754
*
754755
* @tparam Curve
755756
* @param points

barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ template <typename Fr> Polynomial<Fr>& Polynomial<Fr>::operator-=(PolynomialSpan
221221
return *this;
222222
}
223223

224-
template <typename Fr> Polynomial<Fr>& Polynomial<Fr>::operator*=(const Fr scaling_factor)
224+
template <typename Fr> Polynomial<Fr>& Polynomial<Fr>::operator*=(const Fr& scaling_factor)
225225
{
226226
parallel_for([scaling_factor, this](const ThreadChunk& chunk) { multiply_chunk(chunk, scaling_factor); });
227227
return *this;
228228
}
229229

230-
template <typename Fr> void Polynomial<Fr>::multiply_chunk(const ThreadChunk& chunk, const Fr scaling_factor)
230+
template <typename Fr> void Polynomial<Fr>::multiply_chunk(const ThreadChunk& chunk, const Fr& scaling_factor)
231231
{
232232
for (size_t i : chunk.range(size())) {
233233
data()[i] *= scaling_factor;
@@ -255,7 +255,7 @@ template <typename Fr> Polynomial<Fr> Polynomial<Fr>::full() const
255255
return result;
256256
}
257257

258-
template <typename Fr> void Polynomial<Fr>::add_scaled(PolynomialSpan<const Fr> other, Fr scaling_factor) &
258+
template <typename Fr> void Polynomial<Fr>::add_scaled(PolynomialSpan<const Fr> other, const Fr& scaling_factor)
259259
{
260260
BB_ASSERT_LTE(start_index(), other.start_index);
261261
BB_ASSERT_GTE(end_index(), other.end_index());
@@ -264,7 +264,9 @@ template <typename Fr> void Polynomial<Fr>::add_scaled(PolynomialSpan<const Fr>
264264
}
265265

266266
template <typename Fr>
267-
void Polynomial<Fr>::add_scaled_chunk(const ThreadChunk& chunk, PolynomialSpan<const Fr> other, Fr scaling_factor) &
267+
void Polynomial<Fr>::add_scaled_chunk(const ThreadChunk& chunk,
268+
PolynomialSpan<const Fr> other,
269+
const Fr& scaling_factor)
268270
{
269271
// Iterate over the chunk of the other polynomial's range
270272
for (size_t offset : chunk.range(other.size())) {

barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ template <typename Fr> class Polynomial {
232232
* @param other q(X)
233233
* @param scaling_factor scaling factor by which all coefficients of q(X) are multiplied
234234
*/
235-
void add_scaled(PolynomialSpan<const Fr> other, Fr scaling_factor) &;
235+
void add_scaled(PolynomialSpan<const Fr> other, const Fr& scaling_factor);
236236

237-
void add_scaled_chunk(const ThreadChunk& chunk, PolynomialSpan<const Fr> other, Fr scaling_factor) &;
237+
void add_scaled_chunk(const ThreadChunk& chunk, PolynomialSpan<const Fr> other, const Fr& scaling_factor);
238238

239239
/**
240240
* @brief adds the polynomial q(X) 'other'.
@@ -255,9 +255,9 @@ template <typename Fr> class Polynomial {
255255
*
256256
* @param scaling_factor s
257257
*/
258-
Polynomial& operator*=(Fr scaling_factor);
258+
Polynomial& operator*=(const Fr& scaling_factor);
259259

260-
void multiply_chunk(const ThreadChunk& chunk, Fr scaling_factor);
260+
void multiply_chunk(const ThreadChunk& chunk, const Fr& scaling_factor);
261261

262262
/**
263263
* @brief Add random values to the coefficients of a polynomial. In practice, this is used for ensuring the

barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST(AvmFixedVKTests, FixedVKCommitments)
2222
auto polynomials = compute_polynomials(trace);
2323
auto proving_key = proving_key_from_polynomials(polynomials);
2424

25-
AvmVerifier::VerificationKey vk_computed(proving_key);
25+
auto vk_computed = AvmVerifier::VerificationKey::from_proving_key(*proving_key);
2626
auto vk_computed_commitments = vk_computed.get_all();
2727

2828
// Get the fixed VK commitments

barretenberg/cpp/src/barretenberg/vm2/constraining/flavor.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,23 @@ class AvmFlavor {
233233

234234
VerificationKey() = default;
235235

236-
VerificationKey(const std::shared_ptr<ProvingKey>& proving_key)
236+
VerificationKey(std::array<Commitment, NUM_PRECOMPUTED_COMMITMENTS> const& precomputed_cmts)
237237
{
238238
this->log_circuit_size = MAX_AVM_TRACE_LOG_SIZE;
239-
for (auto [polynomial, commitment] : zip_view(proving_key->get_precomputed(), this->get_all())) {
240-
commitment = proving_key->commitment_key.commit(polynomial);
239+
for (auto [vk_cmt, cmt] : zip_view(this->get_all(), precomputed_cmts)) {
240+
vk_cmt = cmt;
241241
}
242242
}
243243

244-
VerificationKey(std::array<Commitment, NUM_PRECOMPUTED_COMMITMENTS> const& precomputed_cmts)
244+
// NOTE: This should not be used in production. You should use the fixed VK instead.
245+
static VerificationKey from_proving_key(const ProvingKey& proving_key)
245246
{
246-
this->log_circuit_size = MAX_AVM_TRACE_LOG_SIZE;
247-
for (auto [vk_cmt, cmt] : zip_view(this->get_all(), precomputed_cmts)) {
248-
vk_cmt = cmt;
247+
VerificationKey vk;
248+
vk.log_circuit_size = MAX_AVM_TRACE_LOG_SIZE;
249+
for (auto [polynomial, commitment] : zip_view(proving_key.get_precomputed(), vk.get_all())) {
250+
commitment = proving_key.commitment_key.commit(polynomial);
249251
}
252+
return vk;
250253
}
251254

252255
/**

0 commit comments

Comments
 (0)