QoreGauntlet

PQGuard — require PQ authorisation

A guarded operation carries an ML-DSA-87 signature over a digest that binds the domain, chain ID, contract address, signer, operation class, payload, a per-(signer, operation) nonce and a deadline. The contract reads the signer’s key live from the chain registry via pqcKeyStatus (0x…0A02) and verifies the signature via pqcVerify (0x…0A01). The key is never stored in the contract, so rotating it on-chain rotates it for every guarded contract at once.

PQGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {IPQC} from "../pqc/IPQC.sol";

/// @notice PQGuard — the Fix Kit authorisation base contract (SPEC §5.6).
///
///         Authorisation model: a privileged operation executes only when it
///         carries an ML-DSA-87 signature, by the signer's *currently
///         registered* on-chain PQ key, over a digest binding:
///           domain separator, chain ID, this contract, signer,
///           operation class, per-(signer, operation) nonce, deadline, payload.
///         The key is read from the chain registry (via IPQC.pqcKeyStatus) on
///         every call and is never stored in the contract, so an on-chain key
///         rotation (MsgRotatePQCKey) takes effect immediately and stale-key
///         signatures stop working (attack A7 defence).
///
///         Fail-closed: IPQC implementations revert on empty precompile
///         returns (production adapter) and this contract reverts on
///         unregistered keys and invalid signatures — there is no code path
///         that proceeds without a positive verification (attack A8 defence).
///         Separate nonce spaces per (signer, operation class) make a
///         signature for one operation useless for any other, and the nonce
///         makes every signature single-use (attack A6 defence).
abstract contract PQGuard {
    IPQC public immutable pqc;
    address public pqController;

    bytes32 public constant GUARD_DOMAIN = keccak256("QoreGauntlet.PQGuard.v1");

    /// @notice Per-(signer, operation class) nonce spaces.
    mapping(address => mapping(bytes32 => uint256)) public pqcNonces;

    error PQDeadlineExpired();
    error PQKeyNotRegistered();
    error PQInvalidSignature();
    error PQZeroAddress();

    event PQControllerRotated(address indexed previous, address indexed next);

    constructor(address pqc_, address pqController_) {
        if (pqc_ == address(0) || pqController_ == address(0)) revert PQZeroAddress();
        pqc = IPQC(pqc_);
        pqController = pqController_;
    }

    /// @notice The exact digest a PQ signature must cover. Public so off-chain
    ///         signers (and the attack engine, as a control) can reproduce it.
    function pqcDigest(address signer, bytes32 opClass, bytes memory payload, uint256 nonce, uint256 deadline)
        public
        view
        returns (bytes32)
    {
        return keccak256(abi.encode(GUARD_DOMAIN, block.chainid, address(this), signer, opClass, nonce, deadline, payload));
    }

    /// @notice Authorise one operation for the PQ controller.
    function _pqcAuthorize(bytes32 opClass, bytes memory payload, uint256 deadline, bytes memory signature)
        internal
        returns (bytes32 digest)
    {
        return _pqcAuthorizeFor(pqController, opClass, payload, deadline, signature);
    }

    /// @notice Authorise one operation for an arbitrary signer (e.g. a
    ///         guardian) against that signer's registered PQ key.
    function _pqcAuthorizeFor(
        address signer,
        bytes32 opClass,
        bytes memory payload,
        uint256 deadline,
        bytes memory signature
    ) internal returns (bytes32 digest) {
        if (block.timestamp > deadline) revert PQDeadlineExpired();
        (bool registered,, bytes memory pubkey) = pqc.pqcKeyStatus(signer);
        if (!registered || pubkey.length == 0) revert PQKeyNotRegistered();
        uint256 nonce = pqcNonces[signer][opClass];
        digest = pqcDigest(signer, opClass, payload, nonce, deadline);
        if (!pqc.pqcVerify(pubkey, signature, abi.encodePacked(digest))) {
            revert PQInvalidSignature();
        }
        pqcNonces[signer][opClass] = nonce + 1;
    }

    /// @notice Rotate the PQ controller. Only callable from a function that
    ///         has already authorised the rotation with the current
    ///         controller's PQ signature.
    function _rotatePQController(address next) internal {
        if (next == address(0)) revert PQZeroAddress();
        address previous = pqController;
        pqController = next;
        emit PQControllerRotated(previous, next);
    }
}

