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

Write chiplet module constraints in AirScript #253

Merged
merged 4 commits into from
May 30, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions constraints/miden-vm/chiplets.air
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
mod ChipletsConstraintsAir

use bitwise::bitwise_chiplet
use hash::hash_chiplet
use memory::memory_chiplet
grjte marked this conversation as resolved.
Show resolved Hide resolved

### Helper evaluators #############################################################################

# Enforces that the provided columns must be binary.
ev is_binary(main: [a]):
enf a^2 = a

# Enforces that the chiplet selector columns are set correctly.
enf chiplet_selectors(main: [s[3]]):
Fumuran marked this conversation as resolved.
Show resolved Hide resolved
# Enforce that selectors are binary.
enf is_binary([s[0]])
enf is_binary([s[1]]) when s[0]
enf is_binary([s[2]]) when s[0] & s[1]

# Enforce that the chiplets are stacked correctly by restricting selector values so they can
# only change from 0 to 1.
enf s[0]' = s[0] when s[0]
enf s[1]' = s[1] when s[0] & s[1]
enf s[2]' = s[2] when s[0] & s[1] & s[2]


### Chiplets Constraints ##########################################################################

ev chiplets(main: [s[3], chiplet_columns[15]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it would be good to have a comment here.

enf chiplet_selectors([s])
match enf:
hash_chiplet([s[1], s[2], chiplet_columns]) when !s[0]
bitwise_chiplet([s[2], chiplet_columns]) when s[0] & !s[1]
memory_chiplet([chiplet_columns]) when s[0] & s[1] & !s[2]'