Files
zeekay cf34e276b0 initial: PQAuth library + IPQVerify interface + Foundry tests
Canonical Solidity helpers for the Lux EVM's native post-quantum
precompiles. One source of truth for L1 contract authors who need to
authenticate post-quantum signers.

PQAuth wraps:
  0x012201  ML-KEM-768           (FIPS 203, key encapsulation)
  0x012202  ML-DSA verify        (FIPS 204, signatures: 44/65/87)
  0x012203  SLH-DSA verify       (FIPS 205, hash-based)
  0x012204  Corona threshold   (lattice threshold verify)
  0x002221  X-Wing hybrid KEM    (X25519 + ML-KEM-768)

API:
  verifyMLDSA44/65/87(pubkey, msgDigest, sig) -> bool
  verifySLHDSA       (pubkey, msgDigest, sig) -> bool
  verifyPermit       (pubkey, msgDigest, sig)  reverts on invalid

The msgDigest is 32 bytes, precomputed off-chain as
TupleHash256(parts, 32, "LUX_PQ_PERMIT_V1") per NIST SP 800-185 §5.
We refuse to implement TupleHash256/cSHAKE256 in Solidity: the EVM
lacks the primitive and emulation costs ~200k gas with high risk of
subtle field-framing bugs. Reference Go implementation:
luxfi/consensus/protocol/auth/hash.go.

Gas comparison vs ETHDILITHIUM (LGPL-3.0, vendored ML-DSA in YUL):
  ETHDILITHIUM verify:      ~8,100,000 gas
  PQAuth.verifyMLDSA65:        100,320 gas (100k base + 320 for 32-byte digest)
  => ~80x cheaper. Do not vendor or re-implement ML-DSA in user code.

IPQVerify.verifyZAuthProof reverts: reserved for the F102/F103 tx-type
0x05 path (separate multi-week project, Option B in the strict-PQ
rollout plan).

Tests (10 passing under forge):
  test_VerifyMLDSA65_ValidSignature_ReturnsTrue
  test_VerifyMLDSA65_InvalidSignature_ReturnsFalse
  test_VerifyMLDSA65_WrongPubkeyLength_Reverts
  test_VerifyMLDSA65_WrongSignatureLength_Reverts
  test_VerifyPermit_ValidSignature_NoRevert
  test_VerifyPermit_InvalidSignature_Reverts
  test_VerifySLHDSA_ValidSignature_ReturnsTrue
  test_VerifySLHDSA_InvalidSignature_ReturnsFalse
  test_VerifyZAuthProof_Reverts
  test_CanonicalAddresses

Stack: Foundry, solc 0.8.27, evm_version=cancun.
2026-05-10 21:39:29 -07:00

29 lines
1.5 KiB
Plaintext

BSD 3-Clause License
Copyright (C) 2025, Lux Industries Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.