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

Support for basic arithmetic on constant values #968

Closed
hackaugusto opened this issue Jun 27, 2023 · 3 comments · Fixed by #1026
Closed

Support for basic arithmetic on constant values #968

hackaugusto opened this issue Jun 27, 2023 · 3 comments · Fixed by #1026
Assignees
Labels
assembly Related to Miden assembly enhancement New feature or request
Milestone

Comments

@hackaugusto
Copy link
Contributor

When describing a large system, like the stark verifier, there are a few constants that are related to each other. For example the memory addresses and their offsets. In these cases it is interesting to support basic arithmetic on the constants.

The idea is to both use these expressions as documentation, since they can express the relation among the constants, and as a tool to prevent bugs, since the assembler would compute the values for us.

@hackaugusto hackaugusto added the enhancement New feature or request label Jun 27, 2023
@hackaugusto
Copy link
Contributor Author

There are two questions I think are important to answer before knowing it is possible to implement the above:

  1. How is division handled? For example, when computing the number of words required to fit x elements a division by 4 is required. This division on the field element won't produce the expected output, perhaps an operator like // in python, that performs automatic rouding would be useful.
  2. How would such a feature interact with serialization/deserialization of the binary representation of the assembly? Should the binary representation have only the computed values, or should it restore to the original expressions?

@bobbinth
Copy link
Contributor

This would be a very useful feature. My thoughts on the two questions above:

  1. I like the idea of using // for integer division (and we can probably use / for field element division).
  2. Currently, this doesn't really matter as constants are not serialized at all (they are all inlined). If we do implement constant serialization, my preference would be to serialize computed values rather than expressions.

One other thing we should decide on is expression features and format. I'm assuming we want to support the usual operands: +, -, *, \, and \\. I'm assuming we'd also want to support parenthesis.

One restriction we have with the current parser is that we can't allow any whitespace in expressions. So, it would have to look something like:

const.A=3
const.B=A+2
const.C=A*B

But I think this should be OK.

@bobbinth
Copy link
Contributor

bobbinth commented Aug 5, 2023

Closed by #1026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assembly Related to Miden assembly enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants