From 256e069bb40739520adfb20bdedb622701399ca0 Mon Sep 17 00:00:00 2001 From: Gautam Botrel Date: Mon, 8 Jan 2024 15:45:43 -0600 Subject: [PATCH] feat: update compress version; failing test (resolved) (#979) * test: highlight failing test -> resolved * build: update compress version * build: update to compress v0.2.0 * build upgrade compress dependency * fix compression mode at byte 2 --------- Co-authored-by: Arya Tabaie --- go.mod | 2 +- go.sum | 6 ++++-- std/compress/lzss/snark.go | 10 ++++++---- std/compress/lzss/snark_test.go | 5 +++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index ff34417136..2acc9523bb 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/bits-and-blooms/bitset v1.8.0 github.com/blang/semver/v4 v4.0.0 github.com/consensys/bavard v0.1.13 - github.com/consensys/compress v0.1.0 + github.com/consensys/compress v0.2.1-0.20240103160955-e4fcce3dc96a github.com/consensys/gnark-crypto v0.12.2-0.20231221171913-5d5eded6bb15 github.com/fxamacker/cbor/v2 v2.5.0 github.com/google/go-cmp v0.5.9 diff --git a/go.sum b/go.sum index 138bb12567..d11680dab2 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,10 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= -github.com/consensys/compress v0.1.0 h1:fczDaganmx2198GudPo4+5VX3eBvKy/bEJfmNotbr70= -github.com/consensys/compress v0.1.0/go.mod h1:Ne8+cGKjqgjF1dlHapZx38pHzWpaBYhsKxQa+JPl0zM= +github.com/consensys/compress v0.2.0 h1:aBg3YJe8ZFUxm/RF+ppx/URFsZq3aJ6o8isLDQysYDA= +github.com/consensys/compress v0.2.0/go.mod h1:Ne8+cGKjqgjF1dlHapZx38pHzWpaBYhsKxQa+JPl0zM= +github.com/consensys/compress v0.2.1-0.20240103160955-e4fcce3dc96a h1:0Y7y1JXtP8O/nL7LHpBt62pGZ87so63uWrYqUoq920s= +github.com/consensys/compress v0.2.1-0.20240103160955-e4fcce3dc96a/go.mod h1:Ne8+cGKjqgjF1dlHapZx38pHzWpaBYhsKxQa+JPl0zM= github.com/consensys/gnark-crypto v0.12.2-0.20231221171913-5d5eded6bb15 h1:mcxhrDtXKIepsKXofxSuXRst+41yzAcoNWKIotsjMTQ= github.com/consensys/gnark-crypto v0.12.2-0.20231221171913-5d5eded6bb15/go.mod h1:wKqwsieaKPThcFkHe0d0zMsbHEUWFmZcG7KBCse210o= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= diff --git a/std/compress/lzss/snark.go b/std/compress/lzss/snark.go index 198cb739df..3ac58fabe4 100644 --- a/std/compress/lzss/snark.go +++ b/std/compress/lzss/snark.go @@ -25,13 +25,15 @@ func Decompress(api frontend.API, c []frontend.Variable, cLength frontend.Variab dictBrNbWords := int(dictBackRefType.NbBitsBackRef) / wordNbBits byteNbWords := 8 / wordNbBits - api.AssertIsEqual(compress.ReadNum(api, c, byteNbWords, wordNbBits), 0) // compressor version TODO @tabaie @gbotrel Handle this outside the circuit instead? - fileCompressionMode := compress.ReadNum(api, c[byteNbWords:], byteNbWords, wordNbBits) + const sizeHeader = 3 // TODO @tabaie @gbotrel Handle this outside the circuit instead + + api.AssertIsEqual(compress.ReadNum(api, c, (sizeHeader-1)*byteNbWords, wordNbBits), 0) // compressor version TODO @tabaie @gbotrel Handle this outside the circuit instead? + fileCompressionMode := compress.ReadNum(api, c[(sizeHeader-1)*byteNbWords:], byteNbWords, wordNbBits) api.AssertIsEqual(api.Mul(fileCompressionMode, fileCompressionMode), api.Mul(fileCompressionMode, wordNbBits)) // if fcm!=0, then fcm=wordNbBits decompressionNotBypassed := api.Sub(1, api.IsZero(fileCompressionMode)) - c = c[2*byteNbWords:] - cLength = api.Sub(cLength, 2*byteNbWords) + c = c[sizeHeader*byteNbWords:] + cLength = api.Sub(cLength, sizeHeader*byteNbWords) outTable := logderivlookup.New(api) for i := range dict { diff --git a/std/compress/lzss/snark_test.go b/std/compress/lzss/snark_test.go index 9de006de57..f9ffcd1159 100644 --- a/std/compress/lzss/snark_test.go +++ b/std/compress/lzss/snark_test.go @@ -1,6 +1,9 @@ package lzss import ( + "os" + "testing" + goCompress "github.com/consensys/compress" "github.com/consensys/compress/lzss" "github.com/consensys/gnark-crypto/ecc" @@ -10,8 +13,6 @@ import ( "github.com/consensys/gnark/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "os" - "testing" ) func Test1ZeroSnark(t *testing.T) {