Skip to content

feat: Poseidon2 gates for Ultra arithmetisation - #7494

Merged
maramihali merged 81 commits into
masterfrom
mm/poseidon-relation-ultra
Aug 21, 2024
Merged

feat: Poseidon2 gates for Ultra arithmetisation#7494
maramihali merged 81 commits into
masterfrom
mm/poseidon-relation-ultra

Conversation

@maramihali

@maramihali maramihali commented Jul 16, 2024

Copy link
Copy Markdown

Add Poseidon2 gates to the UltraCircuitBuilder which now ensures that recursive verifier instantiated with the Ultra arithmetisation produce the correct number of constraints.

Updates required:

  • change verification key length and constant proof length constants across the codebase (two selectors from the new gate whose commitments need to be in the vk and the poseidon relation becomes the one with the highest degree); changes to Prover.toml accordingly
  • ensure the ultra recursive verifier still stays constant size now that hashing produces gates
  • small modification to solidity verifer to reflect the ones in cpp with the caveat that the UltraKeccak flavor still doesnt support Poseidon gate (changes coming in a followup PR)

Tube circuit changes in # of gates (post finalisation):

  • number of gates prior this change, in master: 13947018
  • number of gates post this change: 14038982

Closes AztecProtocol/barretenberg#1041

@maramihali maramihali changed the title Poseidon in UltraHonk feat: Poseidon2 in UltraHonk Jul 16, 2024
@maramihali
maramihali force-pushed the mm/poseidon-relation-ultra branch from 68bf98a to 1d86341 Compare July 17, 2024 16:33
@maramihali
maramihali force-pushed the mm/poseidon-relation-ultra branch from 5304c7e to f1edf5f Compare July 19, 2024 11:04
void set_fixed_size(uint32_t size_in) { fixed_size = size_in; }
};

class TranslatorArith {

ghost Jul 19, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This could just be moved to Translator, randomly stumbled across it

@maramihali maramihali changed the title feat: Poseidon2 in UltraHonk feat: Poseidon2 gates for Ultra arithmetisation Jul 19, 2024
@maramihali maramihali self-assigned this Jul 19, 2024
@maramihali maramihali added the crypto cryptography label Jul 19, 2024
@lucasxia01
lucasxia01 self-requested a review July 19, 2024 15:50
@maramihali
maramihali marked this pull request as ready for review July 22, 2024 16:49
@maramihali
maramihali force-pushed the mm/poseidon-relation-ultra branch from fe9b300 to 83ecd92 Compare July 22, 2024 17:04

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work. Would like to see the before and after difference in the number of gates for the ultra recursive verifier as well if possible.

also a 650k gate difference in the tube circuit seems insane if its just from hashing. That's like 10000 calls to hash()

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());

ghost Jul 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove?

ghost Jul 23, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Erm I guess it's good info generally when running e2e tests

ghost Jul 23, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note that it calls get_num_gates() and not builder.num_gates. As a sidenote, maybe we can change the name of get_num_gates() to estimate_num_finalized_gates()

@@ -1 +1 @@
barretenberg_module(commitment_schemes_recursion commitment_schemes stdlib_primitives) No newline at end of file
barretenberg_module(commitment_schemes_recursion commitment_schemes stdlib_poseidon2) No newline at end of file

ghost Jul 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need stdlib poseidon and not primitives for commitment schemes?

ghost Jul 23, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the module doesnt link without poseidon now that it's enabled and stdlib_poseidon2 already includes stdlib_primitives

# np.set_printoptions(formatter={'int': hex})

EXTENDED_RELATION_LENGTH = 13
EXTENDED_RELATION_LENGTH = 12

ghost Jul 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interesting that this decreased

ghost Jul 23, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

A prior line of work decreased it (using different etas rather than powers of eta) but because nothing in the logic changed, that PR could just remove one value in the combiner tests and this file wasnt modified. Now I had to rerun the script and realised we have one extra eval, but my PR didnt specifically decreased this

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

// Print the number of gates post finalisation
info("Recursive Verifier: num gates = ", builder->num_gates);

ghost Jul 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe could have both actually and mark which one is pre/post finalization

alpha[idx] = transcript->template get_challenge<FF>("alpha_" + std::to_string(idx));
}

// TODO(https://github.com/AztecProtocol/barretenberg/issues/1041): Once hashing produces constraints for Ultra in

ghost Jul 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

put this in the PR description

ghost Jul 25, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not opposed to sprinkling TODOs in the code FWIW it helps keep them top of mind (as long as they link an issue that can then be used for cleanup)

ghost Jul 29, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this TODO is supposed to be resolved by this PR


bool broke(false);
auto check_eq = [&broke](auto& p1, auto& p2) {
EXPECT_TRUE(p1.size() == p2.size());

ghost Jul 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also could have checked that the circuit sizes of the vks were the same, but this works.

if (sumcheck_verified.has_value() && !sumcheck_verified.value()) {
info("Sumcheck verification failed.");
return false;
// return false;

ghost Jul 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this commented out?

ghost Jul 23, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

wopsie, leftover from debugging, thanks for spotting

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good in general with some more cleanup. Also not entirely sure what exactly needs to be done to get everything working after this work.

builder->add_recursive_proof(current_aggregation_object);

info("num gates in tube circuit: ", builder->get_num_gates());
info("num gates in tube circuit: ", builder->num_gates);

ghost Aug 20, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe say that this is num prefinalized gates in tube circuit

ghost Aug 20, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

will remove

stdlib::field_t b(stdlib::witness_t(&builder, fr::random_element()));
stdlib::field_t c(&builder);
size_t passes = (1UL << log2_num_gates) / 4 - 4;
size_t passes = (1UL << log2_num_gates) / 4 - 8;

ghost Aug 20, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why?

ghost Aug 20, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I will add a comment, the function fills a circuit up ot the desired numbers of gates for the benchmark, ensuring finalisation and the add gates to ensure non zero polys method wont cause it to go to the next power of 2 (or at least that was my deduction). Because we enabled poseidon add gates to ensure non zero polys will add more gates so i need to lower a bit the number of passes

Comment thread barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp Outdated
Comment thread barretenberg/cpp/src/barretenberg/stdlib/transcript/transcript.test.cpp Outdated
Comment thread barretenberg/cpp/src/barretenberg/stdlib/transcript/transcript.test.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crypto cryptography

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update gate_challenges for constant honk proof size

4 participants