-
Notifications
You must be signed in to change notification settings - Fork 856
Research ways to make usage of ConstraintBuilder more readable #1115
Comments
Here are some ideas to research:
|
Wrote some docs about the tools I use in the MPT circuits here: #972 (comment). I also think there are a lot ways to make writing circuits better, which will automatically lead to more code reuse. I think it makes a lot of sense to use these tools in other circuits as well (I made them so they do not contain any MPT specific code so they can be reused everywhere), especially the more simple circuits that do not yet contain a lot of abstractions to make them easier to understand. I only focused on the constraints part for now because that's way I needed, but something like a generalized CellManager is I think possible as well so that the circuit layout part is also easier to manage for all circuits. |
Here a proposal: https://hackmd.io/@leolara/getting-rid-halo2-meta |
Another nice thing with exposing higher level control flow blocks like
the CellManager automatically knows it can allocate |
I think my main point is, what makes this code for example difficult to read?
In my opinion, it is the column queries and having to refer to these methods in meta and Rotation. If we could write them like this:
That makes the most difference. We can have the macros that wrap contraint expressions to make it even more readable, but for me this change makes all the difference. Note: we would need a method that wraps meta.create_gate in order to "inject" the gate meta to the column queries. Because we are wrapping the columns on a new type, we can add to it the constrain operators, like 'equal' or
In my opinion there is no advance in readability if there is no replacement for the columns queries. I see in the macros solution there are macros |
Totally agreed that the querying is one the main problems for readability. The only reason it's necessary to the query in the first place is because of the query index, which is not something you care about while writing the circuits, I believe it should be possible to just set those query indices on the halo2 side when it receives the expressions instead of having to rely on people writing circuits to have to manually query each cell themselves. I briefly tried to modify halo2 to do just that, but it was more work than expected so gave up and just decided to go with the macro route for now. We may want to still wrap things on the zk-evm side, but I think it makes sense to modify halo2 to already do a lot of this stuff (like |
This issue is not only about readability of a particular block of code, but also about code organization and abstraction boundaries. Say we want to split a big chip into two smaller chips, each with its bounded responsibilities and some interface between them. That will require the chips to accept or expose Queries (column, rotation), or Expression. But we are not allowed to do that, because these objects are made available inside of the Alternatively, one can steal the queries and expressions from the closure ( Another problem is that the queries are not stored in the configuration and available to synthesis. So developers have to reproduce the layout of rotations using hard-coded offset logic (example: These problems can be solved by not requiring to work in a closure, and making the cells and expressions officially objects to be passed around across chips, functions, modules, config structs, etc. This will let developers organize code in any programming style appropriate to each task. Here is an experiment about splitting code into decoupled chips. This is done by stealing queries (code). Then chips can accept and return Cells and Expressions (example). This is similar to what the EVM circuit does as well, so that looks like a good direction. |
Closing due to inactivity. I believe there's been some work related to this issue in the macro system that @Brechtpd made for the MPT circuit. Once it reaches main we can discuss it to see if we would like to extend it's usage to the rest of the circuits to achieve making the ConstraintBuilder more readable. |
* doc for eip EIP2930_1559 * add 1559 gadget * modify md format
The focus should be in avoiding code repetition and simplifying the code base
Update: we can use this issue to discuss ways to make the usage of the Constraint Builder more readable.
The text was updated successfully, but these errors were encountered: