forked from Consensys/gnark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snark_testing.go
37 lines (34 loc) · 1.01 KB
/
snark_testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package lzss
import (
"github.com/consensys/compress/lzss"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/compress"
test_vector_utils "github.com/consensys/gnark/std/utils/test_vectors_utils"
)
type DecompressionTestCircuit struct {
C []frontend.Variable
D []byte
Dict []byte
CBegin frontend.Variable
CLength frontend.Variable
CheckCorrectness bool
Level lzss.Level
}
func (c *DecompressionTestCircuit) Define(api frontend.API) error {
dict := test_vector_utils.ToVariableSlice(lzss.AugmentDict(c.Dict))
dBack := make([]frontend.Variable, len(c.D)) // TODO Try smaller constants
if cb, ok := c.CBegin.(int); !ok || cb != 0 {
c.C = compress.ShiftLeft(api, c.C, c.CBegin)
}
dLen, err := Decompress(api, c.C, c.CLength, dBack, dict, c.Level)
if err != nil {
return err
}
if c.CheckCorrectness {
api.AssertIsEqual(len(c.D), dLen)
for i := range c.D {
api.AssertIsEqual(c.D[i], dBack[i])
}
}
return nil
}