Skip to content

Commit cfc0c6e

Browse files
authored
feat: merge-train/barretenberg (#16392)
See [merge-train-readme.md](https://github.com/AztecProtocol/aztec-packages/blob/next/.github/workflows/merge-train-readme.md). This is a merge-train.
2 parents a7e30e7 + fefc36d commit cfc0c6e

18 files changed

Lines changed: 56 additions & 76 deletions

barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,8 @@ class ECCVMFlavor {
841841
* @param transcript
842842
* @returns The hash of the verification key
843843
*/
844-
fr add_hash_to_transcript([[maybe_unused]] const std::string& domain_separator,
845-
[[maybe_unused]] Transcript& transcript) const override
844+
fr hash_through_transcript([[maybe_unused]] const std::string& domain_separator,
845+
[[maybe_unused]] Transcript& transcript) const override
846846
{
847847
throw_or_abort("Not intended to be used because vk is hardcoded in circuit.");
848848
}

barretenberg/cpp/src/barretenberg/flavor/flavor.hpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class NativeVerificationKey_ : public PrecomputedCommitments {
205205
}
206206

207207
/**
208-
* @brief Adds the verification key hash to the transcript and returns the hash.
208+
* @brief Hashes the vk using the transcript's independent buffer and returns the hash.
209209
* @details Needed to make sure the Origin Tag system works. We need to set the origin tags of the VK witnesses in
210210
* the transcript. If we instead did the hashing outside of the transcript and submitted just the hash, only the
211211
* origin tag of the hash would be set properly. We want to avoid backpropagating origin tags to the actual VK
@@ -216,7 +216,8 @@ class NativeVerificationKey_ : public PrecomputedCommitments {
216216
* @param transcript
217217
* @returns The hash of the verification key
218218
*/
219-
virtual fr add_hash_to_transcript(const std::string& domain_separator, Transcript& transcript) const
219+
virtual typename Transcript::DataType hash_through_transcript(const std::string& domain_separator,
220+
Transcript& transcript) const
220221
{
221222
transcript.add_to_independent_hash_buffer(domain_separator + "vk_log_circuit_size", this->log_circuit_size);
222223
transcript.add_to_independent_hash_buffer(domain_separator + "vk_num_public_inputs", this->num_public_inputs);
@@ -226,10 +227,8 @@ class NativeVerificationKey_ : public PrecomputedCommitments {
226227
transcript.add_to_independent_hash_buffer(domain_separator + "vk_commitment", commitment);
227228
}
228229

229-
fr vk_hash = transcript.hash_independent_buffer();
230-
transcript.add_to_hash_buffer(domain_separator + "vk_hash", vk_hash);
231-
return vk_hash;
232-
};
230+
return transcript.hash_independent_buffer();
231+
}
233232
};
234233

235234
/**
@@ -299,7 +298,7 @@ class StdlibVerificationKey_ : public PrecomputedCommitments {
299298
}
300299

301300
/**
302-
* @brief Adds the verification key hash to the transcript and returns the hash.
301+
* @brief Hashes the vk using the transcript's independent buffer and returns the hash.
303302
* @details Needed to make sure the Origin Tag system works. We need to set the origin tags of the VK witnesses in
304303
* the transcript. If we instead did the hashing outside of the transcript and submitted just the hash, only the
305304
* origin tag of the hash would be set properly. We want to avoid backpropagating origin tags to the actual VK
@@ -310,18 +309,16 @@ class StdlibVerificationKey_ : public PrecomputedCommitments {
310309
* @param transcript
311310
* @returns The hash of the verification key
312311
*/
313-
virtual FF add_hash_to_transcript(const std::string& domain_separator, Transcript& transcript) const
312+
virtual FF hash_through_transcript(const std::string& domain_separator, Transcript& transcript) const
314313
{
315314
transcript.add_to_independent_hash_buffer(domain_separator + "vk_log_circuit_size", this->log_circuit_size);
316315
transcript.add_to_independent_hash_buffer(domain_separator + "vk_num_public_inputs", this->num_public_inputs);
317316
transcript.add_to_independent_hash_buffer(domain_separator + "vk_pub_inputs_offset", this->pub_inputs_offset);
318317
for (const Commitment& commitment : this->get_all()) {
319318
transcript.add_to_independent_hash_buffer(domain_separator + "vk_commitment", commitment);
320319
}
321-
FF vk_hash = transcript.hash_independent_buffer();
322-
transcript.add_to_hash_buffer(domain_separator + "vk_hash", vk_hash);
323-
return vk_hash;
324-
};
320+
return transcript.hash_independent_buffer();
321+
}
325322
};
326323

