Proving Cost of Non-Native Signature Verification

MPS0052
StatusProposed
CategoryCore
AuthorsHector Bulgarini (hbulgarini), Nicolas Di Prima (NicolasDP), Facundo Lerena (faculerena)
Created26-NOV-2026

Abstract

A signature scheme is non-native to Midnight circuits when its arithmetic runs modulo a different prime from the proof system’s scalar field, over which Jubjub is defined. Every field operation must then be emulated over many constraints, and the cost grows when the signer’s message encoding needs byte-oriented hashes such as SHA-256 or Keccak-256. Midnight verifies Jubjub Schnorr natively and cheaply, yet almost every signer users already trust (passkeys, Apple Secure Enclave and Android StrongBox keys, cloud KMS and HSM keys, and EVM wallets) signs with ECDSA over P-256 (r1) or secp256k1 (k1). Compact 0.35 can verify both in-circuit, so the gap is no longer expressiveness but cost. In a benchmark of the Passport account contract, the same operation needed 1.5–2.3× the circuit rows with k1 and 2.8–6.1× with WebAuthn-wrapped r1, compared with Jubjub Schnorr. On an Apple M4 Max, a typical operation that proved in about 2–4 s with Jubjub took about 10 s with k1 and about 20 s with r1. The cost is expected to be higher on consumer and mobile hardware, which was not measured. This MPS describes the gap and does not propose a solution.

Vision

A user can authorise a Midnight action with the key they already have, whether a passkey, a device secure enclave, an institutional HSM or KMS key, or an EVM wallet, without a material proving penalty compared with Midnight’s native curve. Developers no longer have to choose between good latency and support for the signers their users already hold. An operation authorised by a k1 or r1 signature stays in the same proving-cost class as its native-curve equivalent. Message preparation is included in that cost, such as SHA-256 over WebAuthn client data or Keccak-256 for EIP-191 and EIP-712. The cost is predictable, published per reference workload, and acceptable on the hardware where proofs are actually generated: laptops, phones, and browsers. Users who keep their witness local should not have to hand it to a third-party prover to get usable latency.

Problem

Scope. The problem is the proving cost of verifying any non-native signature scheme in-circuit, including the SNARK-unfriendly hashing its message encoding requires. The evidence below covers k1 and r1, because almost every deployed hardware, platform, and wallet signer uses them. Other non-native schemes share the problem class but have not been measured here: Ed25519, RSA (MPS-0009), and post-quantum schemes such as ML-DSA (upstream PR #434).

1. The native scheme is the one no deployed signer supports

Midnight circuits verify Schnorr over Jubjub with native field arithmetic. Hardware and platform signers do not offer that scheme:

Signer class Curves typically available Notes
Passkeys / WebAuthn authenticators P-256 (ES256) ES256 is the algorithm relying parties can rely on across platform authenticators. The signed message is authenticatorData ‖ SHA-256(clientDataJSON), not a caller-chosen digest.
Apple Secure Enclave P-256 CryptoKit exposes only P-256 keys in the Secure Enclave.
Android Keystore / StrongBox P-256 Hardware-backed EC keys use NIST curves.
Cloud KMS / HSM (AWS, Google Cloud, Azure) P-256 and secp256k1 Both are offered as key specifications; Jubjub is not.
EVM wallets (MetaMask and others) secp256k1 Messages are wrapped as EIP-191 or EIP-712 and hashed with Keccak-256 before signing.

A product can either hold a software Jubjub key itself, which gives up the key-custody guarantees these signers provide, or verify k1 or r1 in-circuit and pay for it. Passport’s temporary Jubjub bootstrap amendment uses an app-held Jubjub key only until the user installs a passkey. It does not remove the need for in-circuit P-256.

2. Measured cost

The evidence comes from the Passport account benchmark (experiments/acc-profile, Passport PR #217). The setup was Compact 0.35.0 (ZKIR v3) with proof server 9.0.0-rc.8, running locally on an Apple M4 Max with an 8-vCPU, 23 GiB ARM64 Docker VM. One request covers artefact upload over loopback and proof generation. Signing, wallet balancing, and chain inclusion fall outside the timer.

How the measured circuits are built. Every signature-authorised export of the Passport account contract has the same three parts:

  1. It builds a challenge that binds the contract address, the operation arguments, and a replay nonce.
  2. It calls the authorisation helper for its signature arm.
  3. It runs an operation body that all three arms share.

Because the body is identical across arms, the difference between the columns of the account table below is the cost of challenge construction plus authorisation. Step 1 is not identical: each arm uses its own challenge builder and domain-separation tags, and the r1 device entry also hashes the relying-party ID hash and origin. The per-stage profile in §3 separates the signature check itself. The links below point to the measured revision. The benchmark ran at df04567, whose contract/ tree is identical to 105ee3f.

Arm Authorisation helper What it proves in-circuit
Jubjub Schnorr require_authorised_with_jubjub Rejects small-order keys, checks that the device entry is enrolled and rolls its use counter, then checks s·G == R + c·pk using Jubjub arithmetic native to the proof system.
secp256k1 (k1) require_authorised_with_k256 Rejects the point at infinity and does the same device-entry check and roll. It then recomputes the signed digest with SHA-256 for both supported envelopes (envelope_digest), because a circuit conditional is a select that evaluates both sides. Finally it runs secp256k1EcdsaVerify.
P-256 WebAuthn (r1) require_authorised_with_p256 Does the same device-entry check and roll, then calls webauthn_verify_profiled. That helper checks the relying-party ID hash and the UP and UV flags. It then rebuilds clientDataJSON from the challenge (base64url-encoded in-circuit) and the origin (byte-validated). It does this for both supported browser layouts, the 134-byte and the 243-byte one, and hashes each with SHA-256. Finally it hashes authenticatorData ‖ clientDataHash and runs secp256r1EcdsaVerify.
Circuit What it does Shared body Source
verify_k1 Standalone probe. Verifies one secp256k1 ECDSA signature over a 32-byte prehashed digest and writes the digest to a public ledger field, so the compiler keeps the circuit. — verify-k1.compact
verify_ecdsa The same probe for P-256, plus checks that r and s are nonzero. — probe-p256.compact
verify_webauthn A complete P-256 WebAuthn assertion check for the fixed 134-byte clientDataJSON layout. — probe-p256.compact
verify_webauthn_profiled The WebAuthn check the account actually uses, covering both browser layouts. — probe-p256.compact
revoke_grant_with_* Marks a spending grant previously issued to a dApp as inactive. The body is one map lookup and one map write. do_revoke_grant Jubjub · k1 · r1
remove_device_with_* Removes an enrolled device entry. It refuses to remove the last device or the device that authorised the call. do_remove_device Jubjub · k1 · r1
withdraw_shielded_with_* Spends a shielded coin held by the account to a user’s Zswap public key and returns any change to the account. do_withdraw_shielded Jubjub · k1 · r1
withdraw_unshielded_with_* Debits the account’s unshielded balance mirror and sends the tokens to a user address. do_withdraw_unshielded Jubjub · k1 · r1
publish_recovery_session_with_* Opens a new recovery session. It replaces the recovery public key and publishes a session nonce, up to four recovery parameters (phi), and a 64-byte wrap. It is refused while a recovery is pending. do_publish_recovery_session Jubjub · k1 · r1
rotate_enc_key_with_* Replaces the account’s inbox encryption key (enc_key), which encrypts the descriptions of shielded coins the account holds. The body is a single ledger write. do_rotate_enc_key Jubjub · k1 · r1

Standalone verifiers (prehashed digest, three paired requests per curve):

Verifier Rows Domain Mean proof request
secp256k1 ECDSA 40,409 k=16 3.78 s
P-256 ECDSA 59,063 k=17 7.47 s
P-256 bounded WebAuthn (134-byte clientDataJSON) 112,156 k=17 not paired

A secp256k1 check alone uses more rows than entire Jubjub-authorised account operations, such as revoke_grant at 26,922 rows.

The same account operation under three signature arms:

Operation Jubjub Schnorr secp256k1 (k1) P-256 WebAuthn (r1)
revoke_grant 26,922 rows, k=15, 2.24 s 61,912 rows, k=17, 9.44 s 163,482 rows, k=18, 19.52 s
remove_device 32,776 rows, k=16, 4.10 s 68,314 rows, k=17, 9.53 s 171,758 rows, k=18, 19.88 s
withdraw_shielded 50,089 rows, k=16, 4.23 s 83,236 rows, k=17, 9.77 s 184,787 rows, k=18, 20.03 s
publish_recovery_session 36,491 rows, k=16, 4.25 s 72,217 rows, k=17, 10.00 s 173,788 rows, k=18, 20.64 s
All 15 signature-authorised operations k=15–17 k=17, rows ×1.5–2.3 k=18, rows ×2.8–6.1

In a separate paired run, rotate_enc_key averaged 11.07 s with k1 and 25.13 s with r1. Its operation body is a single ledger write, so nearly all of that time is spent on authorisation. The same r1 circuit averaged 27.19 s in the sweep and 17.37 s in the later run of §4, which ran at lower host load; the 163,324 rows and k=18 are the same in all three series (see Evidence limits).

3. Where the rows go

  • The signer’s message format dominates r1. In rotate_enc_key_with_p256, which has 163,324 rows, preparing the WebAuthn digest adds 86,363 rows (52.9%). That step base64url-encodes the challenge, validates the origin bytes, and rebuilds and SHA-256-hashes clientDataJSON for both browser layouts. It then hashes the 69-byte signed message. Checking the ECDSA signature adds 49,275 rows (30.2%), leaving about 17% for challenge construction, the device-entry roll, and the single-write operation body. The equivalent Jubjub circuit has 26,764 rows in total, fewer than the P-256 signature check alone. Supporting a second browser layout costs real rows, because a circuit pays for both sides of every conditional. (Stage boundaries.)
  • k1 also pays for envelope hashing. The k1 arm recomputes two SHA-256 envelope digests on every call before the curve check, for the same select-not-branch reason.
  • Part of the cost is in the library, not the curve. Computing 0 × G for the public-key identity check adds 11,651 of 40,409 rows (28.8%) in the standalone secp256k1 verifier and 21,855 of 59,063 (37.0%) in P-256. This step sits inside the lowering of the standard-library secp256k1EcdsaVerify and secp256r1EcdsaVerify, not in Passport code (stage labels). A cheaper representation of the same check would help both curves.
  • Keccak is not yet in the measured path. The measured k1 arm signs a SHA-256 envelope. A MetaMask personal_sign or EIP-712 signature would also need Keccak-256 in-circuit. That cost is not measured here.

4. Proving cost is quantised by domain size

Proving time is dominated by k and roughly doubles with each step. In the sweep, Jubjub operations at k=15, 16, and 17 took about 2.2 s, 4.2 s, and 8 s, while every k1 operation sat at k=17 (about 10 s) and every r1 operation at k=18 (about 20 s). The row counts in this MPS are assigned rows, and k is not their base-2 logarithm rounded up: the domain must also hold fixed overhead such as lookup tables and blinding rows, and that overhead differs between circuits. In the sweep, issue_grant_with_jubjub fits k=16 with 59,968 rows, while the 59,063-row P-256 verifier and every k1 account operation (61,682 rows or more) need k=17. The largest circuit at k=17 has 119,703 rows, and the October single-layout rotation needed k=18 with 129,832. Headroom must therefore be judged against the measured k of each circuit, not against 2k or against row counts alone. Within a domain, cost is not flat either: k1 operations at k=17 took about 10 s against about 8 s for Jubjub operations at the same k, so non-native circuits are slower at equal k and row cuts inside a domain can still help. The largest gains, however, come from crossing a boundary. An experimental variant computes the challenge encoding and origin validation once and shares them between the two browser layouts. It cut verify_webauthn_profiled from 136,195 to 119,703 rows. That moved it from k=18 to k=17 and halved its time (18.82 s → 9.37 s). The same change cut rotate_enc_key_with_p256 from 163,324 to 137,399 rows, but the circuit stayed at k=18, and its time did not change (17.37 s → 17.24 s). A WebAuthn check for a single fixed clientDataJSON layout fits at k=17, but it is still large: verify_webauthn uses 112,156 rows. Supporting the layouts that real browsers produce pushes the check to k=18. Every r1 account operation measured here also sits at k=18, including an earlier single-layout account rotation of 129,832 rows (October measurements).

5. Compounding factors

  • Hardware. These figures come from a high-end desktop. Consumer laptops, phones, and in-browser provers were not measured. They are expected to be slower and more memory-constrained. Passkey and secure-enclave products are mostly used on those devices.
  • Delegated proving moves the problem. A remote proof server can hide latency, but it receives the witness. That brings in the trust problem of MPS-0004 and runs against the reason for using a local hardware signer.
  • Artefact size and key upload. Prover keys grow with the proving domain. In the October measurements, the prover key for rotate_enc_key was 47 MiB with Jubjub (k=15), 224 MiB with k1 (k=17), and 448 MiB with r1 (k=18). The 52 account circuits’ keys occupy about 12 GiB in total. The measured request times include uploading the prover key, verifier key, and ZKIR to the proof server, so larger keys inflate every request. That makes the latency problem worse, and it adds to the distribution burden described in MPS-0039 and addressed in part by MIP-0020.
  • Memory. Proving at k=18 needs several gigabytes. The first full-account P-256 proof was killed for running out of memory in a proof server with about 8 GiB (failure evidence). Peak memory was not instrumented in the benchmark. Memory at this scale is a hard limit for phones and in-browser provers.
  • Signature encoding from real signers. ECDSA signers are not required to emit low-s signatures, and real authenticators emit high-s ones: the Passport verifier probes prove a captured real high-s WebAuthn assertion. A verifier that requires low-s would reject genuine signatures. How often each platform emits high-s has not been measured in a published run. Any cheaper verification path must either accept high-s signatures or normalise s in-circuit, and normalising adds cost.
  • Linear scaling. Every authorised operation pays the cost again. Batches, multi-step flows, and custodial back-ends that sign on behalf of many accounts multiply it.

6. Relationship to existing problem statements

MPS-0010, MPS-0008, and MPS-0011 addressed whether these primitives exist in Compact, and the “poor performance” risk is only a failure scenario in MPS-0010. Compact 0.35 now exposes secp256k1EcdsaVerify and secp256r1EcdsaVerify. This MPS addresses the next gap: the primitives exist, but their cost makes them impractical for interactive products. MIP-0003 covers ledger-level secp256k1, which is distinct from in-circuit authorisation. MIP-0030 specifies the k1 and r1 account envelopes measured here.

Evidence limits

The results come from one machine and one shared local proof server, with two or three samples per circuit. Timings vary with host load: two identical P-256 unshielded withdrawals took 73.21 s and 19.87 s. Row counts and k are deterministic and are the primary evidence. Wall-clock figures indicate scale. Per-stage elapsed time and peak memory were not instrumented in this benchmark. Request times include artefact upload to the proof server.

Use Cases

Passkey-secured self-custody account. A user creates a Midnight account protected by the passkey on their phone. Every withdrawal, grant, device change, and recovery-session change needs a WebAuthn-authorised proof. Guardian-driven recovery steps carry no signature arm and are unaffected. On a high-end desktop, each takes about 20 s, compared with 2–4 s for the same action with a Jubjub key. On the phone where the passkey lives, the wait is longer and unmeasured. A user facing that wait often gives up, and a product team often falls back to an app-held software key, giving up the security the passkey was meant to provide.

Mobile app with a hardware-bound key. A banking or identity app keeps its signing key in the Secure Enclave or StrongBox so the key cannot be exported. Those keys are P-256 only, so every in-circuit authorisation pays the non-native cost and is proved on mobile hardware. Where the app wraps the signature in WebAuthn, each operation measured here sits in the 218 domain. A raw P-256 signature over a prehashed digest avoids the WebAuthn digest preparation: the standalone verifier needs 59,063 rows at k=17, so such operations are likely to sit at k=17, but raw P-256 account operations were not measured.

Institutional custody through an HSM or cloud KMS. A custodian’s policy requires keys to stay in an HSM or KMS that offers P-256 and secp256k1 but not Jubjub. Each customer operation pays the non-native verification cost, and operations across many accounts scale linearly. The custodian must either provision far more proving capacity or accept higher latency on every operation.

EVM user authorising a Midnight action with MetaMask. A user who already holds an EVM wallet wants to control a Midnight account or approve a Midnight transaction without installing a new key. MetaMask signs EIP-191 or EIP-712 messages over secp256k1, so the circuit must recompute Keccak-256 and verify k1. It pays at least the measured k1 cost of about 10 s per operation, plus the unmeasured Keccak cost. This is the cross-ecosystem onboarding path that MPS-0010 and MPS-0011 were meant to open.

Agents and services with managed keys. An automated agent or back-end holds its authority in a cloud KMS. High-frequency, low-value actions are dominated by signature verification, not business logic, which makes Midnight uncompetitive for these workloads.

Goals

In priority order:

  1. Same cost class as the native path. A circuit that authorises an operation with one k1 or r1 signature should stay in the same proving domain (k) as its Jubjub-authorised equivalent, or within an agreed bounded factor, judged by measured k and proof time rather than by row count alone (see §4). This is measured on the Passport account operations above or an equivalent public reference workload.
  2. Full signer formats are covered. The cost bound includes each signer’s real message preparation: the WebAuthn authenticatorData ‖ SHA-256(clientDataJSON) construction, and EIP-191 and EIP-712 Keccak-256 digests. It is not limited to a prehashed curve check.
  3. Measured on the devices where proofs are made. Published, reproducible results cover at least one consumer laptop, one mobile device, and one in-browser prover. They report rows, k, proof time, peak memory, and prover-key size.
  4. No privacy or custody regression. Usable latency should not require users to disclose the signer’s public key or signature publicly. It should not require them to hand their witness to a third-party prover, unless they choose to. The signer key should stay in its hardware.
  5. Correct and auditable. Behaviour on edge cases, such as identity and invalid points, zero r or s, and malformed client data, is defined, and public test vectors cover it. High-s signatures from real signers verify, whether accepted directly or normalised.

Expected Outcomes

  • Products can offer passkey sign-in, hardware-bound mobile keys, HSM- and KMS-backed custody, and EVM-wallet authorisation without a proving penalty that rules out interactive use.
  • Developers can choose a signer for security and usability rather than proving cost, and they stop shipping app-held software keys as a workaround.
  • Institutional integrators can size their proving capacity predictably, with costs comparable to native-curve operations.
  • EVM users have a low-friction path into Midnight applications, which supports the interoperability goals of MPS-0010 and MPS-0011.
  • Smaller proving domains reduce prover-key size and distribution cost, which complements MPS-0039.
  • The ecosystem gains a standard signature-cost benchmark that can catch regressions, in line with MPS-0020.

Open Questions

  1. What latency budget counts as acceptable for interactive authorisation, and on which hardware classes? Who sets it: the Foundation, wallet partners, or a working group?
  2. How much of the measured cost comes from non-native field arithmetic in the current proof system, and how much comes from library implementation choices, such as the 0 × G identity check or byte-oriented hashing?
  3. What do proof time and peak memory look like on mid-range phones and in-browser proving? Is in-browser proving of a 218 circuit feasible at all on common devices?
  4. Is verifying the non-native signature outside the user’s proof acceptable for some use cases, for example at ledger level and bound to the contract call? What linkability or disclosure would that introduce?
  5. Should EIP-191 and EIP-712 Keccak envelopes be first-class targets alongside WebAuthn, and what does Keccak-256 currently cost in-circuit?
  6. How do the other non-native schemes compare under the same benchmark: Ed25519 (used by some HSMs and wallets), RSA (MPS-0009), and post-quantum schemes such as ML-DSA (upstream PR #434)? Can one set of solutions serve all of them, or does each scheme need its own?
  7. Should verifiers accept high-s P-256 signatures directly or normalise s in-circuit? What does each option cost, and what are the malleability implications?
  8. How should improvements be validated across Compact and proof-server versions so that results stay comparable over time?
  • Efficient in-circuit ECDSA verification over secp256k1 and P-256. This MIP should define how Compact and ZKIR verify k1 and r1 signatures at a cost compatible with Goal 1, and specify the identity-check semantics and test vectors. It addresses §2, the curve-check share of §3, and Goal 5, and it extends the performance criterion that MPS-0010 left open.
  • Efficient in-circuit hashing for signer envelopes. This MIP should cover SHA-256 over variable-length byte strings, such as WebAuthn client data, and Keccak-256 for EIP-191 and EIP-712, including the parsing and validation that WebAuthn requires. It addresses the 52.9% digest-preparation share in §3 and Goal 2, and relates to MPS-0008 and MPS-0011.
  • Signature-verification cost benchmark and reporting profile. This MIP should define reference workloads (standalone verifiers and representative account operations), hardware classes (desktop, laptop, mobile, and browser), required metrics, and a reproducible harness, with the Passport acc-profile experiment as one input. It addresses Goal 3 and the evidence limits above, and would sit under MPS-0020’s benchmarking work.
  • Evaluation of non-native signature verification outside the user proof. This MIP should analyse whether, and under what privacy trade-offs, a k1 or r1 signature can be checked outside the user’s proof while remaining bound to a contract call, possibly building on MIP-0003. It addresses Open Question 4 and must respect Goal 4.

References (Optional)

Acknowledgements

The Midnight Foundation and Input Output Group (IOG).

This MPS is licensed under CC-BY-4.0.