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: Trace structure is an object #10003

Merged
merged 14 commits into from
Nov 15, 2024
Merged

Conversation

codygunton
Copy link
Contributor

@codygunton codygunton commented Nov 15, 2024

A trace structure is a set of block sizes that are known at compile time, but previously there was no simple way to extract any of this compile time information even at runtime without executing some heavier code or perhaps by duplicating a switch statement and manually computing a size a runtime. Motivated by this, I refactor the trace structure (formerly an enum coupled loosely to some related structures) so that it becomes a struct. At the same time I refactor related structures to use more familiar patterns. I also do some renaming and related general tidying.

size functions will be implemented in a follow-on, where they will help to allocate and use a single commitment key throughout ClientIVC.

Changes in structuring pattern

Old pattern:
- TraceBlocks subclasses MegaTraceBlocks<ExecutionTraceBlock>
- Each trace structure is a subclass with a different default constructor
- set_fixed_block_sizes instantiates a fixed_block_sizes object MegaTraceBlocks<uint32_t>
- set_fixed_block_sizes checks an enum to figure out which trace structure class to default construct
- set_fixed_block_sizes overwrites the fixed_block_sizes object

New Pattern:
- TraceStructure is MegaTraceBlockData<uint32_t>
- Each trace structure is a static constexpr instance of TraceStructure.
- set_fixed_block_sizes on a MegaExecutionTraceBlocks object takes a trace structure instance and uses it to set the fixed_size of the blocks.

Notions of "execution trace" and "arithmetization"

ExecutionTrace_ used to be the name for a purely static class that assists in proving key construction. We would have unclear lines of code that looked like ExecutionTrace_::populate(builder, proving_key) where it's not clear that is happening--which thing is being populated? The builder is not const, but could it be? Trying to constify took me down a rabbit hole that felt out of scope, so I still don't know. I renamed this class to TraceToPolynomials for clarity and because I wanted to use the name ExecutionTrace for the container of the blocks (In the end I went with ExecutionTraceBlocks) and metadata that used to be the Arithemetization.

Arithmetization (something I think I initially defined) is renamed to ExecutionTrace, broadly speaking. I removed some of the nested class definitions from MegaArith & UltraArith because I think it helps readability, and I flattened the nested TraceBlocks class into its container class which is now called FooTraceBlocks--I didn't see what the nesting gave us there.

Etc

To handle the NONE structure case, I use a std::optional.

ClientIVC gets a constructor from a TraceSettings and a boolean auto_verify_mode. Just a bit of cleanup--there were dozens of instances where this constructor was called for.

I remove some unused templating.

I don't see the value of having a fully public setter for a private value so I nixed set_fixed_size. This clarified the rather puzzling (to me) line
overflow_block.set_fixed_size(static_cast<uint32_t>(overflow_block.size()));

@codygunton codygunton self-assigned this Nov 15, 2024
@codygunton codygunton changed the title refactor: Trace structure from enum to object refactor: Trace structure is an object with a size Nov 15, 2024
@codygunton codygunton changed the title refactor: Trace structure is an object with a size refactor: Trace structure is an object Nov 15, 2024
Copy link
Contributor

@ledwards2225 ledwards2225 left a comment

Choose a reason for hiding this comment

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

Nice looks good. Just one alias that looked like it shouldn't be building..

fixed_sizes.set_fixed_block_sizes(trace_settings);

if (trace_settings.structure) {
info("yes trace structure");
Copy link
Contributor

Choose a reason for hiding this comment

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

stray info

uint32_t overflow_capacity = 0;
};

class MegaTraceBlock : public ExecutionTraceBlock<fr, 4, 14> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe at least inline comments indicating what these numbers are?

.overflow = 0 };

/**
* @brief A minimal structuring specifically tailored to the medium complexity transaction for the Cli: MentIVC
Copy link
Contributor

Choose a reason for hiding this comment

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

weird comment thing happening here

@@ -374,7 +374,7 @@ Accumulator ECCVMSetRelationImpl<FF>::compute_grand_product_denominator(const Al
}

/**
* @brief Expression for the StandardArithmetic gate.
* @brief Expression for the StandardExecutionTracemetic gate.
Copy link
Contributor

Choose a reason for hiding this comment

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

tracemetic, nice

@@ -123,8 +123,8 @@ template <typename RecursiveFlavor> class RecursiveVerifierTest : public testing
static void test_independent_vk_hash()
{
// Retrieves the trace blocks (each consisting of a specific gate) from the recursive verifier circuit
auto get_blocks = [](size_t inner_size)
-> std::tuple<typename OuterBuilder::GateBlocks, std::shared_ptr<typename OuterFlavor::VerificationKey>> {
auto get_blocks = [](size_t inner_size) -> std::tuple<typename OuterBuilder::ExeeuctionTrace,
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm how is this building? ExeeuctionTrace

@codygunton codygunton enabled auto-merge (squash) November 15, 2024 21:52
@codygunton codygunton merged commit 5f83755 into master Nov 15, 2024
71 checks passed
@codygunton codygunton deleted the cg/refactor-trace-structure branch November 15, 2024 22:35
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.

2 participants