Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kustosz committed Sep 4, 2023
1 parent 29350c2 commit 6b4b566
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions prover/keccak/keccak_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,40 @@ func TestKeccak(t *testing.T) {
var circuit1 TestKeccakCircuit1
assert.ProverSucceeded(&circuit1, &TestKeccakCircuit1{
Input: [8]frontend.Variable{0, 0, 0, 0, 0, 0, 0, 0},
Hash: bigIntLE("0xbc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a"),
Hash: reducedBigIntLE("0xbc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a"),
}, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254))

// Keccak: hash empty input
var circuit2 TestKeccakCircuit2
assert.ProverSucceeded(&circuit2, &TestKeccakCircuit2{
Input: [0]frontend.Variable{},
Hash: bigIntLE("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"),
Hash: reducedBigIntLE("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"),
}, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254))

// SHA3: hash empty input
var circuit3 TestSHACircuit
assert.ProverSucceeded(&circuit3, &TestSHACircuit{
Input: [0]frontend.Variable{},
Hash: bigIntLE("0xa7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"),
Hash: reducedBigIntLE("0xa7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"),
}, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254))

}

// we need to feed in the hash in little endian
func bigIntLE(s string) big.Int {
func reducedBigIntLE(s string) big.Int {
var bi big.Int
bi.SetString(s, 0)

b := bi.Bytes()
for i := 0; i < len(b)/2; i++ {
b[i], b[len(b)-i-1] = b[len(b)-i-1], b[i]
}

bi.SetBytes(b)

var modulus big.Int
modulus.SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)

bi.Mod(&bi, &modulus)

return bi
}

0 comments on commit 6b4b566

Please sign in to comment.