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

feat: add miscellaneous block to handle structure trace overflow #9733

Merged
merged 29 commits into from
Nov 11, 2024

Conversation

ledwards2225
Copy link
Contributor

@ledwards2225 ledwards2225 commented Nov 4, 2024

Adds an overflow block to the set of execution trace blocks which can store arbitrary gate types that have "overflowed" the capacity of their corresponding designated gate type block. This allows for accumulation of app circuits which do not fit into a given structured trace configuration.

It works as follows: when constructing a circuit, there is no bound on the size of each gate block. When a proving key is constructed, we check the capacity of each block and move any overflow into the overflow block. In all cases, the polynomials have the prescribed trace structure at the beginning plus a possible overflow block at the end.

@ledwards2225 ledwards2225 self-assigned this Nov 4, 2024
@ledwards2225 ledwards2225 marked this pull request as ready for review November 4, 2024 22:32
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Changes to public function bytecode sizes

Generated at commit: 54f340ddd4f31b2bbfefac55f53e123c172785de, compared to commit: ada3e3aba6141411a8ca931f45cc2b9b7027585e

🧾 Summary (100% most significant diffs)

Program Bytecode size in bytes (+/-) %
FPC::public_dispatch +1,034 ❌ +12.37%
FPC::constructor -96 ✅ -3.05%

Full diff report 👇
Program Bytecode size in bytes (+/-) %
FPC::public_dispatch 9,396 (+1,034) +12.37%
FPC::constructor 3,056 (-96) -3.05%

Copy link
Contributor

@maramihali maramihali left a comment

Choose a reason for hiding this comment

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

Really nice work :D very small suggestions

@@ -88,6 +89,10 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
if (IsGoblinFlavor<Flavor> && !is_structured) {
// Allocate full size polynomials
proving_key.polynomials = typename Flavor::ProverPolynomials(dyadic_circuit_size);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this branch and the one above lead to the same code being executed - did you separate them for readability? It seems like they canbe unified as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I thought it was a bit more readable but seems both you and the linter disagree so I combined them into one :)

@@ -360,7 +360,7 @@ template <typename T>
concept IsUltraPlonkFlavor = IsAnyOf<T, plonk::flavor::Ultra, UltraKeccakFlavor>;

template <typename T>
concept IsUltraPlonkOrHonk = IsAnyOf<T, plonk::flavor::Ultra, UltraFlavor, UltraKeccakFlavor, UltraFlavorWithZK, MegaFlavor>;
concept IsUltraPlonkOrHonk = IsAnyOf<T, plonk::flavor::Ultra, UltraFlavor, UltraKeccakFlavor, UltraFlavorWithZK, MegaFlavor, MegaZKFlavor>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I presume this might have been a culprit for why a test was failing for the ZK flavor

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 concept should be called IsLiterallyAnything

EXPECT_EQ(proving_key->proving_key.log_circuit_size, 19);
}

TEST_F(MegaMockCircuitsPinning, E2EStructuredCircuitSize)
{
GoblinProver goblin;
MegaCircuitBuilder app_circuit{ goblin.op_queue };
auto proving_key = std::make_shared<DeciderProvingKey>(app_circuit, TraceStructure::E2E_FULL_TEST);
TraceSettings trace_settings{ TraceStructure::E2E_FULL_TEST };
auto proving_key = std::make_shared<DeciderProvingKey>(app_circuit, trace_settings);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be:

Suggested change
auto proving_key = std::make_shared<DeciderProvingKey>(app_circuit, trace_settings);
auto proving_key = std::make_shared<DeciderProvingKey>(app_circuit, TraceSettings{TraceStructure::E2E_FULL_TEST});

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it could yeah, just seemed like an unreasonably long single line

uint32_t fixed_block_size = block.get_fixed_size();
if (block_size > fixed_block_size && block != overflow_block) {
// We dont handle this case
ASSERT(!block.is_pub_inputs);
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

@ledwards2225 ledwards2225 Nov 11, 2024

Choose a reason for hiding this comment

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

updated this to also include ecc_op block and added comment explaining that blocks not expected to be used by the App circuits arent allowed to overflow and will not be handled correctly

* to accommodate circuits which cannot fit into a prescribed trace, gates which overflow their corresponding block are
* placed into an overflow block which can contain arbitrary gate types.
* @note One sublety is that gates at row i may in general utilize the values at row i+1 via shifts. If the last row in
* a full-capacity block is such a gate, then moving the overflow out of sequence will cause that gate not to be
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe explain here what you mean by a dummy gate (i.e. that selectors are turn off) and also that it needs duplication so the second to last gate can function appropriately if it needs to check shifts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clarified, thanks

Copy link
Contributor

Changes to circuit sizes

Generated at commit: 54f340ddd4f31b2bbfefac55f53e123c172785de, compared to commit: ada3e3aba6141411a8ca931f45cc2b9b7027585e

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_block_root -464 ✅ -10.35% -5,960 ✅ -0.21%
rollup_block_root_empty -32 ✅ -34.04% -32 ✅ -1.11%
rollup_block_merge -6,944 ✅ -57.86% -29,107 ✅ -1.50%
rollup_root -6,944 ✅ -57.94% -29,107 ✅ -1.50%
rollup_base_public -15,774 ✅ -3.36% -221,618 ✅ -5.88%
rollup_base_private -15,774 ✅ -4.74% -221,618 ✅ -6.46%
private_kernel_reset_4_4_4_4_4_4_4_4_1 -667 ✅ -2.06% -9,667 ✅ -11.16%
private_kernel_reset -10,767 ✅ -12.80% -155,407 ✅ -25.14%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_block_root 4,021 (-464) -10.35% 2,857,288 (-5,960) -0.21%
rollup_block_root_empty 62 (-32) -34.04% 2,859 (-32) -1.11%
rollup_block_merge 5,057 (-6,944) -57.86% 1,911,809 (-29,107) -1.50%
rollup_root 5,041 (-6,944) -57.94% 1,911,795 (-29,107) -1.50%
rollup_base_public 454,278 (-15,774) -3.36% 3,549,032 (-221,618) -5.88%
rollup_base_private 317,095 (-15,774) -4.74% 3,210,904 (-221,618) -6.46%
private_kernel_reset_4_4_4_4_4_4_4_4_1 31,789 (-667) -2.06% 76,935 (-9,667) -11.16%
private_kernel_reset 73,331 (-10,767) -12.80% 462,711 (-155,407) -25.14%

@ledwards2225 ledwards2225 merged commit 80f9cc4 into master Nov 11, 2024
69 of 71 checks passed
@ledwards2225 ledwards2225 deleted the lde/misc_block branch November 11, 2024 16:32
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