-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor!: Use circuit builders #501
Conversation
@@ -7,6 +7,7 @@ | |||
#include "barretenberg/common/net.hpp" | |||
|
|||
const std::string protocol_name = "BARRETENBERG_GRUMPKIN_IPA_CRS"; | |||
// WORKTODO: this is incorrect now right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference between WORKTODO and a regular TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WORKTODO is something I search for and then resolve before putting the PR up for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh maybe I should use something shorter like HEY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps HMM
alla Zac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still in draft so can ignore the nits.
Note: if check_circuit
being false causes the prover to not create a proof, then this would be a breaking change since the observed behaviour from someone doing a recursive verification will be different when the circuit is invalid.
If only a flag is outputted or more generally, the observed behaviour does not change with or without check_circuit
then it is non-breaking
@@ -150,7 +153,7 @@ template <typename OuterComposer> class stdlib_verifier : public testing::Test { | |||
} | |||
|
|||
info("Verifying the ultra (inner) proof natively..."); | |||
auto native_result = native_verifier.verify_proof(recursive_proof); | |||
auto native_result = native_verifier.verify_proof(recursive_proof); // WORKTODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the TODO referring to here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recursive_proof
is a bad name... misleading shorthand for proof_to_be_recursively_verified
. Plan to rename to something easier to parse.
@kevaundray Did you see something that caused you to have a concern around this? |
^ space needed 🥇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving some explanatory notes.
@@ -59,8 +59,6 @@ Diagnostics: | |||
- readability-function-cognitive-complexity | |||
# It is often nicer to not be explicit | |||
- google-explicit-constructor | |||
CheckOptions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this option before to avoid a warning we had, but now we don't need to avoid that warning and I added the option incorrectly anyway.
@@ -21,8 +21,8 @@ | |||
#include "ecc/curves/grumpkin/grumpkin.hpp" | |||
#include "numeric/random/engine.hpp" | |||
#include "numeric/uint256/uint256.hpp" | |||
#include "plonk/composer/turbo_plonk_composer.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The follow-up to this PR will include lots of renaming, eg "circuit constructor" becomes "circuit builder" in various places, "composer" becomes "circuit" or "builder" or "circuit_builder" or something in some places, and stays "composer" in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, there were certain places where I found it helpful/clarifying to do some renaming in order to get this refactor done, and I leave some of that work in place.
plonk::stdlib::field_t b(plonk::stdlib::witness_t(&composer, barretenberg::fr::random_element())); | ||
plonk::stdlib::field_t c(&composer); | ||
proof_system::plonk::stdlib::field_t a( | ||
proof_system::plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was some using namespace
pollution that let us get away with shortened namespace qualifiers.
@@ -41,11 +35,13 @@ struct BenchParams { | |||
* @param composer | |||
* @param num_iterations | |||
*/ | |||
template <typename Composer> void generate_basic_arithmetic_circuit(Composer& composer, size_t num_gates) | |||
template <typename Builder> void generate_basic_arithmetic_circuit(Builder& builder, size_t num_gates) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to be more verbose and use CircuitBuilder
, at least for the type name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer CircuitBuilder
but I dont feel strongly. As long as we're not using B
..
#include <benchmark/benchmark.h> | ||
#include <cstddef> | ||
#include "barretenberg/honk/composer/standard_honk_composer.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming and moving comes in the next PR.
@@ -36,7 +36,8 @@ point<C> pedersen_commitment<C>::commit(const std::vector<field_t>& inputs, | |||
throw_or_abort("Vector size mismatch."); | |||
} | |||
|
|||
if constexpr (C::type == ComposerType::PLOOKUP && C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { | |||
if constexpr (C::type == proof_system::ComposerType::PLOOKUP && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOU: get rid of ComposerType
and introduce a concept like UsePlookup
or something like this.
@@ -113,52 +114,24 @@ std::array<uint64_t, 8> inner_block(std::array<uint64_t, 64>& w) | |||
return output; | |||
} | |||
|
|||
TEST(stdlib_sha256, test_duplicate_proving_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After rewriting this (stdlib) test to not use a composer, it was clear that it's not a test of circuit logic, but instead of composer/proof system logic, so I deleted it.
@@ -1,73 +0,0 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(moved and pared down to one of the above files, similarly with composers_fwd.hpp)
@@ -415,6 +413,23 @@ aggregation_state<Curve> verify_proof_(typename Curve::Composer* context, | |||
return result; | |||
} | |||
|
|||
template <typename Flavor> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this so that I could avoid needing to construct a manifest (a proof-system detail) in the the ACL. @maramihali in future recursion work, we should expose a nice and simple interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automatically nicer for Honk since no manifest..
@@ -1,70 +1,101 @@ | |||
#include "verifier.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took a while to properly refactor this. Since the tests were already hard to read IMO, I went ahead and did a deeper refactor, aiming to save the next person some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Big step forward. No major comments
@@ -41,11 +35,13 @@ struct BenchParams { | |||
* @param composer | |||
* @param num_iterations | |||
*/ | |||
template <typename Composer> void generate_basic_arithmetic_circuit(Composer& composer, size_t num_gates) | |||
template <typename Builder> void generate_basic_arithmetic_circuit(Builder& builder, size_t num_gates) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer CircuitBuilder
but I dont feel strongly. As long as we're not using B
..
@@ -115,22 +111,23 @@ template <typename Composer> void generate_ecdsa_verification_test_circuit(Compo | |||
|
|||
bool first_result = | |||
crypto::ecdsa::verify_signature<Sha256Hasher, fq, fr, g1>(message_string, account.public_key, signature); | |||
static_cast<void>(first_result); // TODO(Cody): This is not used anywhere. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started using [[ maybe_unused ]] first_result = ...
instead, but I think in this case the entire crypto::ecdsa::verify_signature
can be deleted. I think this was debugging code that I forgot to delete.
cpp/src/barretenberg/common/log.hpp
Outdated
@@ -38,7 +20,9 @@ template <typename... Args> std::string format(Args... args) | |||
|
|||
template <typename T> void benchmark_format_chain(std::ostream& os, T const& first) | |||
{ | |||
// We will be saving these values to a CSV file, so we can't tolerate commas | |||
// We will be saving these values to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange. Line breaks way too short
|
||
#define BENCHMARK_INFO_PREFIX "##BENCHMARK_INFO_PREFIX##" | ||
#define BENCHMARK_INFO_SEPARATOR "#" | ||
#define BENCHMARK_INFO_SUFFIX "##BENCHMARK_INFO_SUFFIX##" | ||
#define GET_COMPOSER_NAME_STRING(composer) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lovely
} | ||
|
||
Composer create_circuit_with_witness(acir_format const& constraint_system, | ||
WitnessVector const& witness, | ||
std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
{ | ||
InnerComposer inner_composer = InnerComposer(srs_path); | ||
OuterComposer outer_composer = OuterComposer(srs_path); | ||
InnerBuilder inner_circuit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the difficulty is that the CircuitBuilder
contains both the methods that do the building and the data that defines the circuit. This isnt very appealing and I'm not suggesting it but logically just Circuit
actually makes the most sense to me. Presumably this is what led you to wanting to call the instance inner_circuit.
So perhaps your blend of InnerBuilder inner_circuit
is just the thing..
@@ -415,6 +413,23 @@ aggregation_state<Curve> verify_proof_(typename Curve::Composer* context, | |||
return result; | |||
} | |||
|
|||
template <typename Flavor> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automatically nicer for Honk since no manifest..
// * use this additional function to check that the recursive proof points work. | ||
// * | ||
// * @return boolean result | ||
// */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uncommment this description?
// verifies a proof of a circuit that verifies one of two proofs. Test 'a' uses a proof over the first of the two | ||
// variable circuits | ||
// verifies a proof of a circuit that verifies one of two proofs. Test 'a' uses a proof over the first of the | ||
// two variable circuits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that this happens comment code is further commented out then formatted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good call.
if constexpr (std::same_as<TypeParam, TurboPlonkComposerHelper>) { | ||
TestFixture::test_double_verification(); | ||
} else { | ||
// Test doesn't compile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this expected? Could be worth elaborating here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the comment I rewrote, which said that the test was too heavy to run in CI, was misleading. It doesn't run because in the else
branch there's a type clash due to how the test setup functions are written.
Gets rid of the composers class that wrapped a circuit constructor and a composer helper. This entailed various improvements such as a refactor of the stdlib verifier tests. Cleanup such a renaming of classes and moving of files will come in another PR. Corresponding PR in the core circuits library is #895.
Gets rid of the composers class that wrapped a circuit constructor and a composer helper. This entailed various improvements such as a refactor of the stdlib verifier tests. Cleanup such a renaming of classes and moving of files will come in another PR. Corresponding PR in the core circuits library is #895.
Description
Finally finish the splitting work, up to some renaming for clarity to be done in a follow-up.
Checklist:
/markdown/specs
have been updated.@brief
describing the intended functionality.