Skip to content

Commit

Permalink
refactor: move functions to the new section
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Mar 6, 2023
1 parent 8b8174d commit 4aa1e2b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions constraints/miden-vm/bitwise.air
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
def BitwiseAir

# Enforces that column must be binary
ev check_binary(main: [a]):
enf a^2 - a = 0

# Returns value aggregated from limbs
fn aggregate(limb: vector[4]) -> scalar:
let result = sum([2^i * a for (i, a) in (0..4, limb)])
result


public_inputs:
stack_inputs: [16]

Expand All @@ -15,33 +25,24 @@ boundary_constraints:
enf dummy.first = 0

integrity_constraints:
# Enforces that column must be binary
ev check_binary(main: [a]):
enf a^2 - a = 0

# Returns value aggregated from limbs
fn aggregate(limb: vector[4]) -> scalar:
let result = sum([2^i * a for (i, a) in (0..4, limb)])
result

# Enforce that selector must be binary
enf check_binary(s)
enf check_binary([s])

# Enforce that selector should stay the same throughout the cycle.
enf k1 * (s' - s) = 0

# Enforce that the input is decomposed into valid bits
enf check_binary(a_limb[i]) for i in 0..4
enf check_binary(b_limb[i]) for i in 0..4
enf check_binary([a_limb[i]]) for i in 0..4
enf check_binary([b_limb[i]]) for i in 0..4

# Enforce that the value in the first row of column `a` of the current 8-row cycle should be
# the aggregation of the decomposed bit columns `a_limb`.
let a_aggr = aggregate(a_limb)
let a_aggr = aggregate([a_limb])
enf k0 * (a - a_aggr) = 0

# Enforce that the value in the first row of column `b` of the current 8-row cycle should be
# the aggregation of the decomposed bit columns `b_limb`.
let b_aggr = aggregate(b_limb)
let b_aggr = aggregate([b_limb])
enf k0 * (b - b_aggr) = 0

# Enforce that for all rows in an 8-row cycle, except for the last one, the values in a and b
Expand Down

0 comments on commit 4aa1e2b

Please sign in to comment.