mirror of
https://github.com/luxfi/precompile.git
synced 2026-09-24 00:26:21 +00:00
Adds the e2e test path: real HQC keypair → precompile Encapsulate through 0x012208 → off-chain Decapsulate, shared secrets byte-equal. Three new tests, one per mode (HQC-128 / HQC-192 / HQC-256), all behind -tags=hqc_pqclean. Stub-mode tests (input shape, gas zero, invalid op/mode, wrong pubkey length, backend-not-wired propagation) stay green in the default build without cgo. go.mod: local replace for luxfi/crypto while the in-flight HQC PQClean cgo backend lands upstream. Will be dropped once crypto cuts a release including crypto/hqc/pqclean/.
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
//go:build !hqc_circl && !hqc_pqclean
|
|
|
|
package hqc
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/luxfi/crypto/hqc"
|
|
"github.com/luxfi/geth/common"
|
|
)
|
|
|
|
// TestRun_BackendStubSurfacesError — under the default no-backend
|
|
// build, hqc.Encapsulate returns hqc.ErrBackendNotWired. The precompile
|
|
// must propagate it as-is rather than swallowing into a generic error.
|
|
//
|
|
// Build-tag-gated so it does not run under hqc_pqclean / hqc_circl
|
|
// where a real backend supplies bytes instead of an error.
|
|
func TestRun_BackendStubSurfacesError(t *testing.T) {
|
|
in := make([]byte, 2+SeedSize+2249)
|
|
in[0] = 0x01
|
|
in[1] = 0x00 // HQC-128
|
|
// pkBytes left zero — backend stub returns ErrBackendNotWired before
|
|
// any structural validation, which is the expected behaviour on a
|
|
// host without a wired HQC backend (cgo PQClean or CIRCL HQC).
|
|
_, _, err := HQCPrecompile.Run(nil, common.Address{}, ContractAddress,
|
|
in, 1_000_000, true)
|
|
if !errors.Is(err, hqc.ErrBackendNotWired) {
|
|
t.Errorf("backend-not-wired path: want hqc.ErrBackendNotWired, got %v", err)
|
|
}
|
|
}
|