Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ template <typename Curve> class ShpleminiVerifier_ {
* number of scalar multiplications required during the verification.
*
* More specifically, the Shplemini verifier receives two or three groups of commitments: get_unshifted() and
* get_to_be_shifted() in the case of Ultra, Mega, and ECCVM Flavors; and get_unshifted_without_concatenated(),
* get_to_be_shifted(), and get_groups_to_be_concatenated() in the case of the TranslatorFlavor. The commitments are
* get_to_be_shifted() in the case of Ultra, Mega, and ECCVM Flavors; and get_unshifted_without_interleaved(),
* get_to_be_shifted(), and get_groups_to_be_interleaved() in the case of the TranslatorFlavor. The commitments are
* then placed in this specific order in a BatchOpeningClaim object containing a vector of commitments and a vector
* of scalars. The ranges with repeated commitments belong to the Flavors. This method iterates over these ranges
* and sums the scalar multipliers corresponding to the same group element. After combining the scalars, we erase
Expand Down Expand Up @@ -834,4 +834,4 @@ template <typename Curve> class ShpleminiVerifier_ {
}
};
};
} // namespace bb
} // namespace bb
19 changes: 17 additions & 2 deletions barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "barretenberg/common/mem.hpp"
#include "barretenberg/common/op_count.hpp"
#include "barretenberg/common/zip_view.hpp"
#include "barretenberg/constants.hpp"
#include "barretenberg/crypto/sha256/sha256.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "barretenberg/plonk_honk_shared/types/circuit_type.hpp"
Expand Down Expand Up @@ -255,6 +256,21 @@ template <typename Fr> class Polynomial {
*/
Polynomial& operator*=(Fr scaling_factor);

/**
* @brief Add random values to the coefficients of a polynomial. In practice, this is used for ensuring the
* commitment and evaluation of a polynomial don't leak information about the coefficients in the context of zero
* knowledge.
*/
void mask()
{
// Ensure there is sufficient space to add masking and also that we have memory allocated up to the virtual_size
ASSERT(virtual_size() >= MASKING_OFFSET);
ASSERT(virtual_size() == end_index());
for (size_t i = virtual_size() - 1; i <= virtual_size() - MASKING_OFFSET; i--) {
at(i) = FF::random_element();
}
}

std::size_t size() const { return coefficients_.size(); }
std::size_t virtual_size() const { return coefficients_.virtual_size(); }
void increase_virtual_size(const size_t size_in) { coefficients_.increase_virtual_size(size_in); };
Expand Down Expand Up @@ -400,7 +416,6 @@ template <typename Fr> class Polynomial {
// Namely, it supports polynomial shifts and 'virtual' zeroes past a size up until a 'virtual' size.
SharedShiftedVirtualZeroesArray<Fr> coefficients_;
};

// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays)
template <typename Fr> std::shared_ptr<Fr[]> _allocate_aligned_memory(size_t n_elements)
{
Expand Down Expand Up @@ -514,4 +529,4 @@ template <typename Poly, typename... Polys> auto zip_polys(Poly&& poly, Polys&&.
ASSERT((poly.start_index() == polys.start_index() && poly.end_index() == polys.end_index()) && ...);
return zip_view(poly.indices(), poly.coeffs(), polys.coeffs()...);
}
} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ void TranslatorProver::execute_preamble_round()
transcript->send_to_verifier("accumulated_result", accumulated_result);
}

/**
* @brief Utility to commit to witness polynomial and send the commitment to verifier.
*
* @param polynomial
* @param label
*/
void TranslatorProver::commit_to_witness_polynomial(Polynomial& polynomial, const std::string& label)
{
transcript->send_to_verifier(label, key->proving_key->commitment_key->commit(polynomial));
}

/**
* @brief Compute commitments to wires and ordered range constraints.
*
Expand All @@ -48,13 +59,13 @@ void TranslatorProver::execute_wire_and_sorted_constraints_commitments_round()
for (const auto& [wire, label] :
zip_view(key->proving_key->polynomials.get_wires(), commitment_labels.get_wires())) {

transcript->send_to_verifier(label, key->proving_key->commitment_key->commit(wire));
commit_to_witness_polynomial(wire, label);
}

// The ordered range constraints are of full circuit size.
for (const auto& [ordered_range_constraint, label] : zip_view(
key->proving_key->polynomials.get_ordered_constraints(), commitment_labels.get_ordered_constraints())) {
transcript->send_to_verifier(label, key->proving_key->commitment_key->commit(ordered_range_constraint));
commit_to_witness_polynomial(ordered_range_constraint, label);
}
}

Expand Down Expand Up @@ -105,8 +116,7 @@ void TranslatorProver::execute_grand_product_computation_round()
// Compute constraint permutation grand product
compute_grand_products<Flavor>(key->proving_key->polynomials, relation_parameters);

transcript->send_to_verifier(commitment_labels.z_perm,
key->proving_key->commitment_key->commit(key->proving_key->polynomials.z_perm));
commit_to_witness_polynomial(key->proving_key->polynomials.z_perm, commitment_labels.z_perm);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TranslatorProver {
BB_PROFILE void execute_grand_product_computation_round();
BB_PROFILE void execute_relation_check_rounds();
BB_PROFILE void execute_pcs_rounds();
void commit_to_witness_polynomial(Polynomial& polynomial, const std::string& label);
HonkProof export_proof();
HonkProof construct_proof();

Expand Down
16 changes: 2 additions & 14 deletions barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,6 @@ template <IsUltraFlavor Flavor> typename Flavor::RelationSeparator OinkProver<Fl
return alphas;
}

/**
* @brief We mask the commitment to a witness, its evaluation at the Sumcheck challenge and, if needed, the
* evaluation of its shift.
*/
template <IsUltraFlavor Flavor> void OinkProver<Flavor>::mask_witness_polynomial(Polynomial<FF>& polynomial)
{
const size_t circuit_size = polynomial.virtual_size();
for (size_t idx = 1; idx < MASKING_OFFSET; idx++) {
polynomial.at(circuit_size - idx) = FF::random_element();
}
}

/**
* @brief A uniform method to mask, commit, and send the corresponding commitment to the verifier.
*
Expand All @@ -259,9 +247,9 @@ void OinkProver<Flavor>::commit_to_witness_polynomial(Polynomial<FF>& polynomial
const std::string& label,
const CommitmentKey::CommitType type)
{
// Mask if needed
// Mask the polynomial when proving in zero-knowledge
if constexpr (Flavor::HasZK) {
mask_witness_polynomial(polynomial);
polynomial.mask();
};

typename Flavor::Commitment commitment;
Expand Down
3 changes: 1 addition & 2 deletions barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ template <IsUltraFlavor Flavor> class OinkProver {
void execute_log_derivative_inverse_round();
void execute_grand_product_computation_round();
RelationSeparator generate_alphas_round();
void mask_witness_polynomial(Polynomial<FF>& polynomial);
void commit_to_witness_polynomial(Polynomial<FF>& polynomial,
const std::string& label,
const CommitmentKey::CommitType type = CommitmentKey::CommitType::Default);
};

using MegaOinkProver = OinkProver<MegaFlavor>;

} // namespace bb
} // namespace bb