From c0b28f1970e78b63e51d9bf7176752cfe13fa20d Mon Sep 17 00:00:00 2001 From: AlexandreBelling Date: Wed, 20 Nov 2024 14:38:52 +0100 Subject: [PATCH] Prover: adds field dict_path in config (#314) * feat(conf): adds a config field to explicitly set the dictionary path * fix(typo): prover assets path * fix(e2e): specifies an explicit dict path * comment(dict_path): adds a comment stressing to not use the field outside E2E testing context. --- docker/config/prover/v3/prover-config.toml | 1 + prover/backend/blobdecompression/prove.go | 3 +-- prover/cmd/prover/cmd/setup.go | 2 +- prover/config/config.go | 22 ++++++++++++++++++++++ prover/config/constants.go | 10 +++++----- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docker/config/prover/v3/prover-config.toml b/docker/config/prover/v3/prover-config.toml index 6bd484d6..7f889515 100644 --- a/docker/config/prover/v3/prover-config.toml +++ b/docker/config/prover/v3/prover-config.toml @@ -13,6 +13,7 @@ requests_root_dir = "/data/prover/v3/execution" [blob_decompression] prover_mode = "dev" requests_root_dir = "/data/prover/v3/compression" +dict_path = "/opt/linea/prover/lib/compressor/compressor_dict.bin" [aggregation] prover_mode = "dev" diff --git a/prover/backend/blobdecompression/prove.go b/prover/backend/blobdecompression/prove.go index b65108be..79c92726 100644 --- a/prover/backend/blobdecompression/prove.go +++ b/prover/backend/blobdecompression/prove.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "fmt" "os" - "path/filepath" blob_v0 "github.com/consensys/linea-monorepo/prover/lib/compressor/blob/v0" blob_v1 "github.com/consensys/linea-monorepo/prover/lib/compressor/blob/v1" @@ -69,7 +68,7 @@ func Prove(cfg *config.Config, req *Request) (*Response, error) { return nil, fmt.Errorf("unsupported blob version: %v", version) } - dictPath := filepath.Join(cfg.PathForSetup(string(circuitID)), config.DictionaryFileName) + dictPath := cfg.BlobDecompressionDictPath(string(circuitID)) logrus.Infof("reading the dictionary at %v", dictPath) diff --git a/prover/cmd/prover/cmd/setup.go b/prover/cmd/prover/cmd/setup.go index 3ad86b16..d2f777cb 100644 --- a/prover/cmd/prover/cmd/setup.go +++ b/prover/cmd/prover/cmd/setup.go @@ -138,7 +138,7 @@ func Setup(context context.Context, args SetupArgs) error { } if dict != nil { // we save the dictionary to disk - dictPath := filepath.Join(cfg.PathForSetup(string(c)), config.DictionaryFileName) + dictPath := cfg.BlobDecompressionDictPath(string(c)) if err := os.WriteFile(dictPath, dict, 0600); err != nil { return fmt.Errorf("%s failed to write dictionary file: %w", cmdName, err) } diff --git a/prover/config/config.go b/prover/config/config.go index 9b3294f5..2a0ee91e 100644 --- a/prover/config/config.go +++ b/prover/config/config.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path" + "path/filepath" "text/template" "github.com/ethereum/go-ethereum/common" @@ -216,6 +217,14 @@ type BlobDecompression struct { // ProverMode stores the kind of prover to use. ProverMode ProverMode `mapstructure:"prover_mode" validate:"required,oneof=dev full"` + + // DictPath is an optional parameters allowing the user to specificy explicitly + // where to look for the compression dictionary. If the input is not provided + // then the dictionary will be fetched in ///compression_dict.bin. + // + // We stress that the feature should not be used in production and should + // only be used in E2E testing context. + DictPath string `mapstructure:"dict_path"` } type Aggregation struct { @@ -270,3 +279,16 @@ type PublicInput struct { L2MsgServiceAddr common.Address // duplicate from Config } + +// BlobDecompressionDictPath returns the filepath where to look for the blob +// decompression dictionary file. If provided in the config, the function returns +// in priority the provided [BlobDecompression.DictPath] or it returns a +// prover assets path depending on the provided circuitID. +func (cfg *Config) BlobDecompressionDictPath(circuitID string) string { + + if len(cfg.BlobDecompression.DictPath) > 0 { + return cfg.BlobDecompression.DictPath + } + + return filepath.Join(cfg.PathForSetup(string(circuitID)), DefaultDictionaryFileName) +} diff --git a/prover/config/constants.go b/prover/config/constants.go index a2c430bd..8489be0d 100644 --- a/prover/config/constants.go +++ b/prover/config/constants.go @@ -1,11 +1,11 @@ package config const ( - VerifyingKeyFileName = "verifying_key.bin" - CircuitFileName = "circuit.bin" - VerifierContractFileName = "Verifier.sol" - ManifestFileName = "manifest.json" - DictionaryFileName = "compressor_dict.bin" + VerifyingKeyFileName = "verifying_key.bin" + CircuitFileName = "circuit.bin" + VerifierContractFileName = "Verifier.sol" + ManifestFileName = "manifest.json" + DefaultDictionaryFileName = "compressor_dict.bin" RequestsFromSubDir = "requests" RequestsToSubDir = "responses"