Skip to content

Commit

Permalink
gopter test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabaie committed Sep 11, 2024
1 parent 6eb6bd8 commit edb4897
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions prover/circuits/pi-interconnection/circuit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package pi_interconnection_test
import (
"errors"
"fmt"
"github.com/consensys/zkevm-monorepo/prover/config"
"github.com/leanovate/gopter"
"github.com/leanovate/gopter/gen"
"github.com/leanovate/gopter/prop"
"testing"

"github.com/consensys/gnark-crypto/ecc"
Expand All @@ -14,9 +18,7 @@ import (
"github.com/consensys/zkevm-monorepo/prover/circuits/internal"
pi_interconnection "github.com/consensys/zkevm-monorepo/prover/circuits/pi-interconnection"
"github.com/consensys/zkevm-monorepo/prover/circuits/pi-interconnection/keccak"
"github.com/consensys/zkevm-monorepo/prover/config"
"github.com/consensys/zkevm-monorepo/prover/utils"
"github.com/consensys/zkevm-monorepo/prover/utils/test_utils"
"github.com/stretchr/testify/assert"
"golang.org/x/crypto/sha3"
)
Expand Down Expand Up @@ -103,22 +105,32 @@ func (c *testMerkleCircuit) Define(api frontend.API) error {
}

func TestMaxNbCircuitsSum(t *testing.T) {
cfg := config.PublicInput{
MaxNbDecompression: test_utils.RandIntN(10),
MaxNbExecution: test_utils.RandIntN(10),
MaxNbCircuits: 20,
MaxNbKeccakF: 200,
ExecutionMaxNbMsg: 2,
L2MsgMerkleDepth: 5,
L2MsgMaxNbMerkle: 2,
MockKeccakWizard: true,
}

c, err := pi_interconnection.Compile(cfg)
assert.NoError(t, err)
parameters := gopter.DefaultTestParameters()
parameters.MinSuccessfulTests = 5
parameters.Rng.Seed(0x123456789abcdef0)

properties := gopter.NewProperties(parameters)

properties.Property("provides the correct number of public inputs", prop.ForAll(
func(maxNbDecompression, maxNbExecution int) bool {
cfg := config.PublicInput{
MaxNbDecompression: maxNbDecompression,
MaxNbExecution: maxNbExecution,
MaxNbCircuits: 20,
MaxNbKeccakF: 200,
ExecutionMaxNbMsg: 2,
L2MsgMerkleDepth: 5,
L2MsgMaxNbMerkle: 2,
MockKeccakWizard: true,
}

cs, err := frontend.Compile(ecc.BLS12_377.ScalarField(), scs.NewBuilder, c.Circuit)
assert.NoError(t, err)
c, err := pi_interconnection.Compile(cfg)
assert.NoError(t, err)
cs, err := frontend.Compile(ecc.BLS12_377.ScalarField(), scs.NewBuilder, c.Circuit)
assert.NoError(t, err)
return cfg.MaxNbDecompression+cfg.MaxNbExecution == pi_interconnection.GetMaxNbCircuitsSum(cs)
}, gen.IntRange(1, 10), gen.IntRange(1, 10),
))

assert.Equal(t, cfg.MaxNbDecompression+cfg.MaxNbExecution, pi_interconnection.GetMaxNbCircuitsSum(cs))
properties.TestingRun(t)
}

0 comments on commit edb4897

Please sign in to comment.