Skip to content

Conversation

chriseth
Copy link
Member

No description provided.

@chriseth chriseth changed the title Terminology Optimizer Documentation: Terminology Oct 13, 2025
Comment on lines 53 to 55
a superset of the set of allowed values. This means we can only use
the information if the Range Constraints says that a value is not
allowed. This also makes sense since we are looking at Algebraic
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this part a bit vague.

Comment on lines 62 to 71
A _Wrapping Interval_ is a pair of field elements `min` and `max`.
If `min <= max` (as seen in the natural numbers), the Wrapping
Interval allows a value `x` if and only if `min <= x <= max`.
This is the non-wrapping case.
If `min > max`, the Wrapping Interval allows a value `x`
if and only if `x >= min` or `x <= max`. This is the wrapping case.

The reason we allow these wrapping intervals is that we can compute
the Range Constraint interval of an expression `x + k` for any constant `k`
from the Range Constraint interval of `x` without losing information.
Copy link
Collaborator

@Schaeff Schaeff Oct 14, 2025

Choose a reason for hiding this comment

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

Do wrapping and non-wrapping intervals ever interact? I see the argument that you can define addition (and multiplication?) on intervals in a unified way, but I'm not sure it's worth it given the non-intuitive aspect of min > max being okay. Would it be possible to use an enum enum Interval { Inside { min, max }, Outside { min, max } and define addition and multiplication on that instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, it could be done that way, but then you would need to verify in addition that min <= max is always ensured.

Another way we could do it is just to have first and length, and a value x is in range if it included in the sequence first, first + 1, first + 2, ..., first + length (and if length = 0, we would be able to model the empty range, which we cannot do currently).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, first and length sound good

Copy link
Member Author

Choose a reason for hiding this comment

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

I just checked and I think it's at least 2-3 days work to change it, if not a week. I'll focus on documenting for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for checking!

lookup tables are not stateful.

- `handle_bus_interaction`: Takes a Bus Interaction where its items are represented
by Range Constraints instead of expressions or field elements and returns
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does or apply to here?

Copy link
Member Author

@chriseth chriseth Oct 14, 2025

Choose a reason for hiding this comment

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

I can remove or field elements if it creates confusion instead of clarifying things ;)

Copy link
Member

Choose a reason for hiding this comment

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

yea I guess instead of expressions suffices

Comment on lines 134 to 138
parts of the system. A simple (and also best possible) implementation of
`handle_bus_interaction` would be to always return the `0xff`-mask Range Constraint
for the payload and ignore the input. Even if the input Range Constraint is something
like `200..=300`, the solver will combine the two Range Constraints and derive
`200..=255` as the new Range Constraint for the payload.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is 0xff the best implementation? Isn't it the one that mixes the input constraint with the bus constraint? Seems like this part mixes the naive implementation and what we do?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really understand what you mean. Of course this document does not say what a "good" implementation is, so we cannot tell if it is the best possible. What implementation would you say is better and why? What do you mean by "naive implementation" and what do we do?

Copy link
Member

Choose a reason for hiding this comment

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

I think he's referring to the beginning of the par which does say (and also best possible)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean that the first part of this section talks about one strategy of always returning 0xff, while the second talks about combining range constraints.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh maybe the word 'input' is confusing?

Comment on lines 145 to 146
Since our Range Constraints do not model individual bits well enough, it is sufficient
to only compute the third item if two of them are fully known.
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't understand this

Copy link
Member

Choose a reason for hiding this comment

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

I think the "it is sufficient" part here is what sounds a bit odd to me. Sufficient for what? From the text before it sounds like it's rather not sufficient for a full analysis.

Copy link
Collaborator

@Schaeff Schaeff left a comment

Choose a reason for hiding this comment

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

really good introduction

chriseth and others added 4 commits October 14, 2025 16:22
Co-authored-by: Thibaut Schaeffer <[email protected]>
Co-authored-by: Thibaut Schaeffer <[email protected]>
Co-authored-by: Thibaut Schaeffer <[email protected]>
Copy link
Member

