Skip to content
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

Merged
merged 65 commits into from
Jun 21, 2023
Merged

refactor!: Use circuit builders #501

merged 65 commits into from
Jun 21, 2023

Conversation

codygunton
Copy link
Collaborator

@codygunton codygunton commented Jun 2, 2023

Description

Finally finish the splitting work, up to some renaming for clarity to be done in a follow-up.

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • There are no circuit changes, OR specifications in /markdown/specs have been updated.
  • There are no circuit changes, OR a cryptographer has been assigned for review.
  • I've updated any terraform that needs updating (e.g. environment variables) for deployment.
  • The branch has been rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.
  • New functions, classes, etc. have been documented according to the doxygen comment format. Classes and structs must have @brief describing the intended functionality.
  • If existing code has been modified, such documentation has been added or updated.

@codygunton codygunton self-assigned this Jun 5, 2023
@@ -7,6 +7,7 @@
#include "barretenberg/common/net.hpp"

const std::string protocol_name = "BARRETENBERG_GRUMPKIN_IPA_CRS";
// WORKTODO: this is incorrect now right?
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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

Copy link
Contributor

@kevaundray kevaundray left a 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
Copy link
Contributor

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

Copy link
Collaborator Author

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.

@codygunton
Copy link
Collaborator Author

codygunton commented Jun 14, 2023

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

@kevaundray Did you see something that caused you to have a concern around this?

@codygunton codygunton changed the title Big split refactor!:Big split Jun 14, 2023
@codygunton codygunton changed the title refactor!:Big split feat!:Big split Jun 14, 2023
@codygunton codygunton changed the title feat!:Big split feat:Big split Jun 14, 2023
@codygunton codygunton changed the title feat:Big split refactor!: Big split Jun 14, 2023
@codygunton
Copy link
Collaborator Author

^ space needed 🥇

Copy link
Collaborator Author

@codygunton codygunton left a 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:
Copy link
Collaborator Author

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"
Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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()));
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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?

Copy link
Collaborator

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"
Copy link
Collaborator Author

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 &&
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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 @@
/**
Copy link
Collaborator Author

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>
Copy link
Collaborator Author

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.

Copy link
Collaborator

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"
Copy link
Collaborator Author

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.

@codygunton codygunton linked an issue Jun 21, 2023 that may be closed by this pull request
@codygunton codygunton changed the title refactor!: Big split refactor!: Use circuit builders Jun 21, 2023
@codygunton codygunton marked this pull request as ready for review June 21, 2023 19:24
Copy link
Collaborator

@ledwards2225 ledwards2225 left a 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)
Copy link
Collaborator

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.
Copy link
Collaborator

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.

@@ -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
Copy link
Collaborator

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) \
Copy link
Collaborator

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,
Copy link
Collaborator

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;
Copy link
Collaborator

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>
Copy link
Collaborator

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
// */
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Collaborator Author

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.
Copy link
Collaborator

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

Copy link
Collaborator Author

@codygunton codygunton Jun 21, 2023

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.

@codygunton codygunton merged commit 709a29c into master Jun 21, 2023
@codygunton codygunton deleted the cg/big-split branch June 21, 2023 21:55
ludamad pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 22, 2023
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.
ludamad pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 24, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reinstate ACIR format tests.
3 participants