Skip to content

Commit

Permalink
Update byte_decomposition mode
Browse files Browse the repository at this point in the history
This updates the `byte_decomposition` model to use the
`fixedFunctionalModel`.  At this stage, more work needs to be done to
enable more useful testing, since there are no accepted traces for this
model which actually compute the desired function.
  • Loading branch information
DavePearce committed Oct 23, 2024
1 parent 688f1b4 commit 600b54e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 531,464 deletions.
22 changes: 13 additions & 9 deletions cmd/testgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Model struct {

var models []Model = []Model{
{"bit_decomposition", bitDecompositionModel},
{"byte_decomposition", fixedFunctionModel("ST", "CT", 2, byteDecompositionModel)},
{"byte_decomposition", fixedFunctionModel("ST", "CT", 4, byteDecompositionModel)},
{"memory", memoryModel},
{"word_sorting", wordSortingModel},
{"counter", functionalModel("STAMP", counterModel)},
Expand Down Expand Up @@ -337,15 +337,19 @@ func byteDecompositionModel(first uint, last uint, schema sc.Schema, trace tr.Tr
TWO_8 := fr.NewElement(256)
BYTE := findColumn(0, "BYTE", schema, trace).Data()
ARG := findColumn(0, "ARG", schema, trace).Data()
acc := fr.NewElement(0)
// Iterate elements
for i := first; i <= last; i++ {
byte := BYTE.Get(i)
arg := ARG.Get(i)
acc := add(mul(acc, TWO_8), byte)
// Check accumulator
if acc.Cmp(&arg) != 0 {
return false
}
}
//
arg_0 := ARG.Get(first)
arg_1 := ARG.Get(last)
byte_0 := BYTE.Get(first)
byte_1 := BYTE.Get(last)
// Check arg
val := add(mul(byte_0, TWO_8), byte_1)
//
return arg_0.Cmp(&byte_0) == 0 && arg_1.Cmp(&val) == 0
return true
}

func memoryModel(schema sc.Schema, trace tr.Trace) bool {
Expand Down
19 changes: 10 additions & 9 deletions testdata/byte_decomposition.accepts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ "ST": [], "CT": [], "BYTE": [], "ARG": [] }
{ "ST": [1], "CT": [0], "BYTE": [0], "ARG": [0] }
{ "ST": [1], "CT": [0], "BYTE": [123], "ARG": [123] }
{ "ST": [1,1], "CT": [0,1], "BYTE": [99,104], "ARG": [99,25448] }
{ "ST": [1,1,1], "CT": [0,1,2], "BYTE": [99,104,1], "ARG": [99,25448,6514689] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [0,0,0,0], "ARG": [0,0,0,0] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [1,0,0,0], "ARG": [1,256,65536,16777216] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [0,0,0,123], "ARG": [0,0,0,123] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [0,0,123,0], "ARG": [0,0,123,31488] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [0,0,99,104], "ARG": [0,0,99,25448] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [99,104,255,1], "ARG": [99,25448,6514943,1667825409] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [1,2,3,4], "ARG": [1,258,66051,16909060] }
{ "ST": [1,1,1,1], "CT": [0,1,2,3], "BYTE": [99,104,1,11], "ARG": [99,25448,6514689,1667760395] }
{ "ST": [1,1,1,1,1], "CT": [0,1,2,3,0], "BYTE": [1,2,3,4,5], "ARG": [1,258,66051,16909060,5] }
{ "ST": [1,1,1,1,1,1], "CT": [0,1,2,3,0,1], "BYTE": [1,2,3,4,5,6], "ARG": [1,258,66051,16909060,5,1286] }
{ "ST": [1], "CT": [1], "BYTE": [123], "ARG": [123] }
{ "ST": [1,1], "CT": [1,2], "BYTE": [123,2], "ARG": [123,31490] }
{ "ST": [1,1,1,1,1], "CT": [4,5,6,7,8], "BYTE": [1,2,3,4,5], "ARG": [1,258,66051,16909060,4328719365] }
{ "ST": [1,1,1,1,1,1,1,1], "CT": [0,1,2,3,0,1,2,3], "BYTE": [1,0,0,0,1,2,3,4], "ARG": [1,256,65536,16777216,1,258,66051,16909060] }
{ "ST": [1,1,1,1,1,1,1,1], "CT": [0,1,2,3,0,1,2,3], "BYTE": [0,0,99,104,99,104,1,11], "ARG": [0,0,99,25448,99,25448,6514689,1667760395] }
{ "ST": [0,1,1,1,1], "CT": [0,0,1,2,3], "BYTE": [123,0,0,0,0], "ARG": [0,0,0,0,0] }
Loading

0 comments on commit 600b54e

Please sign in to comment.