Skip to content

Commit f96c1eb

Browse files
authored
fix: Convert folding recursive verifier ops to batch mul (AztecProtocol#4517)
Updates folding recursive verifier to use batch_mul for optimal goblin ec op efficiency. This reduces a single recursive verification from 1144 ECC ops to 264. (Note: 264 = 6*44 where 6 is the number of ecc op gate rows needed for two scalar muls (one for each instance) plus an "equals" op and 44 is the number of witnesses plus precomputed polys, not including shifts) Closes AztecProtocol/barretenberg#849 New benchmark result: ``` ----------------------------------------------------------------- Benchmark Time CPU Iterations ----------------------------------------------------------------- IvcBench/Full/6 54156 ms 51691 ms 1 ``` Old benchmark result: ``` ----------------------------------------------------------------- Benchmark Time CPU Iterations ----------------------------------------------------------------- IvcBench/Full/6 66891 ms 63569 ms 1 ```
1 parent 5f19452 commit f96c1eb

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ template <class VerifierInstances>
188188
void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(const HonkProof& proof)
189189
{
190190
using Transcript = typename Flavor::Transcript;
191-
using ElementNative = typename Flavor::Curve::ElementNative;
192-
using AffineElementNative = typename Flavor::Curve::AffineElementNative;
193191
using ScalarNative = typename Flavor::Curve::ScalarFieldNative;
194192

195193
transcript = std::make_shared<Transcript>(builder, proof);
@@ -244,18 +242,19 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(cons
244242
WitnessCommitments acc_witness_commitments;
245243
auto witness_labels = commitment_labels.get_witness();
246244
size_t comm_idx = 0;
247-
auto random_generator = Commitment::from_witness(builder, AffineElementNative(ElementNative::random_element()));
248245
for (auto& expected_comm : acc_witness_commitments.get_all()) {
249-
expected_comm = random_generator;
246+
std::vector<FF> scalars;
247+
std::vector<Commitment> commitments;
250248
size_t inst = 0;
251249
for (auto& instance : instances) {
252-
expected_comm = expected_comm + instance->witness_commitments.get_all()[comm_idx] * lagranges[inst];
250+
scalars.emplace_back(lagranges[inst]);
251+
commitments.emplace_back(instance->witness_commitments.get_all()[comm_idx]);
253252
inst++;
254253
}
254+
expected_comm = Commitment::batch_mul(commitments, scalars);
255255
auto comm = transcript->template receive_from_prover<Commitment>("next_" + witness_labels[comm_idx]);
256-
auto res = expected_comm - comm;
257-
random_generator.x.assert_equal(res.x);
258-
random_generator.y.assert_equal(res.y);
256+
comm.x.assert_equal(expected_comm.x);
257+
comm.y.assert_equal(expected_comm.y);
259258
comm_idx++;
260259
}
261260

@@ -321,15 +320,17 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(cons
321320
size_t vk_idx = 0;
322321
for (auto& expected_vk : acc_vk->get_all()) {
323322
size_t inst = 0;
324-
expected_vk = random_generator;
323+
std::vector<FF> scalars;
324+
std::vector<Commitment> commitments;
325325
for (auto& instance : instances) {
326-
expected_vk = expected_vk + instance->verification_key->get_all()[vk_idx] * lagranges[inst];
326+
scalars.emplace_back(lagranges[inst]);
327+
commitments.emplace_back(instance->verification_key->get_all()[vk_idx]);
327328
inst++;
328329
}
330+
expected_vk = Commitment::batch_mul(commitments, scalars);
329331
auto vk = transcript->template receive_from_prover<Commitment>("next_" + vk_labels[vk_idx]);
330-
auto res = expected_vk - vk;
331-
random_generator.x.assert_equal(res.x);
332-
random_generator.y.assert_equal(res.y);
332+
vk.x.assert_equal(expected_vk.x);
333+
vk.y.assert_equal(expected_vk.y);
333334
vk_idx++;
334335
}
335336
}

0 commit comments

Comments
 (0)