Skip to content

Commit

Permalink
Fold alphas [no-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Sep 11, 2024
1 parent ff36976 commit e480a58
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@ static Commitment batch_mul_native(const std::vector<Commitment>& _points, const
}
return result;
}

/**
* @brief Utility for native batch multiplication of group elements
* @note This is used only for native verification and is not optimized for efficiency
*/
template <typename FF> static FF linear_combination(const std::vector<FF>& as, const std::vector<FF>& bs)
{
FF result = as[0] * bs[0];
for (size_t idx = 1; idx < as.size(); ++idx) {
result += as[idx] * bs[idx];
}
return result;
}

} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,22 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyVerifier
update_gate_challenges(perturbator_challenge, accumulator->gate_challenges, deltas);

// // Fold the commitments
size_t commitment_idx = 0;
idx = 0;
for (auto& folded_commitment : next_accumulator->verification_key->get_all()) {
folded_commitment =
batch_mul_native(keys_to_fold.get_precomputed_commitments_at_index(commitment_idx), lagranges);
commitment_idx++;
folded_commitment = batch_mul_native(keys_to_fold.get_precomputed_commitments_at_index(idx), lagranges);
idx++;
}
commitment_idx = 0;
idx = 0;
for (auto& folded_commitment : next_accumulator->witness_commitments.get_all()) {
folded_commitment = batch_mul_native(keys_to_fold.get_witness_commitments_at_index(commitment_idx), lagranges);
commitment_idx++;
folded_commitment = batch_mul_native(keys_to_fold.get_witness_commitments_at_index(idx), lagranges);
idx++;
}

// Fold the relation parameters
size_t alpha_idx = 0;
idx = 0;
for (auto& alpha : next_accumulator->alphas) {
alpha = FF(0);
size_t vk_idx = 0;
for (auto& key : keys_to_fold) {
alpha += key->alphas[alpha_idx] * lagranges[vk_idx];
vk_idx++;
}
alpha_idx++;
alpha = linear_combination(keys_to_fold.get_alphas_at_index(idx), lagranges);
idx++;
}
auto& expected_parameters = next_accumulator->relation_parameters;
for (size_t vk_idx = 0; vk_idx < NUM_KEYS; vk_idx++) {
Expand Down
15 changes: 15 additions & 0 deletions barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ template <typename Flavor_, size_t NUM_ = 2> struct DeciderProvingKeys_ {
template <typename Flavor_, size_t NUM_ = 2> struct DeciderVerificationKeys_ {
static_assert(NUM_ > 1, "Must have at least two decider verification keys.");
using Flavor = Flavor_;
using FF = typename Flavor_::FF;
using Commitment = typename Flavor_::Commitment;
using VerificationKey = typename Flavor::VerificationKey;
using DeciderVK = DeciderVerificationKey_<Flavor>;
Expand Down Expand Up @@ -141,5 +142,19 @@ template <typename Flavor_, size_t NUM_ = 2> struct DeciderVerificationKeys_ {

return result;
}

/**
* @brief Get the witness commitments at a given index
* @details This is similar to get_precomputed_commitments_at_index, but for witness commitments.
*/
std::vector<FF> get_alphas_at_index(const size_t idx) const
{
std::vector<FF> result(NUM);
for (auto [elt, key] : zip_view(result, _data)) {
elt = key->alphas[idx];
}

return result;
}
};
} // namespace bb

0 comments on commit e480a58

Please sign in to comment.