Files
accel/ops/crypto/crypto_msm_test.go
zeekay ae157ef07b ops/crypto: typed Curve enum and BLS12-381 G1 MSM via luxcpp/crypto cgo
- Replace MSM(curve string, ...) with MSM(curve Curve, ...). Curve enum
  values (0..3) match GPUKIT_CURVE_* in luxcpp/crypto so the cgo bridge
  forwards them unchanged.
- Drop the always-error msmCPU stub; route through gpukit_multi_pippenger_cpu
  via cgo when -tags=lux_crypto_native is set (CPU body is the same
  signed-digit Bos-Coster Pippenger that backs secp256k1 / bn254 / banderwagon).
- !cgo or !lux_crypto_native build returns ErrUnsupported so callers fall
  back to their own MSM (e.g. gnark-crypto MultiExp inside the EIP-2537
  bls12381 precompile).

Closes the audit hole at luxfi/precompile a5c7257e718ca0d94: MSM on
BLS12-381 G1 now has a real CPU implementation through accel.

Wire format (per Curve doc):
  CurveSecp256k1, CurveBN254, CurveBanderwagon : 64-byte BE x||y per point
  CurveBLS12_381                               : 96-byte BE x||y per point
  scalars                                      : 32-byte LE canonical
2026-04-29 01:05:23 -07:00

41 lines
1.0 KiB
Go

// Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package crypto
import (
"errors"
"testing"
)
func TestMSM_InputValidation(t *testing.T) {
if _, err := MSM(CurveBLS12_381, nil, nil); !errors.Is(err, ErrInvalidInput) {
t.Fatalf("empty inputs: want ErrInvalidInput, got %v", err)
}
if _, err := MSM(CurveBLS12_381,
[][]byte{make([]byte, 32)},
[][]byte{make([]byte, 96), make([]byte, 96)},
); !errors.Is(err, ErrInvalidInput) {
t.Fatalf("len mismatch: want ErrInvalidInput, got %v", err)
}
}
// TestMSM_PointSize asserts the wire format rule: BLS12-381 G1 is 96 bytes,
// every other supported curve is 64 bytes.
func TestMSM_PointSize(t *testing.T) {
cases := []struct {
curve Curve
want int
}{
{CurveSecp256k1, 64},
{CurveBN254, 64},
{CurveBLS12_381, 96},
{CurveBanderwagon, 64},
}
for _, c := range cases {
if got := c.curve.pointSize(); got != c.want {
t.Errorf("Curve(%d) pointSize = %d, want %d", c.curve, got, c.want)
}
}
}