QoreChain adapter — fail closed

Where the precompiles are inactive they return empty data. The production adapter checks return-data length and the ML-DSA-87 sizes (2,592-byte public key, 4,627-byte signature — the chain-canonical size) and reverts on anything short. An inactive precompile stops the call; it never waves it through.

Finding — the 4,595-byte lesson

The first version of this adapter enforced 4,595 bytes — the textbook FIPS 204 signature size — and reverted every genuine signature on qorechain-diana, because the chain’s canonical ML-DSA-87 signature unit is the SDK’s 4,627-byte encoding, and neither 4,595-byte slice of a real signature verifies. The shipped adapter takes the length from the SDK constant (4,627) and enforces exactly that. The full finding is recorded in the deployment notes in the repository.

QoreChainPQCAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {IPQC, IPQCVerifier, IPQCKeyStatus} from "./IPQC.sol";

/// @notice Production adapter: forwards IPQC calls to the real QoreChain
///         precompiles on diana/mainnet and FAILS CLOSED — any unsuccessful
///         call or empty/short return data reverts instead of being treated
///         as a negative or positive answer (SPEC §5.6, §9.6).
/// @dev ML-DSA-87 size checks are enforced here, at the production
///      boundary, so the Fix Kit logic above it stays verifier-agnostic.
///      The lengths are the CHAIN's canonical lengths, taken from the
///      installed qorechain SDK 0.14.0 (`ML_DSA_87_PUBLIC_KEY_LENGTH`
///      2592, `ML_DSA_87_SIGNATURE_LENGTH` 4627) — NOT the bare FIPS 204
///      signature size (4595): QoreChain's verifiable signature unit is
///      the SDK's 4627-byte encoding, and neither 4595-byte slice of it
///      verifies. The first version of this adapter enforced 4595 and
///      reverted every real signature; the diana testnet campaign
///      caught it (see docs/VERIFICATION.md). Take lengths from the
///      SDK, never from the textbook.
contract QoreChainPQCAdapter is IPQC {
    address public constant PQC_VERIFY_PRECOMPILE = 0x0000000000000000000000000000000000000a01;
    address public constant PQC_KEY_STATUS_PRECOMPILE = 0x0000000000000000000000000000000000000a02;

    uint256 public constant MLDSA87_PUBKEY_LENGTH = 2592;
    uint256 public constant MLDSA87_SIGNATURE_LENGTH = 4627;

    error PrecompileUnavailable();
    error InvalidPubkeyLength();
    error InvalidSignatureLength();

    function pqcVerify(bytes calldata pubkey, bytes calldata signature, bytes calldata message)
        external
        view
        override
        returns (bool valid)
    {
        if (pubkey.length != MLDSA87_PUBKEY_LENGTH) revert InvalidPubkeyLength();
        if (signature.length != MLDSA87_SIGNATURE_LENGTH) revert InvalidSignatureLength();
        (bool ok, bytes memory ret) =
            PQC_VERIFY_PRECOMPILE.staticcall(abi.encodeCall(IPQCVerifier.pqcVerify, (pubkey, signature, message)));
        if (!ok || ret.length < 32) revert PrecompileUnavailable();
        return abi.decode(ret, (bool));
    }

    function pqcKeyStatus(address account)
        external
        view
        override
        returns (bool registered, uint8 algorithmId, bytes memory pubkey)
    {
        (bool ok, bytes memory ret) =
            PQC_KEY_STATUS_PRECOMPILE.staticcall(abi.encodeCall(IPQCKeyStatus.pqcKeyStatus, (account)));
        // (bool, uint8, bytes) head is 96 bytes plus the dynamic tail offset.
        if (!ok || ret.length < 96) revert PrecompileUnavailable();
        return abi.decode(ret, (bool, uint8, bytes));
    }
}

