refactor!: Use circuit builders#501
Conversation
| #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.
what is the difference between WORKTODO and a regular TODO?
There was a problem hiding this comment.
WORKTODO is something I search for and then resolve before putting the PR up for review.
There was a problem hiding this comment.
Tbh maybe I should use something shorter like HEY
kevaundray
left a comment
There was a problem hiding this comment.
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
|
|
||
| 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.
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 🥇 |
codygunton
left a comment
There was a problem hiding this comment.
Leaving some explanatory notes.
| - readability-function-cognitive-complexity | ||
| # It is often nicer to not be explicit | ||
| - google-explicit-constructor | ||
| CheckOptions: |
There was a problem hiding this comment.
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.
| #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.
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.
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.
There was some using namespace pollution that let us get away with shortened namespace qualifiers.
| * @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.
Is it better to be more verbose and use CircuitBuilder, at least for the type name?
There was a problem hiding this comment.
I think I prefer CircuitBuilder but I dont feel strongly. As long as we're not using B..
| #include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
| #include <benchmark/benchmark.h> | ||
| #include <cstddef> | ||
| #include "barretenberg/honk/composer/standard_honk_composer.hpp" |
There was a problem hiding this comment.
Renaming and moving comes in the next PR.
| } | ||
|
|
||
| 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.
IOU: get rid of ComposerType and introduce a concept like UsePlookup or something like this.
| return output; | ||
| } | ||
|
|
||
| TEST(stdlib_sha256, test_duplicate_proving_key) |
There was a problem hiding this comment.
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.
(moved and pared down to one of the above files, similarly with composers_fwd.hpp)
| return result; | ||
| } | ||
|
|
||
| template <typename Flavor> |
There was a problem hiding this comment.
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.
Automatically nicer for Honk since no manifest..
| @@ -1,70 +1,101 @@ | |||
| #include "verifier.hpp" | |||
There was a problem hiding this comment.
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.
ledwards2225
left a comment
There was a problem hiding this comment.
Looks great. Big step forward. No major comments
| * @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.
I think I prefer CircuitBuilder but I dont feel strongly. As long as we're not using B..
|
|
||
| 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.
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.
| 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.
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) \ |
|
|
||
| Composer create_circuit_with_witness(acir_format const& constraint_system, | ||
| WitnessVector const& witness, | ||
| std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory, |
| { | ||
| InnerComposer inner_composer = InnerComposer(srs_path); | ||
| OuterComposer outer_composer = OuterComposer(srs_path); | ||
| InnerBuilder inner_circuit; |
There was a problem hiding this comment.
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..
| return result; | ||
| } | ||
|
|
||
| template <typename Flavor> |
There was a problem hiding this comment.
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.
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.
I find that this happens comment code is further commented out then formatted
| if constexpr (std::same_as<TypeParam, TurboPlonkComposerHelper>) { | ||
| TestFixture::test_double_verification(); | ||
| } else { | ||
| // Test doesn't compile. |
There was a problem hiding this comment.
Is this expected? Could be worth elaborating here
There was a problem hiding this comment.
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/specshave been updated.@briefdescribing the intended functionality.