Files
zeekay a466c21334 crypto precompiles: a halt from calldata, two forgeries, and free calls
ring's lsagVerify halted the chain from calldata. A scalar of 0 or >= N makes
ScalarMult return a nil point and curve.Add dereferences it; geth's dispatch
has no recover, so one transaction stops every validator. Its parser also left
scalars unvalidated, and the two builds disagree about them -- cgo refuses an
out-of-range scalar, pure-Go reduces it silently -- so the same calldata
produced different verdicts depending on how the node was compiled.

frost's Schnorr check was a total forgery. An unliftable x-only key fell
through to the identity, collapsing z*G == R + c*Y to z*G == R, so choosing any
z and publishing R = z*G verifies under every off-curve x. cggmp21 forges the
same way if either coordinate comparison is dropped: one coordinate does not
identify a secp256k1 point, since (P, -P) share x and (P, lambda*P,
lambda^2*P) share y through the GLV endomorphism.

pulsar returned the full supplied gas on four exits -- work done, nothing
billed -- and ring had three arms returning zero. Corona quoted base + n*10000
with n an unbounded uint32 off the wire, up to 4.29e13 gas. Capping the charger
alone would have left the exported EstimateGas disagreeing with the fee, so
quote and charge are now one function.

corona's deserializePoly ignored the count from bytes.Reader.Read, which
returns a short read with a nil error, so a truncated blob was zero-filled and
fabricated coefficients were accepted as signed material. Its exported
ExpectedSignatureSize said 4096 against a real 163840 -- it omitted the A
matrix and bTilde that its own parser reads -- so any caller sizing calldata by
it built a call that could only be rejected.

Per-party gas prices nothing: corona's verifier never referenced t or n (dead
parameters, now gone), and frost and cggmp21 use totalSigners only for a
structural check. All three charge a variable fee for constant work. The cap
contains it; the schedule is consensus-visible and left alone.

Vectors are frozen hex with the generators deleted, because a fresh-key round
trip passes when signer and verifier are uniformly wrong together. Each carries
a genuine signature by the same key over the same message under a sibling
slot's context, which must be refused -- domain separation tested against a
real signature rather than corrupted bytes.

189 mutations, one at a time with restore-and-reverify. Five survivors, each
proven equivalent by a downstream check reaching the identical verdict.
2026-08-28 11:22:18 -07:00

102 lines
4.0 KiB
Go

// Copyright (C) 2025-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package pulsar
import (
"testing"
"github.com/luxfi/precompile/modules"
"github.com/luxfi/precompile/precompileconfig"
"github.com/stretchr/testify/require"
)
// otherConfig is a Config from a different precompile, used to pin
// that Equal refuses to compare across types.
type otherConfig struct{}
func (*otherConfig) Key() string { return "other" }
func (*otherConfig) Timestamp() *uint64 { return nil }
func (*otherConfig) IsDisabled() bool { return false }
func (*otherConfig) Equal(precompileconfig.Config) bool { return false }
func (*otherConfig) Verify(precompileconfig.ChainConfig) error { return nil }
type chainCfg struct{}
func (*chainCfg) IsDurango(uint64) bool { return true }
// TestConfigLifecycle walks the activation surface a chain config
// drives: the key it is addressed by, the timestamp that gates it, the
// disable switch, and equality.
func TestConfigLifecycle(t *testing.T) {
cfg := &Config{}
require.Equal(t, ConfigKey, cfg.Key())
require.Nil(t, cfg.Timestamp(), "no upgrade timestamp means unset, not zero")
require.False(t, cfg.IsDisabled())
require.NoError(t, cfg.Verify(&chainCfg{}))
ts := uint64(1766708400)
at := &Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &ts}}
require.Equal(t, &ts, at.Timestamp())
off := &Config{Upgrade: precompileconfig.Upgrade{Disable: true}}
require.True(t, off.IsDisabled())
}
// TestConfigEqualDiscriminates is the half of Equal that matters. A
// config comparison that returned true too readily would let an
// upgrade schedule change without the node noticing a fork, so pin
// both directions: same timestamp equal, different timestamp not
// equal, disabled not equal to enabled, and a foreign config type
// never equal regardless of its contents.
func TestConfigEqualDiscriminates(t *testing.T) {
a, b := uint64(100), uint64(200)
require.True(t, (&Config{}).Equal(&Config{}))
require.True(t,
(&Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &a}}).Equal(
&Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &a}}))
require.False(t,
(&Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &a}}).Equal(
&Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &b}}),
"different activation timestamps are different configs")
require.False(t,
(&Config{Upgrade: precompileconfig.Upgrade{Disable: true}}).Equal(&Config{}),
"disabled is not equal to enabled")
require.False(t, (&Config{}).Equal(&otherConfig{}),
"a config of another precompile is never equal")
require.False(t, (&Config{}).Equal(nil))
}
// TestConfiguratorMakesOwnConfig pins that the configurator hands back
// a config addressed by THIS precompile's key. A copy-paste that
// returned a sibling's config would silently bind the wrong upgrade
// schedule to this address.
func TestConfiguratorMakesOwnConfig(t *testing.T) {
c := &configurator{}
cfg := c.MakeConfig()
require.NotNil(t, cfg)
require.Equal(t, ConfigKey, cfg.Key())
require.IsType(t, &Config{}, cfg)
require.NoError(t, c.Configure(&chainCfg{}, cfg, nil, nil))
// Each call yields a fresh value: a shared instance would let one
// chain config mutate another's activation.
require.NotSame(t, cfg, c.MakeConfig())
}
// TestModuleRegisteredAtCanonicalAddress pins the registration that
// init() performed. The address is consensus-visible: a module bound
// to the wrong slot routes calls meant for Pulsar somewhere else.
func TestModuleRegisteredAtCanonicalAddress(t *testing.T) {
m, ok := modules.GetPrecompileModule(ConfigKey)
require.True(t, ok, "init() must have registered %q", ConfigKey)
require.Equal(t, ContractPulsarVerifyAddress, m.Address)
require.Same(t, PulsarVerifyPrecompile, m.Contract)
byAddr, ok := modules.GetPrecompileModuleByAddress(ContractPulsarVerifyAddress)
require.True(t, ok)
require.Equal(t, ConfigKey, byAddr.ConfigKey,
"the address must resolve back to this module, not a neighbour")
}