From 48e10012dc5f807572adac4d1098f5a17426cef5 Mon Sep 17 00:00:00 2001 From: Arya Tabaie Date: Wed, 16 Oct 2024 07:59:44 -0500 Subject: [PATCH] Prover: decompression prover input padding and error handling (#187) * fix check for error first, then compare snarkHashes * revert: ProveCheck already runs test engine when needed * revert remove request file --------- Co-authored-by: Arya Tabaie <15056835+Tabaie@users.noreply.github.com> Co-authored-by: Leo Jeong --- prover/backend/blobdecompression/prove.go | 58 +++++++++-------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/prover/backend/blobdecompression/prove.go b/prover/backend/blobdecompression/prove.go index 143d24fef..c657f1ef4 100644 --- a/prover/backend/blobdecompression/prove.go +++ b/prover/backend/blobdecompression/prove.go @@ -82,10 +82,6 @@ func Prove(cfg *config.Config, req *Request) (*Response, error) { return nil, fmt.Errorf("unsupported blob version: %v", version) } - setup, err := circuits.LoadSetup(cfg, circuitID) - if err != nil { - return nil, fmt.Errorf("could not load the setup: %w", err) - } dictPath := filepath.Join(cfg.PathForSetup(string(circuitID)), config.DictionaryFileName) logrus.Infof("reading the dictionary at %v", dictPath) @@ -95,24 +91,6 @@ func Prove(cfg *config.Config, req *Request) (*Response, error) { return nil, fmt.Errorf("error reading the dictionary: %w", err) } - maxUsableBytes, err := setup.Manifest.GetInt("maxUsableBytes") - if err != nil { - return nil, fmt.Errorf("missing maxUsableBytes in the setup manifest: %w", err) - } - - maxUncompressedBytes, err := setup.Manifest.GetInt("maxUncompressedBytes") - if err != nil { - return nil, fmt.Errorf("missing maxUncompressedBytes in the setup manifest: %w", err) - } - - if maxUsableBytes != expectedMaxUsableBytes { - return nil, fmt.Errorf("invalid maxUsableBytes in the setup manifest: %v, expected %v", maxUsableBytes, expectedMaxUsableBytes) - } - - if maxUncompressedBytes != expectedMaxUncompressedBytes { - return nil, fmt.Errorf("invalid maxUncompressedBytes in the setup manifest: %v, expected %v", maxUncompressedBytes, expectedMaxUncompressedBytes) - } - // This computes the assignment logrus.Infof("computing the circuit's assignment") @@ -123,35 +101,43 @@ func Prove(cfg *config.Config, req *Request) (*Response, error) { } assignment, pubInput, _snarkHash, err := blobdecompression.Assign( - blobBytes, + utils.RightPad(blobBytes, expectedMaxUsableBytes), dict, req.Eip4844Enabled, xBytes, y, ) + if err != nil { + return nil, fmt.Errorf("while generating the assignment: %w", err) + } + if !bytes.Equal(snarkHash, _snarkHash) { return nil, fmt.Errorf("blob checksum does not match the one computed by the assigner") } + setup, err := circuits.LoadSetup(cfg, circuitID) if err != nil { - return nil, fmt.Errorf("while generating the assignment: %w", err) + return nil, fmt.Errorf("could not load the setup: %w", err) + } + + maxUsableBytes, err := setup.Manifest.GetInt("maxUsableBytes") + if err != nil { + return nil, fmt.Errorf("missing maxUsableBytes in the setup manifest: %w", err) } - // Uncomment the following to activate the test.Solver. This is useful to - // debug when the circuit solving does not pass. It provides more useful - // information about what was wrong. + maxUncompressedBytes, err := setup.Manifest.GetInt("maxUncompressedBytes") + if err != nil { + return nil, fmt.Errorf("missing maxUncompressedBytes in the setup manifest: %w", err) + } - // err := test.IsSolved( - // &assignment, - // &assignment, - // ecc.BLS12_377.ScalarField(), - // test.WithBackendProverOptions(emPlonk.GetNativeProverOptions(ecc.BW6_761.ScalarField(), ecc.BLS12_377.ScalarField())), - // ) + if maxUsableBytes != expectedMaxUsableBytes { + return nil, fmt.Errorf("invalid maxUsableBytes in the setup manifest: %v, expected %v", maxUsableBytes, expectedMaxUsableBytes) + } - // if err != nil { - // panic(err) - // } + if maxUncompressedBytes != expectedMaxUncompressedBytes { + return nil, fmt.Errorf("invalid maxUncompressedBytes in the setup manifest: %v, expected %v", maxUncompressedBytes, expectedMaxUncompressedBytes) + } // This section reads the public parameters. This is a time-consuming part // of the process.