PQVault — reference implementation

PQVault.sol applies PQGuard to withdraw, owner rotation, guardian rotation and freeze/unfreeze, and adds a second line of defence: instant withdrawals are bounded by a daily budget, and anything above it waits out a timelock. Even a stolen post-quantum key is bounded by that budget until the timelock expires.

PQVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {PQGuard} from "./PQGuard.sol";

/// @notice PQVault — reference vault template built on PQGuard (SPEC §5.6).
///         Every value-moving or authority-changing operation requires an
///         ML-DSA-87 signature verified on-chain; `msg.sender` alone can do
///         nothing except deposit. As a second line of defence (against even
///         a stolen PQ key), instant withdrawals are bounded by a daily
///         budget and larger amounts must pass a timelock queue.
contract PQVault is PQGuard {
    bytes32 public constant OP_WITHDRAW = keccak256("WITHDRAW");
    bytes32 public constant OP_QUEUE_WITHDRAWAL = keccak256("QUEUE_WITHDRAWAL");
    bytes32 public constant OP_EXECUTE_WITHDRAWAL = keccak256("EXECUTE_WITHDRAWAL");
    bytes32 public constant OP_SET_OWNER = keccak256("SET_OWNER");
    bytes32 public constant OP_SET_GUARDIAN = keccak256("SET_GUARDIAN");
    bytes32 public constant OP_FREEZE = keccak256("FREEZE");
    bytes32 public constant OP_UNFREEZE = keccak256("UNFREEZE");

    address public owner;
    address public guardian;
    bool public frozen;

    uint256 public immutable dailyBudget;
    uint256 public immutable timelockDelay;

    mapping(uint256 => uint256) public instantSpentOnDay;
    uint256 public nextWithdrawalId;
    mapping(uint256 => QueuedWithdrawal) public queuedWithdrawals;

    struct QueuedWithdrawal {
        address to;
        uint256 amount;
        uint256 eta;
        bool executed;
        bool cancelled;
    }

    error VaultFrozen();
    error ExceedsInstantBudget();
    error WithdrawalNotReady();
    error WithdrawalAlreadyFinal();
    error ZeroAmount();

    event Deposited(address indexed from, uint256 amount);
    event Withdrawn(address indexed to, uint256 amount);
    event WithdrawalQueued(uint256 indexed id, address indexed to, uint256 amount, uint256 eta);
    event WithdrawalExecuted(uint256 indexed id, address indexed to, uint256 amount);
    event OwnerRotated(address indexed previous, address indexed next);
    event GuardianRotated(address indexed previous, address indexed next);
    event Frozen(address indexed by);
    event Unfrozen(address indexed by);

    constructor(
        address pqc_,
        address owner_,
        address guardian_,
        uint256 dailyBudget_,
        uint256 timelockDelay_
    ) PQGuard(pqc_, owner_) {
        if (owner_ == address(0)) revert PQZeroAddress();
        owner = owner_;
        guardian = guardian_;
        dailyBudget = dailyBudget_;
        timelockDelay = timelockDelay_;
    }

    receive() external payable {}

    function deposit() external payable {
        if (msg.value == 0) revert ZeroAmount();
        emit Deposited(msg.sender, msg.value);
    }

    function instantRemainingToday() public view returns (uint256) {
        uint256 spent = instantSpentOnDay[block.timestamp / 1 days];
        if (spent >= dailyBudget) return 0;
        return dailyBudget - spent;
    }

    /// @notice Instant withdrawal, bounded by the daily budget. PQ-signed.
    function withdraw(address to, uint256 amount, uint256 deadline, bytes calldata signature) external {
        if (frozen) revert VaultFrozen();
        if (amount == 0) revert ZeroAmount();
        if (amount > instantRemainingToday()) revert ExceedsInstantBudget();
        _pqcAuthorize(OP_WITHDRAW, abi.encode(to, amount), deadline, signature);
        instantSpentOnDay[block.timestamp / 1 days] += amount;
        (bool ok,) = payable(to).call{value: amount}("");
        require(ok, "transfer failed");
        emit Withdrawn(to, amount);
    }

    /// @notice Queue a withdrawal above the instant budget. PQ-signed.
    function queueWithdrawal(address to, uint256 amount, uint256 deadline, bytes calldata signature)
        external
        returns (uint256 id)
    {
        if (frozen) revert VaultFrozen();
        if (amount == 0) revert ZeroAmount();
        _pqcAuthorize(OP_QUEUE_WITHDRAWAL, abi.encode(to, amount), deadline, signature);
        id = nextWithdrawalId++;
        queuedWithdrawals[id] =
            QueuedWithdrawal({to: to, amount: amount, eta: block.timestamp + timelockDelay, executed: false, cancelled: false});
        emit WithdrawalQueued(id, to, amount, block.timestamp + timelockDelay);
    }

    /// @notice Execute a queued withdrawal after its timelock. PQ-signed.
    function executeWithdrawal(uint256 id, uint256 deadline, bytes calldata signature) external {
        if (frozen) revert VaultFrozen();
        QueuedWithdrawal storage w = queuedWithdrawals[id];
        if (w.executed || w.cancelled) revert WithdrawalAlreadyFinal();
        if (block.timestamp < w.eta) revert WithdrawalNotReady();
        _pqcAuthorize(OP_EXECUTE_WITHDRAWAL, abi.encode(id, w.to, w.amount), deadline, signature);
        w.executed = true;
        (bool ok,) = payable(w.to).call{value: w.amount}("");
        require(ok, "transfer failed");
        emit WithdrawalExecuted(id, w.to, w.amount);
    }

    /// @notice Rotate the owner (and with it the PQ controller). PQ-signed
    ///         by the current controller.
    function setOwner(address next, uint256 deadline, bytes calldata signature) external {
        _pqcAuthorize(OP_SET_OWNER, abi.encode(next), deadline, signature);
        address previous = owner;
        owner = next;
        _rotatePQController(next);
        emit OwnerRotated(previous, next);
    }

    /// @notice Rotate the guardian. PQ-signed by the controller.
    function setGuardian(address next, uint256 deadline, bytes calldata signature) external {
        _pqcAuthorize(OP_SET_GUARDIAN, abi.encode(next), deadline, signature);
        address previous = guardian;
        guardian = next;
        emit GuardianRotated(previous, next);
    }

    /// @notice Freeze the vault. PQ-signed by the guardian (or controller).
    function freeze(uint256 deadline, bytes calldata signature) external {
        address signer = guardian != address(0) ? guardian : pqController;
        _pqcAuthorizeFor(signer, OP_FREEZE, abi.encode(address(this)), deadline, signature);
        frozen = true;
        emit Frozen(signer);
    }

    /// @notice Unfreeze the vault. PQ-signed by the controller only.
    function unfreeze(uint256 deadline, bytes calldata signature) external {
        _pqcAuthorize(OP_UNFREEZE, abi.encode(address(this)), deadline, signature);
        frozen = false;
        emit Unfrozen(pqController);
    }
}
Find the PQVault result on the leaderboard

