complete changes
This commit is contained in:
parent
5c1a361619
commit
50be20e8ba
7 changed files with 67 additions and 68 deletions
|
@ -1,23 +1,17 @@
|
|||
def lt(field a,field b) -> (field):
|
||||
return if a < b then 1 else 0 fi
|
||||
def lt(field a,field b) -> (bool):
|
||||
return a < b
|
||||
|
||||
def cutoff() -> (field):
|
||||
return 31337
|
||||
|
||||
def getThing(field index) -> (field):
|
||||
field result = 3
|
||||
result = if index == 0 then 13 else result fi
|
||||
result = if index == 1 then 23 else result fi
|
||||
result = if index == 2 then 43 else result fi
|
||||
result = if index == 3 then 53 else result fi
|
||||
result = if index == 4 then 73 else result fi
|
||||
result = if index == 5 then 83 else result fi
|
||||
return result
|
||||
field[6] a = [13, 23, 43, 53, 73, 83]
|
||||
return a[index]
|
||||
|
||||
def cubeThing(field thing) -> (field):
|
||||
return thing**3
|
||||
|
||||
def main(field index) -> (field):
|
||||
def main(field index) -> (bool):
|
||||
field thing = getThing(index)
|
||||
thing = cubeThing(thing)
|
||||
return lt(cutoff(), thing)
|
||||
|
|
|
@ -6,7 +6,7 @@ import "hashes/utils/256bitsDirectionHelper" as multiplex
|
|||
|
||||
// Merke-Tree inclusion proof for tree depth 3 using SNARK efficient pedersen hashes
|
||||
// directionSelector=> 1/true if current digest is on the rhs of the hash
|
||||
def main(bool[256] rootDigest, private bool[256] leafDigest, private bool[3] directionSelector, bool[256] PathDigest0, private bool[256] PathDigest1, private bool[256] PathDigest2) -> (bool):
|
||||
def main(bool[256] rootDigest, private bool[256] leafDigest, private bool[3] directionSelector, bool[256] PathDigest0, private bool[256] PathDigest1, private bool[256] PathDigest2) -> ():
|
||||
BabyJubJubParams context = context()
|
||||
|
||||
//Setup
|
||||
|
@ -22,5 +22,7 @@ def main(bool[256] rootDigest, private bool[256] leafDigest, private bool[3] dir
|
|||
preimage = multiplex(directionSelector[2], currentDigest, PathDigest2)
|
||||
currentDigest = hash(preimage)
|
||||
|
||||
return rootDigest == currentDigest
|
||||
rootDigest == currentDigest
|
||||
|
||||
return
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import "utils/multiplexer/256bit" as multiplex
|
|||
|
||||
// Merkle-Tree inclusion proof for tree depth 3
|
||||
|
||||
def main(field treeDepth, bool[256] rootDigest, private bool[256] leafDigest, private bool[2] directionSelector, bool[256] PathDigest0, private bool[256] PathDigest1) -> (field):
|
||||
def main(field treeDepth, bool[256] rootDigest, private bool[256] leafDigest, private bool[2] directionSelector, bool[256] PathDigest0, private bool[256] PathDigest1) -> ():
|
||||
|
||||
//Setup
|
||||
bool[256] currentDigest = leafDigest
|
||||
|
@ -23,4 +23,7 @@ def main(field treeDepth, bool[256] rootDigest, private bool[256] leafDigest, pr
|
|||
currentDigest = sha256(lhs, rhs)
|
||||
counter = counter + 1
|
||||
|
||||
return counter == treeDepth && rootDigest == currentDigest
|
||||
counter == treeDepth
|
||||
rootDigest == currentDigest
|
||||
|
||||
return
|
|
@ -4,9 +4,9 @@
|
|||
// It should not work for the maxvalue = 2^(pbits - 2) - 1 augmented by one
|
||||
// /!\ should be called with a = 0
|
||||
|
||||
def main(field a) -> (field):
|
||||
def main(field a) -> (bool):
|
||||
field pbits = 254
|
||||
// maxvalue = 2**252 - 1
|
||||
field maxvalue = a + 7237005577332262213973186563042994240829374041602535252466099000494570602496 - 1
|
||||
// we added a = 0 to prevent the condition to be evaluated at compile time
|
||||
return if 0 < (maxvalue + 1) then 1 else 0 fi
|
||||
return 0 < (maxvalue + 1)
|
|
@ -1,7 +1,7 @@
|
|||
// as p - 1 is greater than p/2, comparing to it should fail
|
||||
// /!\ should be called with a = 0
|
||||
|
||||
def main(field a) -> (field):
|
||||
def main(field a) -> (bool):
|
||||
field p = 21888242871839275222246405745257275088548364400416034343698204186575808495617 + a
|
||||
// we added a = 0 to prevent the condition to be evaluated at compile time
|
||||
return if 0 < p - 1 then 1 else 0 fi
|
||||
return 0 < p - 1
|
|
@ -8,68 +8,68 @@
|
|||
// --------------------------
|
||||
// | c21 | c22 || d21 | d22 |
|
||||
|
||||
def checkEquality(field e11,field e12,field e21,field e22) -> (field):
|
||||
field counter = if e11 == e12 then 1 else 0 fi
|
||||
counter = counter + if e11 == e21 then 1 else 0 fi
|
||||
counter = counter + if e11 == e22 then 1 else 0 fi
|
||||
counter = counter + if e12 == e21 then 1 else 0 fi
|
||||
counter = counter + if e12 == e21 then 1 else 0 fi
|
||||
counter = counter + if e21 == e22 then 1 else 0 fi
|
||||
return counter
|
||||
// We use a naive encoding of the values as `[1, 2, 3, 4]` and rely on if-else statements to detect duplicates
|
||||
|
||||
def countDuplicates(field e11,field e12,field e21,field e22) -> (field):
|
||||
field duplicates = if e11 == e12 then 1 else 0 fi
|
||||
duplicates = duplicates + if e11 == e21 then 1 else 0 fi
|
||||
duplicates = duplicates + if e11 == e22 then 1 else 0 fi
|
||||
duplicates = duplicates + if e12 == e21 then 1 else 0 fi
|
||||
duplicates = duplicates + if e12 == e21 then 1 else 0 fi
|
||||
duplicates = duplicates + if e21 == e22 then 1 else 0 fi
|
||||
return duplicates
|
||||
|
||||
// returns 0 for x in (1..4)
|
||||
def validateInput(field x) -> (field):
|
||||
return (x-1)*(x-2)*(x-3)*(x-4)
|
||||
return (x-1)*(x-2)*(x-3)*(x-4)
|
||||
|
||||
// variables naming: box'row''column'
|
||||
def main(field a21, field b11, field b22, field c11, field c22, field d21, private field a11, private field a12, private field a22, private field b12, private field b21, private field c12, private field c21, private field d11, private field d12, private field d22) -> (field):
|
||||
def main(field a21, field b11, field b22, field c11, field c22, field d21, private field a11, private field a12, private field a22, private field b12, private field b21, private field c12, private field c21, private field d11, private field d12, private field d22) -> (bool):
|
||||
|
||||
// validate inputs
|
||||
0 == validateInput(a11)
|
||||
0 == validateInput(a12)
|
||||
0 == validateInput(a21)
|
||||
0 == validateInput(a22)
|
||||
// validate inputs
|
||||
0 == validateInput(a11)
|
||||
0 == validateInput(a12)
|
||||
0 == validateInput(a21)
|
||||
0 == validateInput(a22)
|
||||
|
||||
0 == validateInput(b11)
|
||||
0 == validateInput(b12)
|
||||
0 == validateInput(b21)
|
||||
0 == validateInput(b22)
|
||||
0 == validateInput(b11)
|
||||
0 == validateInput(b12)
|
||||
0 == validateInput(b21)
|
||||
0 == validateInput(b22)
|
||||
|
||||
0 == validateInput(c11)
|
||||
0 == validateInput(c12)
|
||||
0 == validateInput(c21)
|
||||
0 == validateInput(c22)
|
||||
0 == validateInput(c11)
|
||||
0 == validateInput(c12)
|
||||
0 == validateInput(c21)
|
||||
0 == validateInput(c22)
|
||||
|
||||
0 == validateInput(d11)
|
||||
0 == validateInput(d12)
|
||||
0 == validateInput(d21)
|
||||
0 == validateInput(d22)
|
||||
0 == validateInput(d11)
|
||||
0 == validateInput(d12)
|
||||
0 == validateInput(d21)
|
||||
0 == validateInput(d22)
|
||||
|
||||
field counter = 0 // globally counts duplicate entries in boxes, rows and columns
|
||||
field duplicates = 0 // globally counts duplicate entries in boxes, rows and columns
|
||||
|
||||
// check box correctness
|
||||
// check box correctness
|
||||
|
||||
// no duplicates
|
||||
counter = counter + checkEquality(a11,a12,a21,a22)
|
||||
counter = counter + checkEquality(b11,b12,b21,b22)
|
||||
counter = counter + checkEquality(c11,c12,c21,c22)
|
||||
counter = counter + checkEquality(d11,d12,d21,d22)
|
||||
duplicates = duplicates + countDuplicates(a11,a12,a21,a22)
|
||||
duplicates = duplicates + countDuplicates(b11,b12,b21,b22)
|
||||
duplicates = duplicates + countDuplicates(c11,c12,c21,c22)
|
||||
duplicates = duplicates + countDuplicates(d11,d12,d21,d22)
|
||||
|
||||
// check row correctness
|
||||
// check row correctness
|
||||
|
||||
counter = counter + checkEquality(a11,a12,b11,b12)
|
||||
counter = counter + checkEquality(a21,a22,b21,b22)
|
||||
counter = counter + checkEquality(c11,c12,d11,d12)
|
||||
counter = counter + checkEquality(c21,c22,d21,d22)
|
||||
duplicates = duplicates + countDuplicates(a11,a12,b11,b12)
|
||||
duplicates = duplicates + countDuplicates(a21,a22,b21,b22)
|
||||
duplicates = duplicates + countDuplicates(c11,c12,d11,d12)
|
||||
duplicates = duplicates + countDuplicates(c21,c22,d21,d22)
|
||||
|
||||
// check column correctness
|
||||
// check column correctness
|
||||
|
||||
counter = counter + checkEquality(a11,a21,c11,c21)
|
||||
counter = counter + checkEquality(a12,a22,c12,c22)
|
||||
counter = counter + checkEquality(b11,b21,d11,d21)
|
||||
counter = counter + checkEquality(b12,b22,d12,d22)
|
||||
duplicates = duplicates + countDuplicates(a11,a21,c11,c21)
|
||||
duplicates = duplicates + countDuplicates(a12,a22,c12,c22)
|
||||
duplicates = duplicates + countDuplicates(b11,b21,d11,d21)
|
||||
duplicates = duplicates + countDuplicates(b12,b22,d12,d22)
|
||||
|
||||
// assert counter is 0
|
||||
counter == 0
|
||||
|
||||
return 1
|
||||
// the solution is correct if and only if there are no duplicates
|
||||
return duplicates == 0
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
// we can compare numbers up to 2^(pbits - 2) - 1, ie any number which fits in (pbits - 2) bits
|
||||
// lt should work for the maxvalue = 2^(pbits - 2) - 1
|
||||
|
||||
def main(field a) -> (field):
|
||||
def main(field a) -> (bool):
|
||||
field pbits = 254
|
||||
// maxvalue = 2**252 - 1
|
||||
field maxvalue = 7237005577332262213973186563042994240829374041602535252466099000494570602496 - 1
|
||||
return if 0 < maxvalue then 1 else 0 fi
|
||||
return 0 < maxvalue
|
Loading…
Reference in a new issue