Files
zeekayandHanzo Dev 67da44a1f3 Depend on the renamed utility package
github.com/luxfi/utils is now github.com/luxfi/util. Import paths and the
module requirement follow the rename; the old module stays as an indirect
requirement that published dependencies still pull in.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-06 04:15:48 -07:00

46 lines
1.1 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package mldsafx
import (
"errors"
"github.com/luxfi/math"
"github.com/luxfi/util"
)
const (
// CostPerSignature is the compute cost per ML-DSA signature verification.
// Benchmarked at ~228us vs secp256k1 ~40us (5.7x ratio).
// secp256k1 CostPerSignature = 1000, so ML-DSA = 6000.
CostPerSignature uint64 = 6000
)
var (
ErrNilInput = errors.New("nil input")
ErrInputIndicesNotSortedUnique = errors.New("address indices not sorted and unique")
)
// Input references signature indices into the credential for spending.
type Input struct {
SigIndices []uint32 `serialize:"true" json:"signatureIndices"`
}
func (in *Input) Cost() (uint64, error) {
numSigs := uint64(len(in.SigIndices))
return math.Mul(numSigs, CostPerSignature)
}
// Verify this input is syntactically valid
func (in *Input) Verify() error {
switch {
case in == nil:
return ErrNilInput
case !utils.IsSortedAndUniqueOrdered(in.SigIndices):
return ErrInputIndicesNotSortedUnique
default:
return nil
}
}