Docs: WebAuthn and P-256

Protocol

WebAuthn and P-256

Exactly what the account checks before it accepts a passkey signature, byte by byte, and what the RIP-7212 precompile on Elysium changes.

Signature format

userOp.signature starts with one type byte. 0x00 is a passkey signature, 0x01 a session key (see Session keys). Any other first byte fails validation. A passkey signature is:

0x00 ++ abi.encode(bytes32 keyId, WebAuthn.WebAuthnAuth auth)

struct WebAuthnAuth {          // OpenZeppelin utils/cryptography/WebAuthn.sol
    bytes32 r;
    bytes32 s;
    uint256 challengeIndex;    // offset of "challenge":"..." in clientDataJSON
    uint256 typeIndex;         // offset of "type":"..." in clientDataJSON
    bytes   authenticatorData;
    string  clientDataJSON;
}

keyId is keccak256(abi.encode(x, y)) of the passkey's public key. An account holds up to 8 passkeys, each stored with its x, y, rpIdHash and last signature counter. Authenticators return the ECDSA signature in DER; the client decodes it to (r, s) and normalises s to the low half before encoding.

userOp.signature

[0]0x00passkey path
bytes32keyIdkeccak256(abi.encode(x, y))
bytes32, bytes32r, ss at most n/2
uint256, uint256challengeIndex, typeIndexoffsets into clientDataJSON
bytesauthenticatorDataat least 37 bytes
stringclientDataJSONas returned by the browser

authenticatorData

[0:32]rpIdHashmust equal sha256(rpId) stored for this passkey
[32]flags
[33:37]signCountuint32, big-endian
Top: the account signature. Bottom: the 37 bytes of authenticatorData the account reads. UP and UV must be set; BS may be set only when BE is set.

What the account checks

HipAccount._validatePasskey runs these checks in this order. Any failure returns SIG_VALIDATION_FAILED (the EntryPoint reports AA24 signature error); nothing reverts, so a bad signature costs the bundler nothing beyond simulation.

  1. keyId names an active passkey of this account.
  2. authenticatorData is at least 37 bytes long.
  3. authenticatorData[0:32] equals the rpIdHash stored for that passkey.
  4. OpenZeppelin WebAuthn.verify(abi.encodePacked(userOpHash), auth, x, y, requireUV = true), which checks, in order:
    • clientDataJSON at typeIndex reads "type":"webauthn.get".
    • clientDataJSON at challengeIndex reads "challenge":" followed by base64url(userOpHash) and a closing quote.
    • The UP flag (user present, bit 0) is set.
    • The UV flag (user verified, bit 2) is set. This is the Face ID, Touch ID or PIN step.
    • BE and BS are consistent: the backup state bit (bit 4) may be set only if the backup eligibility bit (bit 3) is set.
    • P-256 verify(sha256(authenticatorData ++ sha256(clientDataJSON)), r, s, x, y), with r in (0, n), s in (0, n/2] and a valid public key.
  5. The signature counter rule (below). If it passes, the new counter is stored.

Both libraries are OpenZeppelin's audited WebAuthn and P256 from @openzeppelin/contracts. HIP-ID adds the rpIdHash binding and the counter rule on top; it does not reimplement any cryptography.

authenticatorData

The account reads three fields: the rpIdHash in bytes 0 to 31, the flags byte at 32, and the 4-byte big-endian counter at 33 to 36. Anything after byte 37 (attested credential data, extensions) is covered by the signature but not interpreted.

FlagBitRule
UP, user present0x01Required
UV, user verified0x04Required
BE, backup eligible0x08Free
BS, backed up0x10Allowed only together with BE

The challenge

The WebAuthn challenge is the 32-byte ERC-4337 userOpHash itself. The browser places it in clientDataJSON as base64url without padding (43 characters). A typical clientDataJSON:

{"type":"webauthn.get","challenge":"<base64url(userOpHash), 43 chars>","origin":"https://<site>","crossOrigin":false}

Because the userOpHash commits to the sender, nonce, initCode, callData, gas limits, fees, paymasterAndData, the EntryPoint address and the chain id, a signature is valid for exactly one operation on one chain. Replaying it fails on the nonce.

What is not checked on-chain

The origin, crossOrigin and topOrigin fields are not parsed by the contract. The binding to the site is the rpIdHash in authenticatorData, which the authenticator writes and signs. The browser only lets a page request an assertion for an rpId equal to its own domain or a registrable suffix of it, or for an rpId whose /.well-known/webauthn lists the page's origin (Related Origin Requests).

rpId binding

A passkey is bound to the site's domain, its rpId. The account stores sha256(rpId) with each passkey, and the factory mixes it into the account address through the CREATE2 salt keccak256(abi.encode(x, y, rpIdHash, salt)). Two consequences:

  • A passkey made on one domain does not sign for another. The browser refuses to use it for a different rpId, and if it ever did, the authenticatorData would carry a different rpIdHash and the account would refuse it. test_otherRpIdFails signs with the same key under another rpId and checks the refusal.
  • The same key under a different rpId gives a different account address. An account created on this site is reached through this site's rpId, or through any other passkey you add to it.

