Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompression Prover input padding and error handling #187

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading