-
Notifications
You must be signed in to change notification settings - Fork 21
feat: upgrade go corset to v11 #636
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
Conversation
42b0110 to
5de0208
Compare
This version of `go-corset` is much stricter than previous versions. In particular, there is essentially no longer a distinction between loobean and boolean. As such, managing this transition requires treading carefully. This update does not fully complete the transition, but it is a very big step.
This rewrite is necessary to fit the new requirements around conditionals. However, it is slightly less efficient as produces at least two constraints, versus only one for the original.
This rewrites one case of this constraint into a more friendly form for go-corset. This is less efficient, in that it produces one more constraint. However, at the same time, it reads exactly like the specification.
This applies three new translations to the mxp module to handle cases where `is-zero` (which has now been dropped) was being used. The resulting translations are all improvements with no additional overhead.
This rewrites the translation of this constraint to avoid use of `is-not-zero` (which has now been dropped). The resulting translation is clearer, but does introduce some inefficiency (i.e. generates 3 constraints rather than just 1).
This fixes / tweaks two problematic constraints.
This removes attempts to define control-flow constructs within the constraints themselves.
b3bfe42 to
8eea0e1
Compare
8eea0e1 to
d5f1ff0
Compare
| ;; trigger_MMU == 0 | ||
| (eq! FLAG MISC_WEIGHT_MXP) | ||
| ;; trigger_MMU == 1 | ||
| (eq! FLAG (+ MISC_WEIGHT_MXP MISC_WEIGHT_MMU))))) |
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.
I will say I find the usage of or unfamiliar but it works.
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.
Hmmmm, we probably could write it so that it looks exactly like it does in the spec using three cases with the AND for the third case.
| ;; no change | ||
| (remained-constant! ABS_TX_NUM) | ||
| ;; increment | ||
| (did-inc! ABS_TX_NUM 1))) |
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.
What is the idea behind converting constraints à la
(= X (+ Y (binary-value))to
(if (binary-value)
(= X (+ Y 1))
(= X Y)
)AFAICT this was done in hub/constraints/instruction-handling/halting/revert.lisp, too. The underlying constraint is different (though equivalent) and has a higher degree:
// old approach
0 = X - Y - (binary-value) // degree = max{ 1, degree (binary-value) }
// new approach
0 = (binary-value) * (X - Y - 1) + (1 - (binary-value)) * (X - Y) // degree = 1 + degree (binary-value)Also it deviates from the spec which may end up causing confusion in the future.
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.
What is the idea behind converting constraints à la
The issue is to do with the structuring that go-corset imposes. It distinguishes "logical values" from general arithmetic values. For example, (== X 1) returns a logical value (of the bool type) where as say (+ X 1) returns an arithmetic value (of the int type). Constraints require logical values, as do if conditions. So you cannot write this:
(defcolumns (X :i16))
(defconstraint c1 () X)
Instead, you are forced to write this:
(defcolumns (X :i16))
(defconstraint c1 () (== X 0))
Likewise, you cannot mix logical and arithmetical values arbitrarily as you did before. So, you cannot do this:
(defconstraint c1 () (== X (== Y 1))
Because the operands of == are expected to be arithmetic values, not logical values.
Going back to the original constraint, the issue is that remained-constant! returns a logical value, and hence cannot be used in the position it was. So I refactored to avoid that.
Also it deviates from the spec which may end up causing confusion in the future.
Personally, I would suggest that the original presentation is much harder to understand and is a potential source of confusion itself. The logical presentation (whilst potentially less efficient) is much easy to read and follow. So, if it were me, I would just change the spec to match.
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.
I should add that in theory go-corset could actually apply the optimisation itself when applicable. However, right now --- it does not.
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.
And, the whole purpose of all this is to make explicit when equality is being used (as opposed to -) and, likewise, when logical or and logical and are being used (as opposed to * and +). That is, for field agnosticity.
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.
Also, just to clarify. Isn't this the wrong way around:
(= X (+ Y (binary-value))
to
(if (binary-value)
(= X (+ Y 1))
(= X Y)
)
Here, when binary-value==0 we want (= X Y) ... right? Anyway, it does't matter as I get the point.
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.
Also, just thinking about this comment:
0 = (binary-value) * (X - Y - 1) + (1 - (binary-value)) * (X - Y)
Firstly, see my slack message on linea-arithmetisation about how the original corset tool handles if.
Secondly, assuming we translate as above ... then this will multiply out and simplify when turned into a polynomial, meaning its identical. At least that would be my understanding. Something like this:
0 = bv * (X - Y - 1) + (1 - bv) * (X - Y)
==> bv.X - bv.Y - bv + X - Y - bv.X + bv.Y
==> X - Y - bv
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.
then this will multiply out and simplify when turned into a polynomial, meaning its identical
This may be the case, I don't know whether corset does such algebraic manipulations under the hood. My assumption was that it doesn't, it just takes takes the constraint as is. We would certainly benefit from go-corset doing this expansion in this particular case.
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.
So boolean / loobean is gone but we now have numerical and logical columns. I'm ok with that, especially if it simplifies FV work and allows us to talk with AND's and OR's etc ...
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.
You got it --- its gone, but not quite gone ;)
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.
This may be the case, I don't know whether corset does such algebraic manipulations under the hood.
Go-corset doesn't at the moment (though it could for sure), but I actually think the prover might do this already. They do a fair bit of work simplifying constraints.
OlivierBBB
left a comment
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.
LGTM but I'm confused as to a couple of changes mentioned in comments
This updates `go-corset` to the latest release which removes the notion of loobean, and replaces it with a clear distinction between logical conditions and integer values. In particular, this adds the operators `==` and `!=` along with true notions of logical or and logical and. This also includes relational operators (e.g. `<` and `<=`) which can be used in constrant expresions (only).
d5f1ff0 to
7b8b314
Compare
This updates `go-corset` to the latest release which removes the notion of loobean, and replaces it with a clear distinction between logical conditions and integer values. In particular, this adds the operators `==` and `!=` along with true notions of logical or and logical and. This also includes relational operators (e.g. `<` and `<=`) which can be used in constrant expresions (only).
No description provided.