Files
zeekay ca0bf6b303 precompile: seven packages to 96-99%, from lanes killed before they could commit
slhdsa 97.9 · mlkem 97.4 · mldsa 96.8 · xwing 96.2 · bls12381 97.2 ·
kzg4844 97.8 · v3 98.7. All build, vet and gofmt clean, all green under
-count=1, and preserved here rather than lost to a session limit.

v3's lane did report before it died: 78.1% to 98.7%, 70 of 70 mutations caught,
four of which survived a first pass and needed tests written. The two that
matter are rounding: burn rounding principal UP, and fee growth rounding UP,
neither of which any behaviour test could see -- a Q128.128 off-by-one is
2^-128 of a token and floors to zero through every payout path, so it took an
exact-value assertion. It also found that a full drain of a pool with
overlapping positions REVERTS rather than paying out, because deposits round
down once per position while payouts round down once per step over combined
liquidity, and floor(a+b) >= floor(a)+floor(b). Custody holds; not one unbacked
wei leaves. Liveness, not theft.

The other six carry no report -- their lanes were killed mid-run. Build, vet,
gofmt and the suite are all I can vouch for.
2026-08-28 13:27:00 -07:00

91 lines
2.6 KiB
Go

// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package xwing
import (
"testing"
"github.com/luxfi/geth/common"
"github.com/stretchr/testify/require"
)
// C-02: X-Wing KeyGen must not be exposed on-chain.
//
// Vulnerability: KeyGen (0x01) returned secret key material in EVM return data,
// visible to all validators and archived in transaction receipts forever.
//
// Fix: Remove OpKeyGen entirely. Only OpEncapsulate (0x02) is permitted.
// This test fails if KeyGen op is accepted.
func TestC02_XWingKeyGenRejected(t *testing.T) {
// OpKeyGen was 0x01 in the vulnerable version
const opKeyGen = 0x01
input := []byte{opKeyGen}
gas := XWingPrecompile.RequiredGas(input)
// Refused ops still cost the node a dispatch, so they are metered.
require.Equal(t, uint64(GasRefuse), gas, "KeyGen op must be metered, not free")
ret, _, err := XWingPrecompile.Run(
nil,
common.Address{},
ContractAddress,
input,
1_000_000,
false,
)
require.Error(t, err, "KeyGen op (0x01) must be rejected")
require.Nil(t, ret, "KeyGen must not return any data")
}
// C-02: X-Wing Decapsulate must not be exposed on-chain.
//
// Vulnerability: Decapsulate required the secret key in calldata, which is
// public on-chain. Any node can read the secret key from the transaction.
//
// Fix: Remove OpDecapsulate. Only OpEncapsulate is permitted.
func TestC02_XWingDecapsulateRejected(t *testing.T) {
// OpDecapsulate was 0x03 in the vulnerable version
const opDecapsulate = 0x03
input := []byte{opDecapsulate}
gas := XWingPrecompile.RequiredGas(input)
require.Equal(t, uint64(GasRefuse), gas, "Decapsulate op must be metered, not free")
ret, _, err := XWingPrecompile.Run(
nil,
common.Address{},
ContractAddress,
input,
1_000_000,
false,
)
require.Error(t, err, "Decapsulate op (0x03) must be rejected")
require.Nil(t, ret, "Decapsulate must not return any data")
}
// C-02: Only OpEncapsulate (0x02) is a valid operation.
//
// Verify that every single-byte op code other than 0x02 is rejected.
func TestC02_XWingOnlyEncapsulateAllowed(t *testing.T) {
for op := byte(0x00); op <= 0x10; op++ {
if op == OpEncapsulate {
continue
}
input := []byte{op}
gas := XWingPrecompile.RequiredGas(input)
require.Equal(t, uint64(GasRefuse), gas, "Op 0x%02x must be metered, not free", op)
ret, _, err := XWingPrecompile.Run(
nil,
common.Address{},
ContractAddress,
input,
1_000_000,
false,
)
require.Error(t, err, "Op 0x%02x must be rejected", op)
require.Nil(t, ret, "Op 0x%02x must not return data", op)
}
}