327324
template <typename FF, typename VerificationKey> class VKAndHash_ {

barretenberg/cpp/src/barretenberg/flavor/native_verification_key.test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TYPED_TEST_SUITE(NativeVerificationKeyTests, FlavorTypes);
6161

6262
/**
6363
* @brief Checks that the hash produced from calling to_field_elements and then add_to_independent_hash_buffer is the
64-
* same as the hash() call and also the same as the add_hash_to_transcript.
64+
* same as the hash() call and also the same as the hash_through_transcript.
6565
*
6666
*/
6767
TYPED_TEST(NativeVerificationKeyTests, VKHashingConsistency)
@@ -79,15 +79,15 @@ TYPED_TEST(NativeVerificationKeyTests, VKHashingConsistency)
7979
for (const auto& field_element : vk_field_elements) {
8080
transcript.add_to_independent_hash_buffer("vk_element", field_element);
8181
}
82-
fr vkey_hash_1 = transcript.hash_independent_buffer();
82+
fr vk_hash_1 = transcript.hash_independent_buffer();
8383
// Second method of hashing: using hash().
84-
fr vkey_hash_2 = vk.hash();
85-
EXPECT_EQ(vkey_hash_1, vkey_hash_2);
84+
fr vk_hash_2 = vk.hash();
85+
EXPECT_EQ(vk_hash_1, vk_hash_2);
8686
if constexpr (!IsAnyOf<Flavor, ECCVMFlavor, TranslatorFlavor>) {
87-
// Third method of hashing: using add_hash_to_transcript.
87+
// Third method of hashing: using hash_through_transcript.
8888
typename Flavor::Transcript transcript_2;
89-
fr vkey_hash_3 = vk.add_hash_to_transcript("", transcript_2);
90-
EXPECT_EQ(vkey_hash_2, vkey_hash_3);
89+
fr vk_hash_3 = vk.hash_through_transcript("", transcript_2);
90+
EXPECT_EQ(vk_hash_2, vk_hash_3);
9191
}
9292
}
9393

barretenberg/cpp/src/barretenberg/flavor/stdlib_verification_key.test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ TYPED_TEST_SUITE(StdlibVerificationKeyTests, FlavorTypes);
4141

4242
/**
4343
* @brief Checks that the hash produced from calling to_field_elements and then add_to_independent_hash_buffer is the
44-
* same as the hash() call and also the same as the add_hash_to_transcript.
44+
* same as the hash() call and also the same as the hash_through_transcript.
4545
*
4646
*/
4747
TYPED_TEST(StdlibVerificationKeyTests, VKHashingConsistency)
@@ -77,14 +77,14 @@ TYPED_TEST(StdlibVerificationKeyTests, VKHashingConsistency)
7777
for (const auto& field_element : vk_field_elements) {
7878
transcript.add_to_independent_hash_buffer("vk_element", field_element);
7979
}
80-
FF vkey_hash_1 = transcript.hash_independent_buffer();
80+
FF vk_hash_1 = transcript.hash_independent_buffer();
8181
// Second method of hashing: using hash().
82-
FF vkey_hash_2 = vk.hash(outer_builder);
83-
EXPECT_EQ(vkey_hash_1.get_value(), vkey_hash_2.get_value());
84-
// Third method of hashing: using add_hash_to_transcript.
82+
FF vk_hash_2 = vk.hash(outer_builder);
83+
EXPECT_EQ(vk_hash_1.get_value(), vk_hash_2.get_value());
84+
// Third method of hashing: using hash_through_transcript.
8585
if constexpr (!IsAnyOf<Flavor, TranslatorRecursiveFlavor, ECCVMRecursiveFlavor>) {
8686
StdlibTranscript transcript_2;
87-
FF vkey_hash_3 = vk.add_hash_to_transcript("", transcript_2);
88-
EXPECT_EQ(vkey_hash_2.get_value(), vkey_hash_3.get_value());
87+
FF vk_hash_3 = vk.hash_through_transcript("", transcript_2);
88+
EXPECT_EQ(vk_hash_2.get_value(), vk_hash_3.get_value());
8989
}
9090
}

barretenberg/cpp/src/barretenberg/flavor/ultra_keccak_flavor.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,6 @@ class UltraKeccakFlavor : public bb::UltraFlavor {
9393
}
9494
}
9595

96-
/**
97-
* @brief Adds the verification key witnesses directly to the transcript.
98-
* @details Needed to make sure the Origin Tag system works. See the base class function for
99-
* more details.
100-
*
101-
* @param domain_separator
102-
* @param transcript
103-
*
104-
* @returns The hash of the verification key
105-
*/
106-
fr add_hash_to_transcript(const std::string& domain_separator, Transcript& transcript) const override
107-
{
108-
// This hash contains a hash of the entire vk - including all of the elements
109-
const fr hash = this->hash();
110-
111-
transcript.add_to_hash_buffer(domain_separator + "vk_hash", hash);
112-
return hash;
113-
}
114-
11596
// Don't statically check for object completeness.
11697
using MSGPACK_NO_STATIC_CHECK = std::true_type;
11798

barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void ProtogalaxyProver_<Flavor, NUM_KEYS>::run_oink_prover_on_each_incomplete_ke
3737
run_oink_prover_on_one_incomplete_key(key, verifier_accum, domain_separator);
3838
} else {
3939
// Fiat-Shamir the verifier accumulator
40-
FF accum_hash = verifier_accum->add_hash_to_transcript("", *transcript);
40+
FF accum_hash = verifier_accum->hash_through_transcript(domain_separator + '_', *transcript);
41+
transcript->add_to_hash_buffer(domain_separator + "_accum_hash", accum_hash);
4142
info("Accumulator hash in PG prover: ", accum_hash);
4243
}
4344

barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ void ProtogalaxyVerifier_<DeciderVerificationKeys>::run_oink_verifier_on_each_in
2525
key->gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0);
2626
} else {
2727
// Fiat-Shamir the verifier accumulator
28-
FF accum_hash = key->add_hash_to_transcript("", *transcript);
28+
FF accum_hash = key->hash_through_transcript(domain_separator + '_', *transcript);
29+
transcript->add_to_hash_buffer(domain_separator + "_accum_hash", accum_hash);
2930
info("Accumulator hash in PG verifier: ", accum_hash);
3031
}
3132

barretenberg/cpp/src/barretenberg/stdlib/eccvm_verifier/eccvm_recursive_flavor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class ECCVMRecursiveFlavor {
146146
* @param domain_separator
147147
* @param transcript
148148
*/
149-
FF add_hash_to_transcript([[maybe_unused]] const std::string& domain_separator,
150-
[[maybe_unused]] Transcript& transcript) const override
149+
FF hash_through_transcript([[maybe_unused]] const std::string& domain_separator,
150+
[[maybe_unused]] Transcript& transcript) const override
151151
{
152152
throw_or_abort("Not intended to be used because vk is hardcoded in circuit.");
153153
}

barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ template <typename Flavor> void OinkRecursiveVerifier_<Flavor>::verify()
5050
WitnessCommitments commitments;
5151
CommitmentLabels labels;
5252

53-
FF vkey_hash = decider_vk->vk_and_hash->vk->add_hash_to_transcript(domain_separator, *transcript);
54-
vinfo("vk hash in Oink recursive verifier: ", vkey_hash);
53+
FF vk_hash = decider_vk->vk_and_hash->vk->hash_through_transcript(domain_separator, *transcript);
54+
transcript->add_to_hash_buffer(domain_separator + "vk_hash", vk_hash);
55+
vinfo("vk hash in Oink recursive verifier: ", vk_hash);
5556
vinfo("expected vk hash: ", decider_vk->vk_and_hash->hash);
5657
// Check that the vk hash matches the hash of the verification key
57-
decider_vk->vk_and_hash->hash.assert_equal(vkey_hash);
58+
decider_vk->vk_and_hash->hash.assert_equal(vk_hash);
5859

5960
size_t num_public_inputs =
6061
static_cast<size_t>(static_cast<uint32_t>(decider_vk->vk_and_hash->vk->num_public_inputs.get_value()));

barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ void ProtogalaxyRecursiveVerifier_<DeciderVerificationKeys>::run_oink_verifier_o
2929
// Fiat-Shamir the accumulator.
3030
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1390): assert_equal on accumulator hash with public
3131
// input hash.
32-
FF accum_hash = key->add_hash_to_transcript("", *transcript);
32+
FF accum_hash = key->hash_through_transcript(domain_separator + '_', *transcript);
33+
transcript->add_to_hash_buffer(domain_separator + "_accum_hash", accum_hash);
3334
info("Accumulator hash in PG rec verifier: ", accum_hash);
3435
}
3536

0 commit comments

Comments
 (0)