-
Notifications
You must be signed in to change notification settings - Fork 609
feat: IPA claim as public component #13429
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
Changes from all commits
8d09c51
fcbcaf1
d4d304f
8f47d15
b489441
f2ccec7
b12a704
082cc08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,24 +51,62 @@ template <typename Curve> class OpeningClaim { | |
| using Fr = typename Curve::ScalarField; | ||
|
|
||
| public: | ||
| using Builder = | ||
| std::conditional_t<std::is_same_v<Curve, stdlib::grumpkin<UltraCircuitBuilder>>, UltraCircuitBuilder, void>; | ||
| // (challenge r, evaluation v = p(r)) | ||
| OpeningPair<Curve> opening_pair; | ||
| // commitment to univariate polynomial p(X) | ||
| Commitment commitment; | ||
|
|
||
| IPAClaimIndices get_witness_indices() const | ||
| // Size of public inputs representation of an opening claim over Grumpkin | ||
| static constexpr size_t PUBLIC_INPUTS_SIZE = IPA_CLAIM_SIZE; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this can be written as a sum now, and IPA_CLAIM_SIZE can be based off of this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good idea but it spirals in the linker bc agg types has to include some stdlib types which in turn wreaks havoc in all the places agg types is included. leaving it for another day |
||
|
|
||
| /** | ||
| * @brief Set the witness indices for the opening claim to public | ||
| * @note Implemented only for an opening claim over Grumpkin for use with IPA. | ||
| * | ||
| */ | ||
| uint32_t set_public() | ||
| requires(std::is_same_v<Curve, stdlib::grumpkin<UltraCircuitBuilder>>) | ||
| { | ||
| uint32_t start_idx = opening_pair.challenge.set_public(); | ||
| opening_pair.evaluation.set_public(); | ||
| commitment.set_public(); | ||
|
|
||
| Builder* ctx = commitment.get_context(); | ||
| // TODO(https://github.com/AztecProtocol/barretenberg/issues/1325): Eventually the builder/PK/VK will store | ||
| // public input key which should be set here and ipa_claim_public_input_indices should go away. | ||
| uint32_t pub_idx = start_idx; | ||
| for (uint32_t& idx : ctx->ipa_claim_public_input_indices) { | ||
| idx = pub_idx++; | ||
| } | ||
| ctx->contains_ipa_claim = true; | ||
|
|
||
| return start_idx; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Reconstruct an opening claim from limbs stored on the public inputs. | ||
| * @note Implemented only for an opening claim over Grumpkin for use with IPA. | ||
| * | ||
| */ | ||
| static OpeningClaim<Curve> reconstruct_from_public( | ||
| const std::span<const stdlib::field_t<Builder>, PUBLIC_INPUTS_SIZE>& limbs) | ||
| requires(std::is_same_v<Curve, stdlib::grumpkin<UltraCircuitBuilder>>) | ||
| { | ||
| return { opening_pair.challenge.binary_basis_limbs[0].element.normalize().witness_index, | ||
| opening_pair.challenge.binary_basis_limbs[1].element.normalize().witness_index, | ||
| opening_pair.challenge.binary_basis_limbs[2].element.normalize().witness_index, | ||
| opening_pair.challenge.binary_basis_limbs[3].element.normalize().witness_index, | ||
| opening_pair.evaluation.binary_basis_limbs[0].element.normalize().witness_index, | ||
| opening_pair.evaluation.binary_basis_limbs[1].element.normalize().witness_index, | ||
| opening_pair.evaluation.binary_basis_limbs[2].element.normalize().witness_index, | ||
| opening_pair.evaluation.binary_basis_limbs[3].element.normalize().witness_index, | ||
| commitment.x.normalize().witness_index, // no idea if we need these normalize() calls... | ||
| commitment.y.normalize().witness_index }; | ||
| ASSERT(2 * Fr::PUBLIC_INPUTS_SIZE + Commitment::PUBLIC_INPUTS_SIZE == PUBLIC_INPUTS_SIZE); | ||
|
|
||
| const size_t FIELD_SIZE = Fr::PUBLIC_INPUTS_SIZE; | ||
| const size_t COMMITMENT_SIZE = Commitment::PUBLIC_INPUTS_SIZE; | ||
| std::span<const stdlib::field_t<Builder>, FIELD_SIZE> challenge_limbs{ limbs.data(), FIELD_SIZE }; | ||
| std::span<const stdlib::field_t<Builder>, FIELD_SIZE> evaluation_limbs{ limbs.data() + FIELD_SIZE, FIELD_SIZE }; | ||
| std::span<const stdlib::field_t<Builder>, COMMITMENT_SIZE> commitment_limbs{ limbs.data() + 2 * FIELD_SIZE, | ||
| COMMITMENT_SIZE }; | ||
| auto challenge = Fr::reconstruct_from_public(challenge_limbs); | ||
| auto evaluation = Fr::reconstruct_from_public(evaluation_limbs); | ||
| auto commitment = Commitment::reconstruct_from_public(commitment_limbs); | ||
|
|
||
| return OpeningClaim<Curve>{ { challenge, evaluation }, commitment }; | ||
| } | ||
|
|
||
| auto get_native_opening_claim() const | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,11 +183,12 @@ template <typename FF_> class CircuitBuilderBase { | |
| virtual uint32_t add_public_variable(const FF& in); | ||
|
|
||
| /** | ||
| * Make a witness variable public. | ||
| * @brief Make a witness variable public. | ||
| * | ||
| * @param witness_index The index of the witness. | ||
| * */ | ||
| virtual void set_public_input(uint32_t witness_index); | ||
| * @return uint32_t The index of the witness in the public inputs vector. | ||
| */ | ||
| virtual uint32_t set_public_input(uint32_t witness_index); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should modify the comment to say what it returns |
||
| virtual void assert_equal(uint32_t a_idx, uint32_t b_idx, std::string const& msg = "assert_equal"); | ||
|
|
||
| // TODO(#216)(Adrian): This method should belong in the ComposerHelper, where the number of reserved gates can be | ||
|
|
@@ -216,8 +217,6 @@ template <typename FF_> class CircuitBuilderBase { | |
| void add_pairing_point_accumulator_for_plonk( | ||
| const PairingPointAccumulatorIndices& pairing_point_accum_witness_indices); | ||
|
|
||
| void add_ipa_claim(const IPAClaimIndices& ipa_claim_witness_indices); | ||
|
|
||
| bool failed() const; | ||
| const std::string& err() const; | ||
|
|
||
|
|
||
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.
does this fail to compile if we try to use it with a non grumpkin curve?
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.
Well it fails to compile with a non stdlib Curve type (this class is shared with native code). I made it explicitly Grumpkin because that's all we currently need it for and all we currently test