#461 Prover: Add constraints version validation (#470)

* edit Makefile

* edit prover Makefile to capture tracefile dep.

* added prover arithmetization version validation check

* added regex check for conflated trace files

* add log msgs to prover validation checks

* add check for traces engine version and conflated trace file

* impl soft changes

* impl soft changes and replace zkevm.bim with version from main branch

* replace config-sepolia-full.toml with the version from main branch

* undo change to set the conflate dir to default value

* fix typo in comments

* embed constraint version files at compile time

* update regex check to include optional dir path in trace file
This commit is contained in:
Lakshminarayanan Nandakumar
2024-12-19 21:03:49 +01:00
committed by GitHub
parent d37c5c09aa
commit a83d22cafe
4 changed files with 63 additions and 1 deletions

View File

@@ -44,7 +44,11 @@ corset:
## Build and bundle the Corset trace-expander dependency
##
zkevm/arithmetization/zkevm.bin: corset
cd ../constraints && $(CORSET) make zkevm.bin && mv zkevm.bin ../prover/zkevm/arithmetization
cd ../constraints && \
TAGS=$$(git tag --points-at HEAD) && \
echo "$$TAGS" > ../prover/backend/execution/constraints-versions.txt && \
$(CORSET) && make zkevm.bin && \
mv zkevm.bin ../prover/zkevm/arithmetization
##
## Generate the setup for the execution prover (to be run with S3 access)

View File

@@ -0,0 +1,2 @@
v0.8.0-rc7
v0.8.0-rc8

View File

@@ -2,9 +2,14 @@ package execution
import (
"bytes"
_ "embed"
"fmt"
"path"
"regexp"
"strings"
public_input "github.com/consensys/linea-monorepo/prover/public-input"
"github.com/sirupsen/logrus"
"github.com/consensys/linea-monorepo/prover/backend/ethereum"
"github.com/consensys/linea-monorepo/prover/backend/execution/bridge"
@@ -19,12 +24,26 @@ import (
"github.com/consensys/linea-monorepo/prover/zkevm"
)
// Embed the constraints-versions.txt file at compile time
//
//go:embed constraints-versions.txt
var constraintsVersionsStr string
// Craft prover's functional inputs
func CraftProverOutput(
cfg *config.Config,
req *Request,
) Response {
// Split the embedded file contents into a string slice
constraintsVersions := strings.Split(strings.TrimSpace(constraintsVersionsStr), "\n")
// Check the arithmetization version used to generate the trace is contained in the prover request
// and fail fast if the constraint version is not supported
if err := checkArithmetizationVersion(req.ConflatedExecutionTracesFile, req.TracesEngineVersion, constraintsVersions); err != nil {
panic(err.Error())
}
var (
l2BridgeAddress = cfg.Layer2.MsgSvcContract
blocks = req.Blocks()
@@ -231,3 +250,39 @@ func mimcHashLooselyPacked(b []byte) types.Bytes32 {
gnarkutil.ChecksumLooselyPackedBytes(b, buf[:], mimc.NewMiMC())
return types.AsBytes32(buf[:])
}
// verifies the arithmetization version used to generate the trace file against the list of versions
// specified by the constraints in the file path.
func checkArithmetizationVersion(traceFileName, tracesEngineVersion string, constraintsVersions []string) error {
logrus.Info("Verifying the arithmetization version for generating the trace file is supported by the constraints version")
traceFileVersion, err := validateAndExtractVersion(traceFileName)
if err != nil {
return err
}
if strings.Compare(traceFileVersion, tracesEngineVersion) != 0 {
return fmt.Errorf("version specified in the conflated trace file: %s does not match with the trace engine version: %s", traceFileVersion, tracesEngineVersion)
}
for _, version := range constraintsVersions {
if version != "" && strings.Compare(traceFileVersion, version) == 0 && strings.Compare(tracesEngineVersion, version) == 0 {
return nil
}
}
return fmt.Errorf("unsupported arithmetization version:%s found in the conflated trace file: %s", traceFileVersion, traceFileName)
}
func validateAndExtractVersion(traceFileName string) (string, error) {
logrus.Info("Validating and extracting the version from conflated trace files")
// Define the regex pattern with a capturing group for the version part
// The pattern accounts for an optional directory path
traceFilePattern := `^(?:.*/)?\d+-\d+\.conflated\.(v\d+\.\d+\.\d+-[^.]+)\.lt$`
re := regexp.MustCompile(traceFilePattern)
// Check if the file name matches the pattern and extract the version part
matches := re.FindStringSubmatch(traceFileName)
if len(matches) > 1 {
return matches[1], nil
}
return "", fmt.Errorf("conflated trace file: %s not in the appropriate format or version not found", traceFileName)
}

View File

@@ -42,6 +42,7 @@ func Prove(args ProverArgs) error {
if err := readRequest(args.Input, req); err != nil {
return fmt.Errorf("could not read the input file (%v): %w", args.Input, err)
}
// we use the large traces in 2 cases;
// 1. the user explicitly asked for it (args.Large)
// 2. the job contains the large suffix and we are a large machine (cfg.Execution.CanRunLarge)