Skip to content

Conversation

@DavePearce
Copy link
Collaborator

@DavePearce DavePearce commented Apr 2, 2025

No description provided.

@DavePearce DavePearce force-pushed the 630-upgrade-go-corset-to-v11 branch 2 times, most recently from 42b0110 to 5de0208 Compare April 2, 2025 22:35
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.
@DavePearce DavePearce force-pushed the 630-upgrade-go-corset-to-v11 branch from b3bfe42 to 8eea0e1 Compare April 16, 2025 02:35
@DavePearce DavePearce force-pushed the 630-upgrade-go-corset-to-v11 branch from 8eea0e1 to d5f1ff0 Compare April 16, 2025 20:08
;; trigger_MMU == 0
(eq! FLAG MISC_WEIGHT_MXP)
;; trigger_MMU == 1
(eq! FLAG (+ MISC_WEIGHT_MXP MISC_WEIGHT_MMU)))))
Copy link
Collaborator

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.

Copy link
Collaborator Author

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)))
Copy link
Collaborator

@OlivierBBB OlivierBBB Apr 23, 2025

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.

Copy link
Collaborator Author

@DavePearce DavePearce Apr 23, 2025

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@DavePearce DavePearce Apr 23, 2025

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

Copy link
Collaborator

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.

Copy link
Collaborator

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 ...

Copy link
Collaborator Author

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 ;)

Copy link
Collaborator Author

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.

Copy link
Collaborator

@OlivierBBB OlivierBBB left a 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).
@DavePearce DavePearce force-pushed the 630-upgrade-go-corset-to-v11 branch from d5f1ff0 to 7b8b314 Compare April 28, 2025 08:04
@DavePearce DavePearce merged commit cbc6bcb into master Apr 28, 2025
3 checks passed
@DavePearce DavePearce deleted the 630-upgrade-go-corset-to-v11 branch April 28, 2025 08:06
OlivierBBB pushed a commit that referenced this pull request Jun 9, 2025
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).
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