@leonardoalt leonardoalt left a comment

Choose a reason for hiding this comment

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

First pass, need to continue from Bus Interaction Abstraction

The task of the optimizer is hugely simplified by the concept of
_Range Constraints_. In an abstract way, a _Range Constraint_ is
the set of possible values for a specific algebraic expression.
The solver can derive new Range Constraints from Algebraic Constraints
Copy link
Member

Choose a reason for hiding this comment

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

This is the first time solver is used, it'd be good to refer to something or define it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it to optimizer


In our concrete implementation, we do not represent the exact set
of allowed values. Instead, we use an under-approximation, i.e.
a superset of the set of allowed values. This means we can only use
Copy link
Member

Choose a reason for hiding this comment

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

That would be an overapproximation, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

True!

In our concrete implementation, we do not represent the exact set
of allowed values. Instead, we use an under-approximation, i.e.
a superset of the set of allowed values. This means we can only use
the information if the Range Constraints says that a value is not
Copy link
Member

Choose a reason for hiding this comment

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

I think I do understand this part, but what's unclear here is "use for what"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Clarified

We use `RC(x)` to denote the Range Constraint of an algebraic
expression `x`.

TODO It is not clear if this is the currently best-known range constraint,
Copy link
Member

Choose a reason for hiding this comment

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

TODO as in for this PR or the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

semantics of a bus interaction depends on the environment, i.e. the
zkVM we are operating inside and the chips it has.

A _Bus Interaction_ consists of a _Bus ID_, a _Multiplicity_ and
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it makes sense to introduce it as a relation or predicate here? I think that could help abstract it

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you give an example?

Copy link
Member

@leonardoalt leonardoalt left a comment

Choose a reason for hiding this comment

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

Done now.

lookup tables are not stateful.

- `handle_bus_interaction`: Takes a Bus Interaction where its items are represented
by Range Constraints instead of expressions or field elements and returns
Copy link
Member

Choose a reason for hiding this comment

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

yea I guess instead of expressions suffices


As an example, let us assume we are modeling a bus that implements a byte range
constraint, i.e. a bus that takes a single payload item and enforces that it is
in the range `0..=255`. The bus is not stateful since it does not depend on any
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
in the range `0..=255`. The bus is not stateful since it does not depend on any
in the range `0..=255`. The bus is not stateful since it does not depend on nor affects any

parts of the system. A simple (and also best possible) implementation of
`handle_bus_interaction` would be to always return the `0xff`-mask Range Constraint
for the payload and ignore the input. Even if the input Range Constraint is something
like `200..=300`, the solver will combine the two Range Constraints and derive
Copy link
Member

Choose a reason for hiding this comment

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

solver also undefined up to here

Comment on lines 134 to 138
parts of the system. A simple (and also best possible) implementation of
`handle_bus_interaction` would be to always return the `0xff`-mask Range Constraint
for the payload and ignore the input. Even if the input Range Constraint is something
like `200..=300`, the solver will combine the two Range Constraints and derive
`200..=255` as the new Range Constraint for the payload.
Copy link
Member

Choose a reason for hiding this comment

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

I think he's referring to the beginning of the par which does say (and also best possible)

Another example would be an XOR-bus that takes three payload items `a, b, c`
and ensures that all of them are bytes and `a ^ b = c`. This bus is also not stateful.
Here, one would implement `handle_bus_interaction` by returning the three byte constraints
for the payload items if the input has no restrictiens. But if the value of the same bit
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for the payload items if the input has no restrictiens. But if the value of the same bit
for the payload items if the input has no restrictions. But if the value of the same bit

Comment on lines 145 to 146
Since our Range Constraints do not model individual bits well enough, it is sufficient
to only compute the third item if two of them are fully known.
Copy link
Member

Choose a reason for hiding this comment

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

I think the "it is sufficient" part here is what sounds a bit odd to me. Sufficient for what? From the text before it sounds like it's rather not sufficient for a full analysis.

- exhaustive search
- equal zero check

### Constraint System Solver
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this section could be moved to the top to clarify what the instances of solver above mean.

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