Skip to content

Fixed error handling of Groth16 functions. - #2213

Merged
alexeykiselev merged 5 commits into
masterfrom
fix-groth16-error-handling
Aug 31, 2026
Merged

Fixed error handling of Groth16 functions.#2213
alexeykiselev merged 5 commits into
masterfrom
fix-groth16-error-handling

Conversation

@alexeykiselev

Copy link
Copy Markdown
Collaborator

Regression test added.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Groth16 verification behavior in the Ride runtime to treat verification/parsing failures as a false result (instead of surfacing an error), and tightens argument validation (inputs/proof/key sizes) to prevent malformed inputs from reaching the verifier. It also expands crypto-level tests/benchmarks to cover the updated error-handling expectations and adds a BN254 regression test.

Changes:

  • Add stricter size/shape checks for Groth16 inputs (multiple-of-32, proof size, and key size) in generated Ride functions and in functions_proto.go.
  • Change Ride Groth16 wrappers to suppress verifier errors and return false instead.
  • Refactor/add Groth16 tests and add a BN254 regression test.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/ride/generate/internal/function_families_generation.go Updates the generator to emit stricter Groth16 argument validation and to suppress verifier errors.
pkg/ride/functions_proto.go Adds runtime checks for inputs/proof/key sizes and changes Groth16 error handling to return false on verifier errors.
pkg/ride/function_families.gen.go Regenerated family functions with the new validation and error-suppression behavior.
pkg/crypto/groth16_test.go Refactors Groth16 tests/benchmarks and adds a BN254 regression test suite.
Files not reviewed (1)
  • pkg/ride/function_families.gen.go: Generated file
Suppressed comments (5)

pkg/crypto/groth16_test.go:378

  • This loop initializes vkFail0 again instead of vkFail15, leaving vkFail15 filled with zero bytes and making the test case not exercise the intended malformed VK bytes.
	vkFail15 := make([]byte, 256+32*15)
	for i := range vkFail0 {
		vkFail0[i] = 1
	}

pkg/crypto/groth16_test.go:382

  • This loop initializes vkFail0 again instead of vkFail16, leaving vkFail16 filled with zero bytes and making the test case not exercise the intended malformed VK bytes.
	vkFail16 := make([]byte, 256+32*16)
	for i := range vkFail0 {
		vkFail0[i] = 1
	}

pkg/crypto/groth16_test.go:231

  • Using require.* assertions inside the benchmark loop adds measurable overhead and can distort benchmark results; prefer plain if checks with b.Fatalf/b.Fatal on failure.
	for b.Loop() {
		result, err := Groth16Verify(vk, proof, inputs, ecc.BLS12_381)
		require.True(b, result)
		require.NoError(b, err)
	}

pkg/crypto/groth16_test.go:263

  • Using require.* assertions inside the benchmark loop adds measurable overhead and can distort benchmark results; prefer plain if checks with b.Fatalf/b.Fatal on failure.
	for b.Loop() {
		result, err := Groth16Verify(vk, proof, inputs, ecc.BLS12_381)
		require.True(b, result)
		require.NoError(b, err)
	}

pkg/crypto/groth16_test.go:296

  • Using require.* assertions inside the benchmark loop adds measurable overhead and can distort benchmark results; prefer plain if checks with b.Fatalf/b.Fatal on failure.
	for b.Loop() {
		result, err := Groth16Verify(vk, proof, inputs, ecc.BLS12_381)
		require.True(b, result)
		require.NoError(b, err)
	}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/crypto/groth16_test.go
Comment thread pkg/crypto/groth16_test.go
Comment thread pkg/crypto/groth16_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pkg/ride/function_families.gen.go: Generated file

Comment thread pkg/ride/generate/internal/function_families_generation.go
@nickeskov
nickeskov deployed to Deploy-mainnet-amd64 August 31, 2026 12:28 — with GitHub Actions Active
@alexeykiselev
alexeykiselev merged commit 5b3117e into master Aug 31, 2026
26 checks passed
@alexeykiselev
alexeykiselev deleted the fix-groth16-error-handling branch August 31, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants