Skip to content

Commit

Permalink
move print statement for number of gates post finalisation for client…
Browse files Browse the repository at this point in the history
… IVC rec vec
  • Loading branch information
maramihali committed Jul 17, 2024
1 parent a5ccefa commit 1d86341
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 27 deletions.
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,11 @@ void prove_tube(const std::string& output_path)
ClientIVC verifier{ builder, input };

verifier.verify(proof);
info("num gates in tube circuit: ", builder->get_num_gates());
using Prover = UltraProver_<UltraFlavor>;
using Verifier = UltraVerifier_<UltraFlavor>;
Prover tube_prover{ *builder };
// Print the number of gates post finalisation for a precise result
info("num gates in tube circuit: ", builder->get_num_gates());
auto tube_proof = tube_prover.construct_proof();
std::string tubeProofPath = output_path + "/proof";
write_file(tubeProofPath, to_buffer<true>(tube_proof));
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(commitment_schemes_recursion commitment_schemes stdlib_primitives)
barretenberg_module(commitment_schemes_recursion commitment_schemes stdlib_poseidon2)
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ template <typename C> field_t<C> poseidon2<C>::hash_buffer(C& builder, const std
}
template class poseidon2<bb::MegaCircuitBuilder>;
template class poseidon2<bb::UltraCircuitBuilder>;
template class poseidon2<bb::CircuitSimulatorBN254>;

} // namespace bb::stdlib
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,6 @@ void Poseidon2Permutation<Params, Builder>::matrix_multiplication_external(

template class Poseidon2Permutation<crypto::Poseidon2Bn254ScalarFieldParams, MegaCircuitBuilder>;
template class Poseidon2Permutation<crypto::Poseidon2Bn254ScalarFieldParams, UltraCircuitBuilder>;
template class Poseidon2Permutation<crypto::Poseidon2Bn254ScalarFieldParams, CircuitSimulatorBN254>;

} // namespace bb::stdlib
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,51 @@ namespace bb::stdlib::recursion::honk {
template <typename Builder> struct StdlibTranscriptParams {
using Fr = stdlib::field_t<Builder>;
using Proof = std::vector<Fr>;

static inline Fr hash(const std::vector<Fr>& data)
{
if constexpr (std::is_same_v<Builder, MegaCircuitBuilder>) {
ASSERT(!data.empty() && data[0].get_context() != nullptr);
Builder* builder = data[0].get_context();
return stdlib::poseidon2<Builder>::hash(*builder, data);
} else if constexpr (std::is_same_v<Builder, UltraCircuitBuilder>) {
ASSERT(!data.empty() && data[0].get_context() != nullptr);
Builder* builder = data[0].get_context();
return stdlib::poseidon2<Builder>::hash(*builder, data);
} else {
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1035): Add constraints for hashing in Ultra
using NativeFr = bb::fr;
ASSERT(!data.empty() && data[0].get_context() != nullptr);
Builder* builder = data[0].get_context();

// call the native hash on the data
std::vector<NativeFr> native_data;
native_data.reserve(data.size());
for (const auto& fr : data) {
native_data.push_back(fr.get_value());
}
NativeFr hash_value = crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash(native_data);
ASSERT(!data.empty() && data[0].get_context() != nullptr);

Builder* builder = data[0].get_context();
return stdlib::poseidon2<Builder>::hash(*builder, data);
// } else {
// // TODO(https://github.com/AztecProtocol/barretenberg/issues/1035): Add constraints for hashing in Ultra
// using NativeFr = bb::fr;
// ASSERT(!data.empty() && data[0].get_context() != nullptr);
// Builder* builder = data[0].get_context();

Fr hash_field_ct = Fr::from_witness(builder, hash_value);
return hash_field_ct;
}
// // call the native hash on the data
// std::vector<NativeFr> native_data;
// native_data.reserve(data.size());
// for (const auto& fr : data) {
// native_data.push_back(fr.get_value());
// }
// NativeFr hash_value = crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash(native_data);

// Fr hash_field_ct = Fr::from_witness(builder, hash_value);
// return hash_field_ct;
// }
}

template <typename T> static inline T convert_challenge(const Fr& challenge)
{
Builder* builder = challenge.get_context();
return bb::stdlib::field_conversion::convert_challenge<Builder, T>(*builder, challenge);
}

template <typename T> static constexpr size_t calc_num_bn254_frs()
{
return bb::stdlib::field_conversion::calc_num_bn254_frs<Builder, T>();
}

template <typename T> static inline T convert_from_bn254_frs(std::span<const Fr> frs)
{
ASSERT(!frs.empty() && frs[0].get_context() != nullptr);
Builder* builder = frs[0].get_context();
return bb::stdlib::field_conversion::convert_from_bn254_frs<Builder, T>(*builder, frs);
}

template <typename T> static inline std::vector<Fr> convert_to_bn254_frs(const T& element)
{
Builder* builder = element.get_context();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ TEST_F(ClientIVCRecursionTests, Basic)
// Generate the recursive verification circuit
verifier.verify(proof);

info("Recursive Verifier: num gates = ", builder->num_gates);

EXPECT_EQ(builder->failed(), false) << builder->err();

EXPECT_TRUE(CircuitChecker::check(*builder));

info("Recursive Verifier: num gates = ", builder->num_gates);
}

} // namespace bb::stdlib::recursion::honk
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase<typename Arithmetization_
* 3) Number of Rom array-associated gates
* 4) Number of range-list associated gates
* 5) Number of non-native field multiplication gates.
* !!! WARNING: This function is predictive and might report an incorrect number. Make sure to finalise the circuit
* and then check the number of gates for a precise result. Kesha: it's basically voodoo
*
* @return size_t
* TODO(https://github.com/AztecProtocol/barretenberg/issues/875): This method may return an incorrect value before
Expand Down

0 comments on commit 1d86341

Please sign in to comment.