This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Verify ECDSA signatures against public keys to authenticate messages. Signature verification is the cornerstone of Ethereum’s security model - every transaction must pass verification before execution.
ECDSA verification confirms that a signature was created by the private key corresponding to a given public key. The verifier needs:
Signature (r, s, v) - 65 bytes total
Message hash - 32 bytes (what was signed)
Public key - 64 bytes uncompressed (x || y coordinates)
Verification succeeds if the signature was created by the matching private key, fails otherwise. No secret information is revealed during verification - it’s safe to perform publicly.
The signature was created as: s = k^-1 * (e + r * private_key) mod nRearranging: k = s^-1 * (e + r * private_key) mod nSince R = k * G and public_key = private_key * G:
Copy
Ask AI
R = k * G = s^-1 * (e + r * private_key) * G = s^-1 * e * G + s^-1 * r * private_key * G = (e * s^-1) * G + (r * s^-1) * public_key
This matches step 4 above. If the signature is valid, R.x == r.
function isValidSignatureComponents(r: bigint, s: bigint): boolean { const n = SECP256K1_N; // Curve order // r must be in [1, n-1] if (r < 1n || r >= n) return false; // s must be in [1, n-1] if (s < 1n || s >= n) return false; // Ethereum enforces low-s (s ≤ n/2) to prevent malleability if (s > n / 2n) return false; return true;}
function isValidPublicKey(pubkey: Uint8Array): boolean { if (pubkey.length !== 64) return false; // Parse x and y coordinates const x = bytesToBigInt(pubkey.slice(0, 32)); const y = bytesToBigInt(pubkey.slice(32, 64)); // Check point is on curve: y² = x³ + 7 (mod p) const p = SECP256K1_P; // Field prime const y2 = (y * y) % p; const x3_plus_7 = (x * x * x + 7n) % p; return y2 === x3_plus_7;}
Invalid public keys (not on curve) always fail verification.
The v component is only needed for public key recovery (ecRecover). Standard verification ignores it because the public key is already provided.
Copy
Ask AI
// v is ignored during verification (only r and s matter)const sig1 = { r, s, v: 27 };const sig2 = { r, s, v: 28 };// Both verify the same way if public key is providedverify(sig1, hash, pubkey) === verify(sig2, hash, pubkey);
For recovery-based verification (like Ethereum’s ecRecover), v is critical.