mirror of
https://github.com/vacp2p/linea-monorepo.git
synced 2026-01-09 15:38:06 -05:00
feat bypass wizard option (#3878)
* feat bypass wizard option * docs mark unspecified wizard parameters * revert add MockKeccakWizard back in --------- Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com> Co-authored-by: Arya Tabaie <15056835+Tabaie@users.noreply.github.com>
This commit is contained in:
@@ -3,14 +3,15 @@ package pi_interconnection
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"slices"
|
||||
|
||||
"github.com/consensys/gnark-crypto/ecc"
|
||||
"github.com/consensys/gnark/constraint"
|
||||
"github.com/consensys/gnark/frontend/cs/scs"
|
||||
"github.com/consensys/zkevm-monorepo/prover/circuits"
|
||||
"github.com/consensys/zkevm-monorepo/prover/config"
|
||||
public_input "github.com/consensys/zkevm-monorepo/prover/public-input"
|
||||
"math/big"
|
||||
"slices"
|
||||
|
||||
"github.com/consensys/gnark/frontend"
|
||||
"github.com/consensys/gnark/std/compress"
|
||||
@@ -43,8 +44,9 @@ type Circuit struct {
|
||||
L2MessageMerkleDepth int
|
||||
L2MessageMaxNbMerkle int
|
||||
|
||||
MaxNbCircuits int // possibly useless TODO consider removing
|
||||
UseGkrMimc bool
|
||||
MaxNbCircuits int // possibly useless TODO consider removing
|
||||
UseGkrMimc bool
|
||||
MockKeccakWizard bool // for testing purposes, bypass expensive keccak verification
|
||||
}
|
||||
|
||||
func (c *Circuit) Define(api frontend.API) error {
|
||||
@@ -192,7 +194,11 @@ func (c *Circuit) Define(api frontend.API) error {
|
||||
api.AssertIsEqual(c.AggregationPublicInput[0], compress.ReadNum(api, aggregationPIBytes[:16], twoPow8))
|
||||
api.AssertIsEqual(c.AggregationPublicInput[1], compress.ReadNum(api, aggregationPIBytes[16:], twoPow8))
|
||||
|
||||
return hshK.Finalize()
|
||||
if c.MockKeccakWizard {
|
||||
return nil
|
||||
} else {
|
||||
return hshK.Finalize()
|
||||
}
|
||||
}
|
||||
|
||||
func MerkleRootSnark(hshK keccak.BlockHasher, leaves [][32]frontend.Variable) [32]frontend.Variable {
|
||||
@@ -272,6 +278,7 @@ func allocateCircuit(c config.PublicInput) Circuit {
|
||||
L2MessageMerkleDepth: c.L2MsgMerkleDepth,
|
||||
L2MessageMaxNbMerkle: c.L2MsgMaxNbMerkle,
|
||||
MaxNbCircuits: c.MaxNbCircuits,
|
||||
MockKeccakWizard: c.MockKeccakWizard,
|
||||
UseGkrMimc: true,
|
||||
}
|
||||
}
|
||||
@@ -320,5 +327,10 @@ func (b builder) Compile() (constraint.ConstraintSystem, error) {
|
||||
}
|
||||
|
||||
func WizardCompilationParameters() []func(iop *wizard.CompiledIOP) {
|
||||
panic("implement me")
|
||||
panic("implement me") // TODO @alexandre.belling
|
||||
}
|
||||
|
||||
// GetMaxNbCircuitsSum computes MaxNbDecompression + MaxNbExecution from the compiled constraint system
|
||||
func GetMaxNbCircuitsSum(cs constraint.ConstraintSystem) int {
|
||||
return cs.GetNbPublicVariables() - 2
|
||||
}
|
||||
|
||||
@@ -3,18 +3,22 @@ package pi_interconnection_test
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/consensys/gnark-crypto/ecc"
|
||||
fr377 "github.com/consensys/gnark-crypto/ecc/bls12-377/fr"
|
||||
"github.com/consensys/gnark/frontend"
|
||||
"github.com/consensys/gnark/frontend/cs/scs"
|
||||
"github.com/consensys/gnark/test"
|
||||
"github.com/consensys/zkevm-monorepo/prover/backend/aggregation"
|
||||
"github.com/consensys/zkevm-monorepo/prover/circuits/internal"
|
||||
"github.com/consensys/zkevm-monorepo/prover/circuits/internal/test_utils"
|
||||
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/stretchr/testify/assert"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMerkle(t *testing.T) {
|
||||
@@ -97,3 +101,24 @@ func (c *testMerkleCircuit) Define(api frontend.API) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
cs, err := frontend.Compile(ecc.BLS12_377.ScalarField(), scs.NewBuilder, c.Circuit)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, cfg.MaxNbDecompression+cfg.MaxNbExecution, pi_interconnection.GetMaxNbCircuitsSum(cs))
|
||||
}
|
||||
|
||||
@@ -252,11 +252,12 @@ func (cfg *WithRequestDir) DirDone() string {
|
||||
}
|
||||
|
||||
type PublicInput struct {
|
||||
MaxNbDecompression int `mapstructure:"max_nb_decompression" validate:"gte=0"`
|
||||
MaxNbExecution int `mapstructure:"max_nb_execution" validate:"gte=0"`
|
||||
MaxNbCircuits int `mapstructure:"max_nb_circuits" validate:"gte=0"` // if not set, will be set to MaxNbDecompression + MaxNbExecution
|
||||
MaxNbKeccakF int `mapstructure:"max_nb_keccakf" validate:"gte=0"`
|
||||
ExecutionMaxNbMsg int `mapstructure:"execution_max_nb_msg" validate:"gte=0"`
|
||||
L2MsgMerkleDepth int `mapstructure:"l2_msg_merkle_depth" validate:"gte=0"`
|
||||
L2MsgMaxNbMerkle int `mapstructure:"l2_msg_max_nb_merkle" validate:"gte=0"` // if not explicitly provided (i.e. non-positive) it will be set to maximum
|
||||
MaxNbDecompression int `mapstructure:"max_nb_decompression" validate:"gte=0"`
|
||||
MaxNbExecution int `mapstructure:"max_nb_execution" validate:"gte=0"`
|
||||
MaxNbCircuits int `mapstructure:"max_nb_circuits" validate:"gte=0"` // if not set, will be set to MaxNbDecompression + MaxNbExecution
|
||||
MaxNbKeccakF int `mapstructure:"max_nb_keccakf" validate:"gte=0"`
|
||||
ExecutionMaxNbMsg int `mapstructure:"execution_max_nb_msg" validate:"gte=0"`
|
||||
L2MsgMerkleDepth int `mapstructure:"l2_msg_merkle_depth" validate:"gte=0"`
|
||||
L2MsgMaxNbMerkle int `mapstructure:"l2_msg_max_nb_merkle" validate:"gte=0"` // if not explicitly provided (i.e. non-positive) it will be set to maximum
|
||||
MockKeccakWizard bool // for testing purposes only
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user