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 #895

Merged
merged 29 commits into from
Jun 28, 2023
Merged

refactor!: Use circuit builders #895

merged 29 commits into from
Jun 28, 2023

Conversation

codygunton
Copy link
Contributor

@codygunton codygunton commented Jun 20, 2023

Description

This PR is 'just' bulk cleanup to reflect changes in Barretenberg. These are the main changes.

  • Composer is renamed to Builder or CircuitBuilder
  • composer is renamed to builder. In some contexts circuit also makes sense and it might be preferable.
  • Circuit builders are not instantiated with a string specifying a crs, so these constructors (which were available because of a hack) are removed.
  • ComposerType was renamed to CircuitType and this is changed accordingly, along with renaming composer_type to circuit_type.
  • Rename DummyComposer and dummy_composer.hpp.
  • In order to restrict the barretenberg API, the Aggregator::aggregate function now calls a more encapsulated recursive verifier function.

Some unexpected compiler errors around unused variables came up. I'm not sure how to proceed. I made an issue (#914) recording this in the hopes that we can merge with todos referencing that issue.

I left some additional notes as comments on lines of code.

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.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@codygunton codygunton self-assigned this Jun 21, 2023
codygunton added a commit to AztecProtocol/barretenberg that referenced this pull request Jun 21, 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 AztecProtocol/aztec-packages#895.
.l1_to_l2_messages_tree_root = 3000,
.private_kernel_vk_tree_root = 4000,
} };
// CombinedHistoricTreeRoots<NT> const historic_tree_roots = { .private_historic_tree_roots = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably? I haven't looked into the history or discussed with core circuits team yet.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I didn't see it was a draft, my bad

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up making an issue to look at this and two other unused variables in the same test file, and I reference that issue in TODOs in the code.

Copy link
Collaborator

@ludamad ludamad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall (although now I realize its a draft)

{
static_assert((std::is_same<NativeTypes, NCT>::value));

// Capture the composer:
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); };
// Capture the circuit builder:
Copy link
Contributor Author

@codygunton codygunton Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I think this this comment and this lambda are repeated 30 times!

@@ -91,7 +91,7 @@ std::shared_ptr<NT::VK> fake_vk()
{
std::map<std::string, NT::bn254_point> commitments;
commitments["FAKE"] = *new NT::bn254_point(NT::fq(0), NT::fq(0));
NT::VKData vk_data = { .composer_type = proof_system::ComposerType::TURBO,
NT::VKData vk_data = { .circuit_type = static_cast<uint32_t>(proof_system::CircuitType::TURBO),
Copy link
Contributor Author

@codygunton codygunton Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum ComposerType became enum class CircuitType : uint32_t and so we need to do explicit casting sometimes.

CT::AggregationObject result = verify_proof<CT::bn254, CT::recursive_inner_verifier_settings>(
composer, vk, recursive_manifest, proof, previous_aggregation_output);
CT::AggregationObject result =
verify_proof<plonk::flavor::Ultra>(builder, vk, proof, previous_aggregation_output);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was added to Barretenberg to avoid the circuits library from having to know about a manifest. In general, we should insulate the circuits library from details of proof construction (such as a manifest). I'm not sure that the flavor is the "right" thing, but it's an improvement, and doing it this way let me expose MUCH less in barretenberg.hpp.

STANDARD = 0,
TURBO = 1,
PLOOKUP = 2,
STANDARD_HONK = 3,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no difference between a standard Honk circuit and a standard Plonk circuit! This was a hack we introduced, iirc, in order to make the stdlib tests run with Honk.

@codygunton codygunton marked this pull request as ready for review June 27, 2023 01:08
PreviousKernelData<NT> const& previous_kernel,
std::array<NT::fr, READ_REQUESTS_LENGTH> const& read_requests,
std::array<MembershipWitness<NT, PRIVATE_DATA_TREE_HEIGHT>, READ_REQUESTS_LENGTH> const&
read_request_membership_witnesses);

CircuitResult<KernelCircuitPublicInputs<NT>> native_private_kernel_circuit_ordering_rr_dummy(
CircuitResult<KernelCircuitPublicInputs<NT> > native_private_kernel_circuit_ordering_rr_dummy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit but is this an unwanted space?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

{
// compute P0, P1 for private function proof
CT::AggregationObject aggregation_object = Aggregator::aggregate(
&composer, private_inputs.private_call.vk, private_inputs.private_call.proof, num_private_call_public_inputs);
CT::AggregationObject aggregation_object =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice, aggregate shouldn't have to know what the number of public inputs of the private call is.

std::conditional_t<std::same_as<Composer, plonk::TurboPlonkComposer>,
stdlib::recursion::recursive_turbo_verifier_settings<bn254>,
stdlib::recursion::recursive_ultra_verifier_settings<bn254>>;
using recursive_inner_verifier_settings = stdlib::recursion::recursive_ultra_verifier_settings<bn254>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is his because we don't expect turbo to be used as inner circuit builder anymore? If so, makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, Luke's previous PR fixed the inner circuit type to Ultra (indeed, Aggregate::aggregate now uses a fixed flavor), so it wouldn't even work to toggle the inner type. In general this recursion stuff needs a rework, so I thought I'd pare it down to make it simpler for when we do that work. In fact, I see now this alias is not in use anywhere, so I think I'll remove it.

Copy link
Contributor

@suyash67 suyash67 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just left a couple of minor comments. Thanks @codygunton.

@@ -113,7 +113,7 @@ value: 0xd05
"
`;

exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101, 0 }"`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @PhilWindle, this final value in the snapshot here should not exist because the signature tested is not an ECDSA signature as the naming suggests--it was switched in some places to a Schnorr signature. I complete this switch by changing the definition of abis__test_roundtrip_serialize_signature to use a Schnorr signature and updated the snapshot accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I tried to rename the test and ran into a weird error:

 FAIL  structs/kernel/index.test.ts
  ● Test suite failed to run

    ReferenceError: exports is not defined

      1 | import { expectSerializeToMatchSnapshot } from '../../tests/expectSerialize.js';
    > 2 | import { makeSchnorrSignature } from '../../tests/factories.js';
        |                       ^
      3 | import {
      4 |   makePreviousKernelData,
      5 |   makePrivateKernelInputsInner,

      at structs/kernel/index.test.ts:2:23

@codygunton codygunton merged commit 1df243e into master Jun 28, 2023
@codygunton codygunton deleted the cg/circuit-builders branch June 28, 2023 02:23
@codygunton codygunton restored the cg/circuit-builders branch June 28, 2023 02:29
@suyash67 suyash67 deleted the cg/circuit-builders branch June 28, 2023 03:20
@codygunton codygunton mentioned this pull request Jun 28, 2023
6 tasks
ludamad pushed a commit that referenced this pull request Jul 14, 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 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 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.

3 participants