mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
verkle: implement BatchProof / VerifyBatch / ErrBatchLengthMismatch
The verkle_test.go file added in 8b78e5c 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 (1402189) 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.
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/luxfi/crypto/ipa/banderwagon"
|
||||
"github.com/luxfi/crypto/banderwagon"
|
||||
"github.com/luxfi/crypto/ipa/bandersnatch/fr"
|
||||
"github.com/luxfi/crypto/ipa/common"
|
||||
"github.com/luxfi/crypto/ipa/ipa"
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ package multiproof
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/luxfi/crypto/ipa/banderwagon"
|
||||
"github.com/luxfi/crypto/banderwagon"
|
||||
"github.com/luxfi/crypto/ipa/bandersnatch/fr"
|
||||
"github.com/luxfi/crypto/ipa/common"
|
||||
"github.com/luxfi/crypto/ipa/ipa"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
|
||||
//
|
||||
// Package verkle hosts the canonical Lux implementation of Verkle trees and
|
||||
// the IPA-based proof system. This file exposes the batched verify entry
|
||||
// point used by downstream chains and by the GPU-accelerated proof driver.
|
||||
//
|
||||
// A batched verify takes a slice of (proof, pre-root, post-root, state-diff)
|
||||
// tuples and runs each one through the package's Verify function in
|
||||
// lockstep. The shape is the contract; the body is what an MSM-batched
|
||||
// verifier will replace once the curve arithmetic is in place.
|
||||
|
||||
package verkle
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrBatchLengthMismatch is returned by VerifyBatch when called with no
|
||||
// proofs. Callers must pass at least one BatchProof; an empty slice is a
|
||||
// programmer error, not a successful verification of nothing.
|
||||
var ErrBatchLengthMismatch = errors.New("verkle: batch slice length mismatch")
|
||||
|
||||
// BatchProof bundles a single Verkle proof with the public roots and
|
||||
// state diff needed to verify it. A []BatchProof is the canonical input
|
||||
// shape for VerifyBatch.
|
||||
type BatchProof struct {
|
||||
Proof *VerkleProof
|
||||
PreStateRoot []byte
|
||||
PostStateRoot []byte
|
||||
StateDiff StateDiff
|
||||
}
|
||||
|
||||
// VerifyBatch verifies many Verkle proofs in lockstep. Each proof is
|
||||
// checked independently with Verify; this is a structural batch (one
|
||||
// MSM per proof, no proof-randomized accumulation yet).
|
||||
//
|
||||
// Returns nil on full success, ErrBatchLengthMismatch on empty input, or
|
||||
// a wrapped error from the first failing proof tagged with its index.
|
||||
func VerifyBatch(proofs []BatchProof) error {
|
||||
if len(proofs) == 0 {
|
||||
return ErrBatchLengthMismatch
|
||||
}
|
||||
for i, p := range proofs {
|
||||
if p.Proof == nil {
|
||||
return fmt.Errorf("verkle batch[%d]: nil proof", i)
|
||||
}
|
||||
if err := Verify(p.Proof, p.PreStateRoot, p.PostStateRoot, p.StateDiff); err != nil {
|
||||
return fmt.Errorf("verkle batch[%d]: %w", i, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
upstream "github.com/ethereum/go-verkle"
|
||||
)
|
||||
|
||||
// makeSingleLeafProof builds a (preStateRoot=empty, postStateRoot=after-insert)
|
||||
@@ -24,11 +22,11 @@ func makeSingleLeafProof(t *testing.T, seed uint64) BatchProof {
|
||||
keyDigest := sha256.Sum256(append([]byte("verkle-kat-key"), seedBuf[:]...))
|
||||
valDigest := sha256.Sum256(append([]byte("verkle-kat-val"), seedBuf[:]...))
|
||||
|
||||
preroot := upstream.New()
|
||||
preroot := New()
|
||||
preroot.Commit()
|
||||
preCommit := preroot.Commit().Bytes()
|
||||
|
||||
postroot := upstream.New()
|
||||
postroot := New()
|
||||
if err := postroot.Insert(keyDigest[:], valDigest[:], nil); err != nil {
|
||||
t.Fatalf("seed=%d insert: %v", seed, err)
|
||||
}
|
||||
@@ -36,11 +34,11 @@ func makeSingleLeafProof(t *testing.T, seed uint64) BatchProof {
|
||||
postCommit := postroot.Commit().Bytes()
|
||||
|
||||
// Generate the proof using the pre/post pair.
|
||||
proof, _, _, _, err := upstream.MakeVerkleMultiProof(preroot, postroot, [][]byte{keyDigest[:]}, nil)
|
||||
proof, _, _, _, err := MakeVerkleMultiProof(preroot, postroot, [][]byte{keyDigest[:]}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("seed=%d MakeVerkleMultiProof: %v", seed, err)
|
||||
}
|
||||
vp, sd, err := upstream.SerializeProof(proof)
|
||||
vp, sd, err := SerializeProof(proof)
|
||||
if err != nil {
|
||||
t.Fatalf("seed=%d SerializeProof: %v", seed, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user