@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/consensys/gnark-crypto/ecc"
12
12
"github.com/consensys/gnark/frontend"
13
+ "github.com/consensys/gnark/frontend/cs/scs"
13
14
zkhash "github.com/consensys/gnark/std/hash"
14
15
"github.com/consensys/gnark/std/math/uints"
15
16
"github.com/consensys/gnark/test"
@@ -158,12 +159,12 @@ func TestSHA3FixedLengthSum(t *testing.T) {
158
159
}
159
160
160
161
const (
161
- minLen = 299
162
- maxLen = 310
162
+ minLen = 1680
163
+ maxLen = 1710
163
164
)
164
165
165
166
type sha3FixedLengthSumWithMinLenCircuit struct {
166
- In [maxLen ]uints.U8
167
+ In []uints.U8
167
168
Expected []uints.U8
168
169
Length frontend.Variable
169
170
hasher string
@@ -182,7 +183,7 @@ func (c *sha3FixedLengthSumWithMinLenCircuit) Define(api frontend.API) error {
182
183
if err != nil {
183
184
return err
184
185
}
185
- h .Write (c .In [:] )
186
+ h .Write (c .In )
186
187
res := h .FixedLengthSum (minLen , c .Length )
187
188
188
189
for i := range c .Expected {
@@ -207,13 +208,13 @@ func TestSHA3FixedLengthSumWithMinLen(t *testing.T) {
207
208
h .Write (in [:length ])
208
209
expected := h .Sum (nil )
209
210
210
- circuit := & sha3FixedLengthSumCircuit {
211
+ circuit := & sha3FixedLengthSumWithMinLenCircuit {
211
212
In : make ([]uints.U8 , maxLen ),
212
213
Expected : make ([]uints.U8 , len (expected )),
213
214
hasher : name ,
214
215
}
215
216
216
- witness := & sha3FixedLengthSumCircuit {
217
+ witness := & sha3FixedLengthSumWithMinLenCircuit {
217
218
In : uints .NewU8Array (in ),
218
219
Expected : uints .NewU8Array (expected ),
219
220
Length : length ,
@@ -227,3 +228,35 @@ func TestSHA3FixedLengthSumWithMinLen(t *testing.T) {
227
228
}, fmt .Sprintf ("hash=%s" , name ))
228
229
}
229
230
}
231
+
232
+ func Test_SHA3FixedLengthSum_WithMinLen_VS_Zero (t * testing.T ) {
233
+ assert := test .NewAssert (t )
234
+
235
+ for name := range testCases {
236
+ name := name
237
+ strategy := testCases [name ]
238
+ h := strategy .native ()
239
+ sumLen := h .Size ()
240
+
241
+ circuit1 := & sha3FixedLengthSumCircuit {
242
+ In : make ([]uints.U8 , maxLen ),
243
+ Expected : make ([]uints.U8 , sumLen ),
244
+ hasher : name ,
245
+ }
246
+
247
+ cs1 , err := frontend .Compile (ecc .BN254 .ScalarField (), scs .NewBuilder , circuit1 )
248
+ assert .NoError (err )
249
+
250
+ circuit2 := & sha3FixedLengthSumWithMinLenCircuit {
251
+ In : make ([]uints.U8 , maxLen ),
252
+ Expected : make ([]uints.U8 , sumLen ),
253
+ hasher : name ,
254
+ }
255
+
256
+ cs2 , err := frontend .Compile (ecc .BN254 .ScalarField (), scs .NewBuilder , circuit2 )
257
+ assert .NoError (err )
258
+
259
+ fmt .Printf ("maxLen=%d, minLen=%d, hash=%s, nbConstraints: %d vs %d(withMinLen)\n " ,
260
+ maxLen , minLen , name , cs1 .GetNbConstraints (), cs2 .GetNbConstraints ())
261
+ }
262
+ }
0 commit comments