-
Notifications
You must be signed in to change notification settings - Fork 599
feat: share the commitment key between instances to reduce mem #8154
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
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 |
|---|---|---|
|
|
@@ -132,6 +132,24 @@ TEST_F(AztecIVCTests, Basic) | |
| EXPECT_TRUE(ivc.prove_and_verify()); | ||
| }; | ||
|
|
||
| /** | ||
| * @brief A simple test demonstrating IVC for four mock circuits, which is slightly more than minimal. | ||
| * @details When accumulating only four circuits, we execute all the functionality of a full AztecIVC run. | ||
| * | ||
| */ | ||
| TEST_F(AztecIVCTests, BasicFour) | ||
|
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. could disable for CI given we have n=2 and n=6 already.
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. why even add this? this case is already contained in the failure test below
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. I'm using it to measure memory since it's the minimal case that does everything. Yeah I guess the failure test does 4 circuits but it was a failure test I guess. I can just disable this and leave a comment saying it's for memory benchmarking
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. oh I see, didn't realize it was the memory case |
||
| { | ||
| AztecIVC ivc; | ||
|
|
||
| MockCircuitProducer circuit_producer; | ||
| for (size_t idx = 0; idx < 4; ++idx) { | ||
| Builder circuit = circuit_producer.create_next_circuit(ivc); | ||
| ivc.accumulate(circuit); | ||
| } | ||
|
|
||
| EXPECT_TRUE(ivc.prove_and_verify()); | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Check that the IVC fails to verify if an intermediate fold proof is invalid | ||
| * @details When accumulating 4 circuits, there are 3 fold proofs to verify (the first two are recursively verfied and | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,12 +331,13 @@ class UltraFlavor { | |
| */ | ||
| class ProvingKey : public ProvingKey_<FF, CommitmentKey> { | ||
| public: | ||
| // Expose constructors on the base class | ||
| using Base = ProvingKey_<FF, CommitmentKey>; | ||
| using Base::Base; | ||
|
|
||
| ProvingKey(const size_t circuit_size, const size_t num_public_inputs) | ||
| : Base(circuit_size, num_public_inputs) | ||
| ProvingKey() = default; | ||
| ProvingKey(const size_t circuit_size, | ||
|
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. had to make these changes to ultra and ultra_keccak because otherwise the call to the constructor was just calling the Base one directly. That meant the polynomials did not get initialized to circuit_size length leading to a segfault. I briefly tried getting rid of the Base constructors (from the
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. actually, maybe adding default constructors to ProvingKey of each flavor would fix this and allow us to delete
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. Seems ok. Calling the parent class constructor from a child class constructor seems like a really natural pattern to me
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. oh, this comment wasn't referring to that pattern. It was referring to the using Base::Base line which brings in the base class constructors to the derived class, which was causing me to hit a segfault rather than a compile error. Like I was just calling the base class constructor when I thought it would call the derived class constructor (because I forgot to change the derived constructor to take in the commitment_key). |
||
| const size_t num_public_inputs, | ||
| std::shared_ptr<CommitmentKey> commitment_key = nullptr) | ||
| : Base(circuit_size, num_public_inputs, std::move(commitment_key)) | ||
| , polynomials(circuit_size){}; | ||
|
|
||
| std::vector<uint32_t> memory_read_records; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,11 +44,14 @@ template <class Flavor> class ProverInstance_ { | |
| std::vector<FF> gate_challenges; | ||
| FF target_sum; | ||
|
|
||
| ProverInstance_(Circuit& circuit, TraceStructure trace_structure = TraceStructure::NONE) | ||
| ProverInstance_(Circuit& circuit, | ||
| TraceStructure trace_structure = TraceStructure::NONE, | ||
| std::shared_ptr<typename Flavor::CommitmentKey> commitment_key = nullptr) | ||
| { | ||
| BB_OP_COUNT_TIME_NAME("ProverInstance(Circuit&)"); | ||
| circuit.add_gates_to_ensure_all_polys_are_non_zero(); | ||
| circuit.finalize_circuit(); | ||
| info("finalized gate count: ", circuit.num_gates); | ||
|
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. should probably be deleted but I wish it was here so people would see what their gate counts are all the time.
Collaborator
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. We are living with clientivc printing data, I'm sure we could live with this for now |
||
|
|
||
| // Set flag indicating whether the polynomials will be constructed with fixed block sizes for each gate type | ||
| const bool is_structured = (trace_structure != TraceStructure::NONE); | ||
|
|
@@ -70,7 +73,7 @@ template <class Flavor> class ProverInstance_ { | |
| } | ||
| { | ||
| ZoneScopedN("constructing proving key"); | ||
| proving_key = ProvingKey(dyadic_circuit_size, circuit.public_inputs.size()); | ||
| proving_key = ProvingKey(dyadic_circuit_size, circuit.public_inputs.size(), commitment_key); | ||
| } | ||
|
|
||
| // Construct and add to proving key the wire, selector and copy constraint polynomials | ||
|
|
||
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.
a little ugly since we now have two blocks of
if (!initialized) {} else {}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.
not great but ok for now. I'd think the eventual solution would be for IVC to initialize and manage its own commitment key then pass it to individual provers