Per-attack remediation

the fix each finding names

A1 · Critical

Direct privileged call — Gate every value-moving function with PQGuard

Call each privileged function (withdraw and friends) with attacker-chosen parameters, using only the compromised classical key.

Put withdraw, sweep and transfer behind PQGuard's onlyPQSigned pattern: the call carries an ML-DSA-87 signature over a digest binding chain, contract, operation, nonce, deadline and payload, verified via pqcVerify against the key pqcKeyStatus returns. msg.sender alone authorises nothing.

A2 · Critical

Owner/role takeover — PQ-gate role rotation itself

Rotate owner, guardian or admin role to the attacker where rotation is classical-only.

A role check is only as strong as the rotation path behind it. setOwner, guardian and admin setters must require the current owner's PQ signature (PQGuard), so a stolen classical key cannot mint itself authority.

A3 · Critical

Upgrade hijack — PQ-gate upgrades and add a timelock

Point a proxy implementation at an attacker contract, then drain through it.

upgradeTo / upgradeToAndCall require the owner's PQ signature and sit behind a timelock, so even a validly signed upgrade is publicly visible before it takes effect.

A4 · High

Mint inflation — PQ-gate minting and cap supply in code

Mint unbacked tokens to the attacker where minting is classical-only.

Minting requires a PQ signature and the contract enforces a hard supply cap, so authority abuse is bounded even before signatures are considered.

