Skip to content

Commit

Permalink
Prover: decompression prover input padding and error handling (#187)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Leo Jeong <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent b385746 commit 48e1001
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions prover/backend/blobdecompression/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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.
Expand Down

0 comments on commit 48e1001

Please sign in to comment.