mirror of
https://github.com/luxfi/fhe.git
synced 2026-07-26 23:16:08 +00:00
wire/wire.go — fhe's wire-format hardening boundary. FHE wire formats nest deeper than pulsar's (CKKS ciphertext = Vec<Poly> over RNS chain of Vec<u64>) so MaxDepth = 5 + larger MaxFrameBytes (32 MiB) reflect the deeper polynomial structure. Tests: * TestValidateCiphertextFrame_RejectsHugeLength — regression for lattice issue #4 attack input class. Same substrate, same rejection. * TestValidateCiphertextFrame_OverCap — MaxFHESliceLen+1 rejected. go.mod adds luxfi/math v1.3.0 dependency. This completes Phase 5 of LP-107: every Lux Go protocol repo (pulsar, lens, fhe, lattice) now consumes the math substrate for bounded wire decoding. The same lattice issue #4 attack input is rejected identically across all four consumers.
43 lines
1006 B
Go
43 lines
1006 B
Go
// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package wire
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/luxfi/math/codec"
|
|
)
|
|
|
|
func encodeUvarint(out *bytes.Buffer, v uint64) {
|
|
for v >= 0x80 {
|
|
out.WriteByte(byte(v) | 0x80)
|
|
v >>= 7
|
|
}
|
|
out.WriteByte(byte(v))
|
|
}
|
|
|
|
func TestValidateCiphertextFrame_RejectsHugeLength(t *testing.T) {
|
|
const huge = uint64(70_368_955_777_453)
|
|
var buf bytes.Buffer
|
|
encodeUvarint(&buf, huge)
|
|
err := ValidateCiphertextFrame(buf.Bytes())
|
|
if err == nil {
|
|
t.Fatal("ValidateCiphertextFrame returned nil for huge length")
|
|
}
|
|
if !errors.Is(err, codec.ErrLimitExceeded) {
|
|
t.Errorf("err is not ErrLimitExceeded: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateCiphertextFrame_OverCap(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
encodeUvarint(&buf, uint64(MaxFHESliceLen+1))
|
|
err := ValidateCiphertextFrame(buf.Bytes())
|
|
if !errors.Is(err, codec.ErrLimitExceeded) {
|
|
t.Errorf("err is not ErrLimitExceeded: %v", err)
|
|
}
|
|
}
|