A5 · High

Approval drain — No standing approvals; PQ-gate allowance changes

Use standing approvals or permit artefacts the target honours to pull funds without any PQ signature.

Do not create or honour open-ended allowances. Allowance grants and increases require a PQ signature, are amount-bounded, and expire.

A6 · Critical

Signature replay — Bind the digest fully, keep per-operation nonces

Capture a legitimate PQ-signed operation and replay it: same contract again, and after any deadline the digest fails to bind.

PQGuard's digest binds domain, chain ID, contract address, signer, operation class, payload, a per-(signer, operation) nonce and a deadline. A captured signature is a single-use artefact: replaying it reverts on the advanced nonce.

A7 · High

Stale-key acceptance — Read the key live from the registry, never store it

After the controller rotates its PQ key in the registry, present a signature from the previous key.

Contracts must call pqcKeyStatus at verification time and verify against the key it returns now. A stored key copy keeps trusting the old key after rotation; PQGuard never stores the key, so MsgRotatePQCKey rotates it for every guarded contract at once.

A8 · Critical

Fail-open probe — Fail closed on empty or short precompile returns

Call the authorisation path where the verifier returns empty data (precompiles inactive / verifier address dead) and observe whether the call proceeds.

QoreChainPQCAdapter checks return-data length and signature/pubkey sizes (ML-DSA-87: 2592-byte pubkey, 4627-byte signature) and reverts on anything short. An inactive precompile must stop the call, never wave it through.

A9 · High · testnet only

Window abuse — Open the narrowest window that does the job

From the compromised account, use an already-open, unscoped or over-broad EVM authorisation window to reach the target and third-party contracts.

Scope every EVM window to a single target with the minimum transaction count and value cap, and close it when the job is done. An unscoped, long-lived window is standing permission for whoever holds the classical key.

A10 · Low · testnet only

Native-lane control test — No fix — this is the control

Attempt a classical-only Native transfer from the drill account. Expected: chain refusal. This is the campaign control — it separates chain-level protection from application-level exposure.

The Native lane's mandatory hybrid signing is the chain's job and the campaign's baseline. A refusal here proves the harness can tell chain protection from application exposure; an acceptance would be reported as a critical chain-level finding.

A11 · Medium

Pause/freeze griefing — PQ-gate availability controls too

Use classical-only pause/freeze/unfreeze to lock or unlock the contract.

Pause, freeze and unfreeze are privileged operations. In the Fix Kit vault they require an owner or guardian PQ signature; a classical-only caller cannot lock users out of their funds.

A12 · High · testnet only

Cross-lane reach — Treat cross-lane movement as value movement

Attempt to move value between the EVM target and the Native lane (convert-coin paths) under classical-only control.

Conversion paths get the same PQ gating as withdrawals. Value does not become less sensitive because it changed lanes.