mirror of
https://github.com/luxfi/utxo.git
synced 2026-10-30 15:13:57 +00:00
Completes the second cut of FINAL_RIP.md. The first cut (a0aab0a) dropped
the codec.Registry field from each fx's VM interface and the public API
codec.Manager params. This cut removes the remaining test-side residue:
- Strip `linearcodec.NewDefault()` Codec field literals from every TestVM
(the field no longer exists on TestVM).
- Drop the obsolete `TestCredentialSerialize`, `TestTransferInputSerialize`,
and `TestOutputSerialize` tests in secp256k1fx — they asserted the
legacy linearcodec wire-byte format. ZAP-native round-trips are covered
in wire/wire_test.go and the per-fx wire_test.go files.
- `go mod edit -droprequire github.com/luxfi/codec` + tidy — codec is now
indirect-only (transitively required via github.com/luxfi/vm for the
verify.State interface).
Build + test clean across all 11 packages. ZAP-native at the activation
boundary 2025-12-25T16:20:00-08:00.
95 lines
2.2 KiB
Go
95 lines
2.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package schnorrfx
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/btcsuite/btcd/btcec/v2"
|
|
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
|
|
|
"github.com/luxfi/crypto/hash"
|
|
"github.com/luxfi/ids"
|
|
log "github.com/luxfi/log"
|
|
)
|
|
|
|
func benchSetup(b *testing.B) (*Fx, *TransferOutput, *TransferInput, *Credential, *TestTx) {
|
|
sk, err := btcec.NewPrivateKey()
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
pkBytes := schnorr.SerializePubKey(sk.PubKey())
|
|
addrBytes := hash.PubkeyBytesToAddress(pkBytes)
|
|
addr, err := ids.ToShortID(addrBytes)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
vm := &TestVM{
|
|
Log: log.NewNoOpLogger(),
|
|
}
|
|
vm.Clk.Set(time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC))
|
|
|
|
fx := &Fx{}
|
|
if err := fx.Initialize(vm); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
_ = fx.Bootstrapping()
|
|
_ = fx.Bootstrapped()
|
|
|
|
txBytes := []byte("benchmark transaction bytes for BIP-340 Schnorr verify")
|
|
digest := taggedDigest(utxoSignCtx, txBytes)
|
|
sig, err := schnorr.Sign(sk, digest)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
var sigArr [SigLen]byte
|
|
copy(sigArr[:], sig.Serialize())
|
|
|
|
utx := &TestTx{UnsignedBytes: txBytes}
|
|
out := &TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: OutputOwners{
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{addr},
|
|
},
|
|
}
|
|
in := &TransferInput{
|
|
Amt: 1,
|
|
Input: Input{SigIndices: []uint32{0}},
|
|
}
|
|
cred := &Credential{
|
|
Sigs: [][SigLen]byte{sigArr},
|
|
PubKeys: [][]byte{pkBytes},
|
|
}
|
|
return fx, out, in, cred, utx
|
|
}
|
|
|
|
// BenchmarkSchnorrVerify benchmarks cold (cache-cleared) verification.
|
|
func BenchmarkSchnorrVerify(b *testing.B) {
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
fx, out, in, cred, utx := benchSetup(b)
|
|
if err := fx.VerifyTransfer(utx, in, cred, out); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// BenchmarkSchnorrVerifyCached benchmarks warm (cache-hit) verification.
|
|
func BenchmarkSchnorrVerifyCached(b *testing.B) {
|
|
fx, out, in, cred, utx := benchSetup(b)
|
|
if err := fx.VerifyTransfer(utx, in, cred, out); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
if err := fx.VerifyTransfer(utx, in, cred, out); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|