Domains and related origins

HIP-ID lives at hipid.app. Passkeys created there, and on www.hipid.app, use the rpId hipid.app. Accounts created before the move have passkeys bound to hipid-green.vercel.app. An rpId is part of the passkey and of the account address, so those accounts keep it for life, and they keep working from hipid.app through WebAuthn Related Origin Requests:

  1. https://hipid-green.vercel.app/.well-known/webauthn returns {"origins":["https://hipid.app","https://www.hipid.app"]} as application/json.
  2. A page on hipid.app asks for an assertion with rpId: "hipid-green.vercel.app". The browser fetches that file, finds its own origin listed, and lets the passkey sign. The authenticatorData carries sha256("hipid-green.vercel.app"), exactly what the account stored, so nothing changes on chain.
  3. Opening the old domain forwards to hipid.app and carries the account record (credential id, public key, rpId) in the URL fragment, which never reaches a server. hipid.app keeps it only after the passkey signs a fresh challenge that the page verifies against that public key, so a crafted link cannot plant another account in your browser.

Related Origin Requests ship in Chrome and Edge 128+, Safari 18+ and Firefox 152+. A browser without them cannot use an old-domain passkey on hipid.app; the app then links to hipid-green.vercel.app/app?stay=1, where the account works as before. The list holds two registrable labels (hipid, hipid-green), well inside the five that browsers support.

Signature counter

WebAuthn Level 3 section 6.1.1 step 21 describes clone detection with the authenticator's signature counter. The account applies it like this:

uint32 count = authenticatorData[33:37];
if (count != 0 || stored != 0) {
    require(count > stored);   // else SIG_VALIDATION_FAILED
    stored = count;
}

Synced passkeys (iCloud Keychain, Google Password Manager) report 0 forever, so for them the rule never triggers. Device-bound authenticators such as hardware security keys increment the counter, and once a counter has been seen it must strictly increase. An assertion from a cloned authenticator replaying a lower counter is refused even if its signature is valid (test_signCountMustIncrease). The stored counter is kept if a passkey is removed and added again.

Low-s only

For every ECDSA signature (r, s) there is a second valid signature (r, n - s). OpenZeppelin's P256 accepts only s at most n/2, which removes that malleability. Authenticators may return either form, so the SDK flips a high s before encoding. test_highSRejected submits the high-s twin of a real signature and checks it is refused.

RIP-7212 at 0x100

Elysium exposes the RIP-7212 P-256 verifier at address 0x100. Its input is 160 bytes, hash ++ r ++ s ++ x ++ y; its output is 32 bytes equal to 1 for a valid signature and empty otherwise. OpenZeppelin's P256.verify calls it first and falls back to its Solidity implementation only if the precompile is absent.

We checked the precompile against the full Wycheproof suite for ECDSA P-256 with SHA-256 (P1363 encoding): 262 vectors, 173 valid and 89 invalid, 0 mismatches. Every Wycheproof ECDSA P-256 SHA-256 (P1363) vector sent to 0x100 on Elysium mainnet in one eth_call (harness injected by state override). The median gas of one staticcall for a valid vector was 7,495. The script is scripts/wycheproof-rip7212.py, the harness contracts/src/probe/Rip7212Batch.sol (never deployed), and the results are in contracts/test/vectors/rip7212-elysium-results.json.

RIP-7212 precompile at 0x1007,773 gas
OpenZeppelin Solidity fallback232,372 gas
Gas for one P-256 verification of the same signature. P256GasProbe.measure on Elysium mainnet: the same passkey signature verified through both paths in one transaction.

The precompile path is about 30 times cheaper than the Solidity path for the same signature.

The same measurement on Elysium mainnet: 0xcf374da0293182472501801f38979e6801f967dfc466dbcf7b86d4b9be0c61c6.

The first passkey-signed operation on Elysium mainnet: 0x8127b6f608f89a09062d0f3250257f790569d1a773bd5fa34a1da9174d508a13.

Tests

The account tests use real WebAuthn assertions, not hand-built bytes. scripts/webauthn-sign.mjs drives Chrome's CDP virtual authenticator with a fixed test credential and returns the authenticatorData, clientDataJSON and signature exactly as a browser produces them.

TestChecks
test_realPasskeyAssertionValidatesA real assertion validates and stores the counter
test_wrongChallengeFailsAn assertion over another hash is refused
test_otherRpIdFailsThe same key signing for another rpId is refused
test_highSRejectedThe high-s twin is refused
test_signCountMustIncreaseA lower counter after a higher one is refused
test_tamperedClientDataFailsOne extra byte in clientDataJSON breaks the signature
test_unknownKeyFailsAn unknown keyId is refused
test_fullPathPasskeySponsoredFirstOpElysium mainnet fork: deploy by initCode, passkey, call, paymaster, then a second op
test_replayedAssertionRefusedFork: the same signed op cannot be included twice