Skip to content

feat(contracts): production IEd25519Verifier for on-chain NodeId ownership proof #669

Closed

Description

@alpergundogdu

Motivation

StakingRegistry.registerNode / bindNodeId / reclaimNodeId prove ownership of an iroh NodeId by verifying an ed25519 signature over an on-chain challenge (ADR 003 § NodeId Ownership Verification). Today only the interface contracts/src/interfaces/IEd25519Verifier.sol and a test stub contracts/test/mocks/MockEd25519Verifier.sol (always returns the toggled accept) exist. The real verifier is a deploy blocker for the staking surface: without it, NodeId ownership is unverified and any address could bind any NodeId.

This is not blocking other contract work — StakingRegistry's unit tests use the mock, and the verifier is consumed only at deploy time (Partition D wiring passes the deployed verifier address into the StakingRegistry constructor).

Exact requirement (interface is frozen — do not change it)

function verify(bytes32 publicKey, bytes32 messageHash, bytes calldata signature)
    external view returns (bool ok);
  • publicKey — 32-byte ed25519 public key = the iroh NodeId (a compressed Edwards point, RFC 8032 little-endian wire encoding).
  • messageHash — 32-byte digest. The node signs these 32 bytes directly as the message M with standard RFC 8032 ed25519 (Sign(sk, M) — NOT ed25519ph / prehashed). So verification must compute k = SHA-512(R ‖ A ‖ M) mod L and check [s]B == R + [k]A. In StakingRegistry, messageHash = keccak256(abi.encodePacked(nodeId, msg.sender, block.chainid, registrationNonce[nodeId])).
  • signature — 64 bytes (R ‖ s).
  • view — callers reach it via STATICCALL (the interface's reentrancy story depends on this; keep it view).

Environment / constraints

  • Solidity 0.8.28, Foundry, evm = cancun.
  • Target chains: Arbitrum One + Arbitrum Sepolia. No ed25519 precompile (RIP-7212 is secp256r1, not relevant); no SHA-512 precompile (only SHA-256 at 0x02) — SHA-512 must be done in-EVM. The modexp precompile (0x05) is available for field inversion / square roots.
  • Must agree with iroh's verifier (iroh uses ed25519-dalek verify_strict): cofactorless equation [S]B = R + [k]A, reject small-order R and A, canonical s (s < L). NOT ZIP-215. A more-permissive on-chain verifier than dalek is a correctness bug.

Work to do

  1. Find and evaluate a Solidity ed25519 verification library against these criteria, and record the comparison in the PR:
    • professionally audited (link the audit), permissively licensed (MIT/Apache), maintained, compiles on 0.8.x;
    • does full RFC 8032 over a raw message with internal SHA-512 (so a 32-byte message M works), or composes cleanly from audited SHA-512 + curve primitives;
    • realistic gas (on-chain ed25519 is ~0.5–2M gas; measure on an Arbitrum fork, not L1 assumptions);
    • acceptance-set parity with verify_strict (or document precisely where it differs).
      Prefer the narrowest audited footprint; pin the exact upstream commit and vendor only the files actually compiled (keep them under contracts/lib/ so fmt/lint/coverage/slither skip them).
  2. Implement contracts/src/Ed25519Verifier.sol behind the frozen IEd25519Verifier interface. Decompress the 32-byte NodeId → curve point with the safety checks verify_strict enforces: canonical y (y < p), on-curve, and small-order-A rejection. Document the failure-mode contract (return false vs revert) for malformed keys.
  3. Wire it in the Partition D deploy script (pass the deployed address to StakingRegistry); keep MockEd25519Verifier for StakingRegistry unit tests.

Testing requirements

  • RFC 8032 known-answer vectors through the public verify(...) shape.
  • Differential vectors generated from ed25519-dalek (iroh's exact library): independently produce (publicKey, 32-byte messageHash, signature) triples in Rust, hardcode them, assert verify == true; include small-order / non-canonical edge cases and assert parity with verify_strict.
  • Negatives: tampered signature, wrong key, non-canonical y, malleable s (s >= L), small-order point → rejected.
  • forge test --gas-report on an Arbitrum fork; record per-verify gas in the PR.

Acceptance criteria

  • Ed25519Verifier implements IEd25519Verifier.verify and passes RFC 8032 + dalek differential KATs.
  • Canonical-y, on-curve, small-order-A checks present and tested.
  • Chosen library is audited + permissively licensed, pinned to a commit, narrowest-footprint vendored under lib/, with the evaluation recorded in the PR.
  • Gas measured on an Arbitrum fork.
  • Deploy script passes the real verifier to StakingRegistry; mock retained for unit tests.

References

  • contracts/src/interfaces/IEd25519Verifier.sol
  • contracts/src/StakingRegistry.sol — _verifyEd25519OwnershipSignature, registerNode, bindNodeId, reclaimNodeId
  • ADR 003 § NodeId Ownership Verification, § Reclaim flow

Activity

  1. added
    kind:feature
    kind:security
    on May 22, 2026
  2. github-actions commented on May 22, 2026

    @github-actions

    🎯 Triage report

    This is a well-scoped implementation task to ship the production Ed25519Verifier contract that is currently a deploy blocker for the staking surface. The interface is frozen (IEd25519Verifier.verify), the acceptance criteria are fully specified (RFC 8032 KATs, dalek differential vectors, gas profiling on an Arbitrum fork, deployment wiring), and the security constraints are precise — the verifier must match ed25519-dalek verify_strict semantics, requiring full in-EVM SHA-512 since no precompile is available on Arbitrum. The issue explicitly notes this is a poc-blocking deploy blocker once StakingRegistry needs to go live.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature New production contract implementation behind an already-frozen interface
    Labels high added; existing enhancement, security, technical, poc-blocking are accurate Security-critical (NodeId ownership unverified without it), poc-blocking deploy blocker
    Coding agent Needs more info Scope is well-defined, but the first step requires a human research decision: evaluating and selecting an audited Solidity ed25519 library (the choice itself has security and licensing implications that shouldn't be automated). Once the library is chosen and recorded, the implementation + wiring work is well-suited for agent execution.

    🔗 Similar issues

    💡 Notes and suggestions

    Library evaluation shortlist

    The most commonly cited audited Solidity ed25519 libraries:

    The most widely deployed production-grade path on Ethereum (used by LayerZero v2, among others) is the daimo-eth/p256-verifier-style composition approach: a standalone SHA-512 impl (e.g., ensdomains/buffer or the sha512 impl in the toniq-labs/ton-bridge contracts) paired with ed25519 curve arithmetic. The implementer should check if SNARKs for ed25519 proofs are a viable gas-reduction path (single-SNARK proof submitted once per registerNode — but this adds a proving infrastructure dep outside scope).

    Gas reality check

    • In-EVM SHA-512 alone is ~100k–300k gas.
    • Full ed25519 verification (decompress + scalar mul) adds another 200k–1.5M gas depending on implementation.
    • Arbitrum L2 gas costs are ~10–100x cheaper than L1 in absolute terms, but the computation cost is the same. Measure with forge test --gas-report --fork-url <arbitrum-sepolia-rpc>.
    • registerNode is a one-time call per node, so even 1M gas is acceptable if it passes the gas-limit ceiling (Arbitrum block gas limit is typically 32M).

    verify_strict parity checklist

    The implementer must confirm the chosen library (or composed implementation) handles all of:

    • Canonical s: reject if s >= L (malleable signature)
    • Canonical y coordinate: reject if y >= p (non-canonical encoding)
    • On-curve check for A (public key / NodeId)
    • Small-order point rejection for both R and A (8 small-order points on Curve25519)
    • Cofactorless equation: [S]B == R + [k]A (not the cofactor variant [8][S]B == [8](R + [k]A))

    Sub-task checklist

    • Library evaluation (human decision): survey audited Solidity ed25519 libs, pick one, record comparison table in PR
    • Rust differential vector generator: small Rust binary using ed25519-dalek to emit hardcoded (pk, msg_hash_32, sig) test vectors including edge cases
    • Implement contracts/src/Ed25519Verifier.sol with all verify_strict checks
    • forge test with RFC 8032 KATs + Rust differential vectors
    • Gas profiling on Arbitrum fork
    • Partition D deploy script wiring
    • PR records library evaluation and gas numbers

    Generated by Agentic Triage for issue #669 · ● 2M · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. alpergundogdu commented on May 29, 2026

    @alpergundogdu
    ContributorAuthor

    Library decision: get-smooth/crypto-lib (Smoo.th Crypto Lib / SCL)

    We're using get-smooth/crypto-lib — specifically src/lib/libSCL_EIP6565.sol (its RIP-6565 ed25519 verifier).

    Pinned commit: d714e9824e2e2e44be3c8fd498e0de651ddc9425 (2024-12-14, main).

    Evaluation against the criteria in this issue

    Criterion Finding
    Audited ✅ Audited by Veridise (doc/Audits/VAR_SmoothCryptoLib_*.pdf) and CryptoExperts (doc/Audits/CRX_smooth_report_*.pdf), 0 residual risks per the project's summary. The library is Ethereum Foundation–funded (it's the reference impl behind RIP-6565). Exact Veridise scope re: the EIP-6565/ed25519 path will be quoted in the PR after reading the report PDF.
    License ✅ MIT (every file header + root LICENSE).
    Maintained / compiles on 0.8.x ✅ pragma solidity >=0.8.19 <0.9.0 — compatible with our pinned 0.8.28.
    Full RFC 8032 over a raw message w/ internal SHA-512 ✅ HashInternal computes SHA-512(R ‖ A ‖ M) entirely in-EVM via a vendored SHA-512 (external/sha512/Sha2Ext.sol). It's PureEdDSA (not ed25519ph), so our 32-byte messageHash is passed directly as the message M. Matches the issue's k = SHA-512(R ‖ A ‖ M) mod L requirement.
    Cofactorless equation ✅ Verify recomputes R' = [S]B + [n−k]A (cofactorless [S]B = R + [k]A, not the [8] cofactor variant) and compares the canonical compressed encoding of R' to the signature's R bytes — so a non-canonical R encoding is implicitly rejected.
    Canonical s (s < L) ✅ Verify_LE rejects s == 0 || s >= n.
    Realistic gas ⏳ To be measured with forge test --gas-report; recorded in the PR. (This is a view/STATICCALL, so per-verify compute cost is identical on Arbitrum vs L1; only calldata/storage pricing differs, which doesn't apply here.)

    ⚠️ Important integration finding (drives the bulk of step 2)

    SCL provides no on-chain public-key decompression. Its Verify(m, r, s, extKpub) consumes a pre-expanded public key extKpub (Weierstrass affine coords + compressed form). Every path that builds extKpub (SCL_EIP6565_UTILS.SetKey) derives it from the secret and is explicitly marked "NEVER USE THIS ONCHAIN." The only decompression code in the repo (edDecompressX) lives in their test file and performs none of the verify_strict safety checks.

    On-chain we only have the 32-byte compressed NodeId. So Ed25519Verifier.sol must do the security-critical decompression itself, then call SCL's Verify_LE:

    1. Parse (y, sign) from the little-endian NodeId; reject non-canonical y (y ≥ p).
    2. Recover x via x² = (y²−1)/(d·y²+1) using SCL's SqrtMod; reject if not a QR (off-curve); apply the RFC 8032 sign rule (and the x = 0, sign = 1 failure case).
    3. Reject small-order A (the 8 torsion points) to match verify_strict (is_small_order).
    4. Convert Edwards → Weierstrass (Edwards2WeierStrass) to build extKpub[0..1]; set extKpub[4] to the compressed key for the hash.
    5. Call SCL_EIP6565.Verify_LE(messageHash, R, s, extKpub).

    verify_strict parity is therefore wrapper-enforced: SCL covers canonical-s + cofactorless + canonical-R; our wrapper adds canonical-y + on-curve + small-order-A. The one residual gap vs. dalek is small-order-R rejection (SCL never decompresses R); the PR will either add an explicit cofactor check on the recomputed R' or document the divergence precisely, per this issue's "(or document precisely where it differs)" clause.

    Vendoring plan

    Narrowest footprint — the actual compile closure of libSCL_EIP6565.sol, vendored under contracts/lib/crypto-lib/ at the pinned commit (so fmt/lint/coverage/slither skip it), with a @solidity/=lib/crypto-lib/src/ remapping:

    src/lib/libSCL_EIP6565.sol
    src/modular/{SCL_modular.sol, SCL_sqrtMod_5mod8.sol}
    src/fields/SCL_wei25519.sol
    src/elliptic/{SCL_ecOncurve.sol, SCL_mulmuladdX_fullgenW.sol}
    src/hash/SCL_sha512.sol
    src/include/{SCL_errcodes.sol, SCL_field.h.sol, SCL_mask.h.sol}
    external/sha512/{Sha2Ext.sol, LibBytes.sol}
    

    (libSCL_eddsaUtils.sol is offchain-only / test-only and libSCL_eccUtils.sol pulls in secp256r1 — both excluded from the production closure.)

    Testing plan

    • RFC 8032 known-answer vectors driven through our verify(pk, msgHash, sig) shape (decompressing the public key on-chain, not via SetKey).
    • Differential vectors generated from ed25519-dalek (already a workspace dep; iroh's verifier) — a small Rust helper emits (publicKey, 32-byte messageHash, signature) triples incl. small-order / non-canonical edge cases; asserts parity with verify_strict.
    • Negatives: tampered sig, wrong key, non-canonical y, malleable s (≥ L), small-order point → rejected.
    • forge test --gas-report; per-verify gas recorded in the PR.

    Wiring

    script/DeployProtocol.s.sol currently takes the verifier address from ED25519_VERIFIER_ADDRESS. The PR will deploy the real Ed25519Verifier from the script (with the env var retained as an override), and keep MockEd25519Verifier for CapacityBond unit tests.

    (Note: the consumer is CapacityBond, not StakingRegistry — renamed since this issue was filed; the registerNode / bindNodeId / reclaimNodeId + _verifyEd25519OwnershipSignature surface is unchanged.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featurekind:securityprio:high

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions