Repository navigation
feat(contracts): production Ed25519Verifier (closes #669) - #712
Conversation
Ship the production `Ed25519Verifier` behind the frozen `IEd25519Verifier` interface and wire it into `DeployProtocol`, resolving the #669 deploy blocker: without on-chain ed25519 verification any address could bind any NodeId. It wraps the audited Smoo.th Crypto Lib (get-smooth/crypto-lib) EIP-6565 verifier, vendored under `lib/crypto-lib`. Security bar — the on-chain verifier is at-least-as-strict as `ed25519-dalek::verify_strict`, the check deCDN nodes run off-chain. A more-permissive on-chain verifier would let an attacker bind a NodeId with a signature the network itself rejects, so parity is the bar. We reject the 8 small-order points for A and R, non-canonical s (s>=L), off-curve A, and non-canonical y. Two divergences are benign-STRICTER, never hit by a legitimate iroh signer: we also reject s==0 and a non-canonical A encoding (y>=p) that dalek would reduce. Deploy wiring: `run()` deploys `new Ed25519Verifier()` as the first broadcast step (forge auto-links the `SCL_EIP6565` library); the `ED25519_VERIFIER_ADDRESS` env var is removed. Test harnesses still inject `MockEd25519Verifier` by populating `cfg.ed25519Verifier` and calling `_runFullDeploy` directly. If an ed25519 precompile (RIP-6565) ever lands on Arbitrum, swap the concrete implementation — a one-line, ADR-gated change. Differential vectors: a pinned `ed25519-dalek =2.2.0` generator under `test/ed25519-vectors` emits the EIGHT_TORSION small-order set, 6 valid vectors, and an off-curve key; `Cargo.lock` is committed for reproducibility. 12 verifier tests + the deploy-script suite pass. Gas: a full successful verify costs ~501,673 gas (one-time per node lifetime). Verification is pure `view` compute (modexp precompile 0x05 + in-EVM SHA-512 + EC mul), so it is chain-identical — no Arbitrum fork needed to test. Vendoring: SCL is pinned at commit d714e98. The only local modification is `src/include/SCL_field.h.sol`, repointed from the secp256r1 field to `../fields/SCL_wei25519.sol` (documented in `lib/crypto-lib/VENDORING.md`). A top-level pre-commit `exclude: ^contracts/lib/` keeps the vendored source byte-faithful to the pin. Verification: forge fmt --check, FOUNDRY_PROFILE=ci forge build --sizes --deny warnings, forge test (301 pass). aderyn/slither run in CI. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contracts coverageLine coverage: 84.87% (1189/1401 lines) |
Gas snapshotGas changes vs baseRun: 26662465593 |
Coverage reportTotal: 89.21% (was 89.21%, ● 0.00%) — 21537/24142 lines No coverage data for changed Rust files. History
|
There was a problem hiding this comment.
Code Review
This pull request integrates the audited Smoo.th Crypto Lib (SCL) EIP-6565 ed25519 verifier to implement a production-ready on-chain Ed25519Verifier contract. The verifier enforces strict-verification guards to match the behavior of ed25519-dalek::verify_strict. The deployment scripts have been updated to deploy this verifier directly, and a comprehensive differential test suite with a Rust-based vector generator has been added. Feedback on the code changes suggests an optimization in the _sqrt function of Ed25519Verifier.sol to avoid redundant mulmod operations on the happy path.
There was a problem hiding this comment.
Pull request overview
This PR delivers a production on-chain Ed25519 signature verifier for the contracts system (closing #669) by wrapping the vendored/audited Smoo.th Crypto Lib (SCL) EIP-6565 verifier behind the already-frozen IEd25519Verifier interface, and wires deployment/tests to use it.
Changes:
- Adds
Ed25519Verifierimplementation (RFC 8032 verification via SCLVerify_LE, plus strict public-key decompression + small-order/off-curve/canonical-y guards forverify_strictparity). - Updates the production deploy script to deploy the verifier in-broadcast (removing the need for an operator-provided verifier address) and records it under
.contracts.Ed25519Verifierin the manifest. - Adds differential test coverage and a pinned Rust vector generator (
ed25519-dalek::verify_strict) to harden acceptance-set parity.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/src/Ed25519Verifier.sol | Production verifier wrapper: strict key checks + call into SCL EIP-6565 Verify_LE. |
| contracts/src/interfaces/IEd25519Verifier.sol | Keeps the frozen verifier interface; updates documentation to reflect the production implementation path. |
| contracts/script/DeployProtocol.s.sol | Deploys Ed25519Verifier as the first broadcast step and writes it into the manifest under contracts. |
| contracts/script/BaseProtocolDeploy.s.sol | Ensures deploy config continues to require a non-zero ed25519Verifier for target deployment. |
| contracts/test/Ed25519Verifier.t.sol | Differential test suite (valid vectors + negative cases) asserting parity with ed25519-dalek::verify_strict. |
| contracts/test/DeployProtocolScript.t.sol | Updates script-behavior tests for the new “script-deployed verifier” shape and manifest location. |
| contracts/test/ed25519-vectors/src/main.rs | Pinned Rust generator emitting Solidity vectors from dalek (valid cases + small-order encodings + off-curve key). |
| contracts/test/ed25519-vectors/README.md | Documents how to regenerate vectors and why strict parity is required. |
| contracts/test/ed25519-vectors/Cargo.toml | Standalone pinned Rust binary crate definition for reproducible vector generation. |
| contracts/lib/crypto-lib/src/include/SCL_field.h.sol | Vendor patch to point SCL’s generic field header at the wei25519 field (ed25519 path). |
| contracts/lib/crypto-lib/src/lib/libSCL_EIP6565.sol | Vendored SCL EIP-6565 verifier implementation used by Ed25519Verifier. |
| contracts/lib/crypto-lib/VENDORING.md | Documents the upstream pin and the minimal vendored compile closure + local patch rationale. |
| contracts/remappings.txt | Adds @solidity/ remapping for the vendored SCL source tree. |
| .pre-commit-config.yaml | Excludes contracts/lib/ from hygiene hooks to keep vendored sources byte-faithful. |
| adr/003-payments.md | Updates protocol documentation to describe the on-chain Ed25519 verification approach and strictness bar. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Convert `contracts/lib/crypto-lib` from copied source to a git submodule pinned at `d714e982`, matching how `openzeppelin-contracts` and `forge-std` are managed (all `lib/` deps are now submodules; standard Foundry layout, clear upstream provenance, no re-vendor process). Drops our one local patch — the copied tree had repointed `src/include/SCL_field.h.sol` from the secp256r1 field to the ed25519 (wei25519) field. A submodule can't carry that, but it was footprint-only, not cryptographic: both the EIP-6565 verifier (`libSCL_EIP6565.sol:18`) and `Ed25519Verifier.sol:8` import their field constants directly from `SCL_wei25519.sol`. `field.h` feeds only `SCL_modular.nModInv`, which has zero call sites in the closure, so upstream's secp256r1 binding is dead code on our verify path. Verified byte-identical behavior: `FOUNDRY_PROFILE=ci forge build --deny warnings` clean (`SCL_EIP6565` unchanged at 9,303 B), and the 12 ed25519-dalek differential vectors + full 301-test suite pass with identical gas. Also removes the `VENDORING.md` (its pin is now the gitlink; provenance moved to the verifier NatSpec) and the top-level pre-commit `exclude: ^contracts/lib/` added for the copied files — submodule contents are not in the hook file list. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address PR #712 review (gemini-code-assist): on the happy path where the first sqrt candidate is already the root (~half of residues), the trailing `mulmod(root, root, p)` re-squared a value just verified equal to `a`. Branch instead so the re-square only runs on the sqrt(-1) correction path. Behavior unchanged — the 12 ed25519-dalek differential vectors pass; verify- path gas drops ~36-180. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…lidity/` Our `Ed25519Verifier` (and its test) now import from `crypto-lib/...`, a remapping named after the dependency it points at. `@solidity/=lib/crypto-lib/ src/` stays alongside it (both resolve to the same tree) only because SCL's own source uses `@solidity/` internally — `SCL_field.h.sol` imports `@solidity/fields/SCL_secp256r1.sol` — and that's an upstream submodule file we do not patch. forge build --deny warnings clean; the 12 differential vectors pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closes #669.
Summary
Ed25519Verifierbehind the already-frozenIEd25519Verifierinterface, wrapping the audited Smoo.th Crypto Lib (SCL)libSCL_EIP6565ed25519 verifier (a pinned git submodule atcontracts/lib/crypto-lib).DeployProtocolas the first broadcast step (new Ed25519Verifier()), replacing the operator-suppliedED25519_VERIFIER_ADDRESSenv var. This unblocks the staking surface: without on-chain ed25519 verification any address could bind any NodeId.ed25519-dalekdifferential-vector generator + a 12-case verifier test suite; the deploy-script suite is updated for the new shape.Library decision:
get-smooth/crypto-lib(SCL)Decision recorded on #669. SCL
src/lib/libSCL_EIP6565.sol(RIP-6565 ed25519), pinned atd714e9824e2e2e44be3c8fd498e0de651ddc9425(2024-12-14).LICENSE).pragma >=0.8.19 <0.9.0— compatible with our pinned0.8.28.SHA-512(R‖A‖M)computed entirely in-EVM (no precompile on Arbitrum). PureEdDSA, so our raw 32-bytemessageHashis passed asM.[S]B == R + [k]A(not the[8]cofactor variant); compares the canonical compressed encoding ofR'.sVerify_LErejectss == 0 || s >= L.SCL provides no on-chain public-key decompression (its
SetKeyderivesextKpubfrom the secret and is marked "NEVER USE THIS ONCHAIN"). SoEd25519Verifierdoes the security-critical decompression and guards itself, then callsSCL_EIP6565.Verify_LE.verify_strict parity — the security bar
The on-chain verifier is at-least-as-strict as
ed25519-dalek::verify_strict, the check deCDN nodes run off-chain. A more-permissive on-chain verifier would let an attacker bind a NodeId with a signature the network itself rejects.Checks enforced (matching verify_strict):
[S]B == R + [k]A(SCL).s—s >= L(SCL).AandR— all 8 EIGHT_TORSION points. The wrapper rejects small-orderRby comparing its raw 32-byte encoding against the 8 known small-order encodings (_isSmallOrder), closing the only gap flagged in feat(contracts): production IEd25519Verifier for on-chain NodeId ownership proof #669 (SCL never decompressesR).A(wrapper decompress:x²must be a QR).R— SCL compares the canonical encoding of the recomputedR'.Two divergences, both benign-STRICTER (we reject; verify_strict accepts) and unreachable by a legitimate iroh signer:
s == 0— verify_strict only requiress < L; SCL'sVerify_LEadditionally rejectss == 0.Aencoding (y >= p) — verify_strict reducesy mod p; the wrapper rejects it. A real NodeId is always a canonical encoding.Gas
A full successful verify costs ~501,673 gas (max) — a one-time cost per node lifetime in
registerNode:SCL_EIP6565.Verify_LE≈ 487,758 (modexp precompile0x05+ in-EVM SHA-512 + Shamir EC mul).Verification is pure
viewcompute (no storage, no calldata pricing sensitivity), so per-verify cost is chain-identical on Arbitrum vs L1 — no fork was needed to measure it.Ed25519Verifierruntime size is 2,071 B;SCL_EIP6565deploys separately at ~9.3 kB.Deploy wiring
run()now deploysnew Ed25519Verifier()inside the broadcast (forge auto-deploys + links theSCL_EIP6565library), and theED25519_VERIFIER_ADDRESSenv var is removed — it was a stopgap for the absent verifier. The manifest records the address under.contracts.Ed25519Verifier. Test harnesses still injectMockEd25519Verifierby populatingcfg.ed25519Verifierand calling_runFullDeploydirectly. If an ed25519 precompile (RIP-6565) ever lands on Arbitrum, swap the concrete implementation — a one-line, ADR-gated change behind the unchanged interface.SCL dependency (git submodule)
contracts/lib/crypto-libis a git submodule pinned atd714e982, managed exactly likeopenzeppelin-contractsandforge-std. Remapping:@solidity/=lib/crypto-lib/src/. No local patches. The verify path reads its ed25519 field constants directly fromSCL_wei25519.sol(bothlibSCL_EIP6565.sol:18andEd25519Verifier.sol:8); upstream's genericSCL_field.h.sol— which binds the secp256r1 field — feeds onlySCL_modular.nModInv, which has zero call sites in the closure, so it is dead code that never touches verification.Differential test vectors
contracts/test/ed25519-vectorsis a pinneded25519-dalek =2.2.0/curve25519-dalek =4.1.3generator that emits, all asserted against the reference impl: the 8 EIGHT_TORSION small-order encodings, 6 valid(pk, msg, R, s)vectors (edge byte patterns), and 1 off-curve key.Cargo.lockis committed for reproducibility (it is a binary, not a library).Test plan
forge fmt --checkFOUNDRY_PROFILE=ci forge build --sizes --deny warnings(all contracts < EIP-170)forge test— 301 pass (12Ed25519Verifier+ deploy-script suite)forge script DeployProtocollocal simulation — deploys + links SCL, writes manifestfail-on: high) + slither (fail_on: medium) — run in CI🤖 Generated with Claude Code