Files
crypto/ipa/batch.go
T
Hanzo AI 6a5473e36b verkle: implement BatchProof / VerifyBatch / ErrBatchLengthMismatch
The verkle_test.go file added in d521262 references three symbols
(BatchProof, VerifyBatch, ErrBatchLengthMismatch) plus a Verify entry
point that lived in the old verkle/verkle.go re-export shim. The
subsequent vendoring (640254c) replaced the shim with a full source
vendor but did not carry the batch-verify wrapper forward, so the
package no longer built.

Restore the wrapper in verkle/verkle.go using the now-local Verify
implementation in proof_ipa.go (no upstream go-verkle import). Drop the
"upstream" alias from verkle_test.go and call the package's own New,
MakeVerkleMultiProof, and SerializeProof directly.

Also fix two stale "github.com/luxfi/crypto/ipa/banderwagon" imports in
ipa/batch.go and ipa/batch_test.go that point at a deleted directory;
the canonical home is now github.com/luxfi/crypto/banderwagon. Without
this the verkle package transitively fails to compile.

Tests (GOWORK=off go test ./verkle/...):
  TestVerifyBatch_KAT         PASS
  TestVerifyBatch_TamperDetected PASS
  TestVerifyBatch_Empty       PASS
  TestVerify_SingleSucceeds   PASS
  TestNodeWidthIs256          PASS
  TestVerifyBatch_NilProof    PASS

Pre-existing failures (TestParseNodeEoA, TestParseNodeSingleSlot,
TestDelLeaf, TestDeletePrune) are unrelated regressions from the
vendoring + blinded-MSM changes already on main.
2026-04-28 02:27:33 -07:00

62 lines
2.3 KiB
Go

// Copyright (C) 2020-2026, Lux Industries Inc. All rights reserved.
package multiproof
import (
"errors"
"fmt"
"github.com/luxfi/crypto/banderwagon"
"github.com/luxfi/crypto/ipa/bandersnatch/fr"
"github.com/luxfi/crypto/ipa/common"
"github.com/luxfi/crypto/ipa/ipa"
)
// ErrBatchLengthMismatch is returned when CheckMultiProofBatch receives
// inputs whose outer slices disagree on length.
var ErrBatchLengthMismatch = errors.New("ipa: batch slice length mismatch")
// BatchProof bundles a single multiproof with the public data needed to
// check it. A BatchProofs slice is the canonical input shape for the
// batched verifier (and for the GPU driver once it lands).
type BatchProof struct {
Proof *MultiProof // the multi-proof to verify
Cs []*banderwagon.Element // commitments (per opening within this proof)
Ys []*fr.Element // claimed evaluations
Zs []uint8 // evaluation points (within domain)
}
// CheckMultiProofBatch verifies many MultiProofs in lockstep. Each proof gets
// its own fresh transcript (the protocol is "verifiable, deterministically
// random per proof"); the batched form simply spares the caller a loop and
// gives the C++ / GPU layer a contiguous workload to dispatch on.
//
// Returns nil on full success or an error on the first mismatch (with the
// failing index embedded). Returning ErrBatchLengthMismatch means the input
// is malformed; any other non-nil return means a specific proof failed.
//
// Future work: a fully-batched verifier that randomizes the linear combination
// across proofs would amortize MSM cost; that's a separate code path.
func CheckMultiProofBatch(transcriptLabel []byte, ipaConf *ipa.IPAConfig, proofs []BatchProof) error {
if len(proofs) == 0 {
return ErrBatchLengthMismatch
}
for i, bp := range proofs {
if bp.Proof == nil {
return fmt.Errorf("ipa batch[%d]: nil proof", i)
}
if len(bp.Cs) != len(bp.Ys) || len(bp.Cs) != len(bp.Zs) {
return fmt.Errorf("ipa batch[%d]: %w", i, ErrBatchLengthMismatch)
}
t := common.NewTranscript(string(transcriptLabel))
ok, err := CheckMultiProof(t, ipaConf, bp.Proof, bp.Cs, bp.Ys, bp.Zs)
if err != nil {
return fmt.Errorf("ipa batch[%d]: %w", i, err)
}
if !ok {
return fmt.Errorf("ipa batch[%d]: proof failed", i)
}
}
return nil
}