Skip to content

Add g16.verify Groth16 verifier builtin - #138

Merged
someone235 merged 3 commits into
kaspanet:masterfrom
elldeeone:g16verify
Aug 7, 2026
Merged

Add g16.verify Groth16 verifier builtin#138
someone235 merged 3 commits into
kaspanet:masterfrom
elldeeone:g16verify

Conversation

@elldeeone

@elldeeone elldeeone commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds g16.verify(...) as the low-level SilverScript intrinsic for verifying Groth16 proofs through the Rusty Kaspa ZK precompile.

The builtin signature is:

g16.verify(byte[] verifyingKey, byte[] proof, byte[32] ...publicInputs)

This PR now builds on merged #137 and reuses its qualified builtin, parser, compiler, and tree-sitter patterns.

This PR includes:

  • parser, AST, formatter, and syntax-highlighting support for g16.verify
  • static validation for byte[] verifying key/proof arguments and variadic byte[32] public inputs
  • compiler lowering to OpZkPrecompile with ZkTag::Groth16 using the Rusty Kaspa stack convention
  • void statement semantics: verification failure aborts script execution and the success value is discarded
  • documentation, an executable example, valid/tampered proof coverage, and debugger support for post-Toccata-sized runtime parameters

Scope

This is the raw Groth16 intrinsic discussed in #137. It intentionally leaves the merged r0.* verifier behavior unchanged.

The possibility of implementing r0.g16.verify(...) as a SilverScript standard function on top of this intrinsic can be evaluated separately, including the cross-path R0 fixture test suggested in the #137 discussion.

Tests

cargo test --workspace
cargo clippy --workspace --tests --benches --examples -- -D warnings
cargo test --manifest-path tree-sitter/Cargo.toml
(cd tree-sitter && npm test)
cargo fmt --all -- --check
git diff --check upstream/master...HEAD

@elldeeone
elldeeone marked this pull request as draft June 29, 2026 05:30
@elldeeone

Copy link
Copy Markdown
Collaborator Author

I missed that #137 was already the ZK base.

I’m going to move this to draft for now and restack it on top of #137 once that lands, so g16.verify can reuse the qualified builtin/parser/compiler shape from the R0 support work instead of duplicating that machinery.

@elldeeone

Copy link
Copy Markdown
Collaborator Author

Restacked on merged #137 and refreshed the description to match the current diff.

The PR now adds the raw g16.verify(...) intrinsic using the compiler patterns from #137; existing r0.* behaviour remains unchanged.

@elldeeone
elldeeone marked this pull request as ready for review August 3, 2026 12:10
Comment thread docs/TUTORIAL.md Outdated

```javascript
entry verify(byte[] verifyingKey, byte[] proof, byte[32] publicInput0, byte[32] publicInput1) {
require(g16.verify(verifyingKey, proof, publicInput0, publicInput1));

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.

Remove the require, g16.verify has to be void

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed g16.verify is now void and drops the success value. Rebased on current master and all checks pass.

let parameters = builtin_parameters(name)
.ok_or_else(|| CompilerError::Unsupported(format!("builtin function '{name}' has no parameter types")))?;
check_builtin_args(name, args, parameters, ctx)?;
if name == "g16.verify" {

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.

Can you add a comment of something like

"g16.verify requires special treatment since it has variable amount of arguments"

@someone235
someone235 merged commit 5aa0886 into kaspanet:master Aug 7, 2026
4 checks passed
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.

2 participants