{
  "schema_version": 1,
  "title": "Creating and verifying signatures",
  "url": "/writing/understanding-elliptic-curves/lessons/0005-signature-creation-and-verification.html",
  "author": "Abhineet Biju",
  "text": "Chapter V · digital signatures Creating and verifying signatures Objective explain signing and verification Solana transaction signatures Model simplified signature equation You can use a signature to prove that a private key authorized one exact message without revealing the key. The public-key relationship used by signatures You already know the key relationship: Q = kGKeep k private. Publish Q and G. Anyone can see Q, but production parameters make recovering k infeasible. Signatures use this same relationship. Signer knowsprivate scalar k creates evidence Verifier knowspublic point Q A signature proves that someone who knows the secret behind Q approved one exact message. It does not reveal the secret and it does not encrypt the message. Create a signature for one message Let's build a simplified Schnorr-shaped signature to see the core EdDSA relationship: The signer creates a one-message secret r and its public point R = rG. A hash binds R, Q, and the message m into a challenge h. The signer combines both secrets into s = r + hk. The published signature is (R, s). Neither k nor r is published. Lowercase r is the one-message secret nonce scalar. Uppercase R=rG is its public curve point. Although h and s are public, they bind the hidden scalars without exposing them. Reusing the same r for two messages creates two equations that can reveal k. To verify the signature, we recompute h and check: sG ?= R + hQ The equation works because: sG = (r + hk)G sG = rG + h(kG) sG = R + hQ The verifier replaces the secret-derived terms rG and kG with their public points R and Q. Matching sides show that the signature has the right hidden relationship. Quick check 1 What gives the signer its unique ability? Verify that the message has not changed Sign the default message, then change send 5 SOL to send 6 SOL. You will see the hash change and the verification equation fail. The stored signature does not change; the same signature simply stops verifying against the modified message. Toy private scalar k Signer keeps The private scalar stays inside the signer. k is hidden Everyone knows The public point identifies the signer. Signer publishes The signature contains R and s, not k. Message to sign Message presented to verifier sGmust equalR + hQ No signature to verify yet. Show the toy arithmetic This uses an insecure 19-element group and a toy hash to expose the relationship. One-message secret Message challenge Signer response Quick check 2 What should changing the signed message do? Solana transaction signatures When your wallet signs a Solana transaction, it signs the serialized message with Ed25519. If you change an instruction, account, amount, or recent blockhash, the bytes change and the signature becomes invalid. A valid signature authorizes those exact bytes. It does not prove that a wallet's human-readable description matched the signer's intent. A PDA has no Ed25519 private key. During invoke_signed, the runtime checks the program ID and seeds and grants signer privilege for that CPI. Transaction signerPrivate key signs exact message bytes. Public key verifies them. Program addressNo private key exists. Runtime seed derivation grants CPI authority. Ed25519 has exact hashing, scalar derivation, encoding, and cofactor rules. Use audited libraries. The equation here explains the relationship; it is not production implementation code. Check your understanding Try to answer each question before you open the solutions. Why can Q=kG be public while k remains private? What does a signature prove, and what does it not hide? How can the verifier check sG=R+hQ without knowing k? Why does changing the message invalidate the signature? How does Solana PDA authorization differ from an Ed25519 signature? Show numbered solutions Double-and-add computes Q=kG efficiently. Recovering k from G and Q requires solving the discrete logarithm problem, which is infeasible at production scale. A valid signature proves that the private-key holder authorized the exact message. It detects changes but does not encrypt the message or prove that a human-readable interpretation matched the signer's intent. Lowercase r is the hidden nonce scalar, while uppercase R=rG is its public point. The signer publishes R and s=r+hk. Multiplying by G gives sG=rG+h(kG)=R+hQ, so the verifier can compute both sides from public values. Reusing r for two challenges creates two equations that can reveal k. The challenge h=H(R,Q,m) binds the equation to m. A changed message produces a different challenge, so the unchanged stored signature fails against the modified message. A wallet produces an Ed25519 signature. A PDA has no private key. During a CPI, invoke_signed re-derives the PDA from its seeds, bump, and program ID and grants signer privilege when the address matches. Primary reading RFC 8032, sections 3.2 through 3.4 defines EdDSA keys, signing, and verification. Solana's transaction documentation connects signatures to serialized transaction messages and signer public keys. Solana's PDA documentation explains off-curve addresses and `invoke_signed` authorization.",
  "headings": [
    {
      "level": 1,
      "id": null,
      "text": "Creating and verifying signatures"
    },
    {
      "level": 2,
      "id": null,
      "text": "The public-key relationship used by signatures"
    },
    {
      "level": 2,
      "id": null,
      "text": "Create a signature for one message"
    },
    {
      "level": 3,
      "id": null,
      "text": "Quick check 1"
    },
    {
      "level": 2,
      "id": null,
      "text": "Verify that the message has not changed"
    },
    {
      "level": 3,
      "id": null,
      "text": "Signer keeps"
    },
    {
      "level": 3,
      "id": null,
      "text": "Everyone knows"
    },
    {
      "level": 3,
      "id": null,
      "text": "Signer publishes"
    },
    {
      "level": 3,
      "id": null,
      "text": "Quick check 2"
    },
    {
      "level": 2,
      "id": null,
      "text": "Solana transaction signatures"
    },
    {
      "level": 2,
      "id": null,
      "text": "Check your understanding"
    },
    {
      "level": 3,
      "id": null,
      "text": "Primary reading"
    }
  ],
  "sections": [
    {
      "id": "bridge",
      "heading": "The public-key relationship used by signatures",
      "text": "The public-key relationship used by signatures You already know the key relationship: Q = kGKeep k private. Publish Q and G. Anyone can see Q, but production parameters make recovering k infeasible. Signatures use this same relationship. Signer knowsprivate scalar k creates evidence Verifier knowspublic point Q A signature proves that someone who knows the secret behind Q approved one exact message. It does not reveal the secret and it does not encrypt the message."
    },
    {
      "id": "signature-creation",
      "heading": "Create a signature for one message",
      "text": "Create a signature for one message Let's build a simplified Schnorr-shaped signature to see the core EdDSA relationship: The signer creates a one-message secret r and its public point R = rG. A hash binds R, Q, and the message m into a challenge h. The signer combines both secrets into s = r + hk. The published signature is (R, s). Neither k nor r is published. Lowercase r is the one-message secret nonce scalar. Uppercase R=rG is its public curve point. Although h and s are public, they bind the hidden scalars without exposing them. Reusing the same r for two messages creates two equations that can reveal k. To verify the signature, we recompute h and check: sG ?= R + hQ The equation works because: sG = (r + hk)G sG = rG + h(kG) sG = R + hQ The verifier replaces the secret-derived terms rG and kG with their public points R and Q. Matching sides show that the signature has the right hidden relationship. Quick check 1 What gives the signer its unique ability?"
    },
    {
      "id": "try",
      "heading": "Verify that the message has not changed",
      "text": "Verify that the message has not changed Sign the default message, then change send 5 SOL to send 6 SOL. You will see the hash change and the verification equation fail. The stored signature does not change; the same signature simply stops verifying against the modified message. Toy private scalar k Signer keeps The private scalar stays inside the signer. k is hidden Everyone knows The public point identifies the signer. Signer publishes The signature contains R and s, not k. Message to sign Message presented to verifier sGmust equalR + hQ No signature to verify yet. Show the toy arithmetic This uses an insecure 19-element group and a toy hash to expose the relationship. One-message secret Message challenge Signer response Quick check 2 What should changing the signed message do?"
    },
    {
      "id": "solana",
      "heading": "Solana transaction signatures",
      "text": "Solana transaction signatures When your wallet signs a Solana transaction, it signs the serialized message with Ed25519. If you change an instruction, account, amount, or recent blockhash, the bytes change and the signature becomes invalid. A valid signature authorizes those exact bytes. It does not prove that a wallet's human-readable description matched the signer's intent. A PDA has no Ed25519 private key. During invoke_signed, the runtime checks the program ID and seeds and grants signer privilege for that CPI. Transaction signerPrivate key signs exact message bytes. Public key verifies them. Program addressNo private key exists. Runtime seed derivation grants CPI authority. Ed25519 has exact hashing, scalar derivation, encoding, and cofactor rules. Use audited libraries. The equation here explains the relationship; it is not production implementation code."
    },
    {
      "id": "close",
      "heading": "Check your understanding",
      "text": "Check your understanding Try to answer each question before you open the solutions. Why can Q=kG be public while k remains private? What does a signature prove, and what does it not hide? How can the verifier check sG=R+hQ without knowing k? Why does changing the message invalidate the signature? How does Solana PDA authorization differ from an Ed25519 signature? Show numbered solutions Double-and-add computes Q=kG efficiently. Recovering k from G and Q requires solving the discrete logarithm problem, which is infeasible at production scale. A valid signature proves that the private-key holder authorized the exact message. It detects changes but does not encrypt the message or prove that a human-readable interpretation matched the signer's intent. Lowercase r is the hidden nonce scalar, while uppercase R=rG is its public point. The signer publishes R and s=r+hk. Multiplying by G gives sG=rG+h(kG)=R+hQ, so the verifier can compute both sides from public values. Reusing r for two challenges creates two equations that can reveal k. The challenge h=H(R,Q,m) binds the equation to m. A changed message produces a different challenge, so the unchanged stored signature fails against the modified message. A wallet produces an Ed25519 signature. A PDA has no private key. During a CPI, invoke_signed re-derives the PDA from its seeds, bump, and program ID and grants signer privilege when the address matches. Primary reading RFC 8032, sections 3.2 through 3.4 defines EdDSA keys, signing, and verification. Solana's transaction documentation connects signatures to serialized transaction messages and signer public keys. Solana's PDA documentation explains off-curve addresses and `invoke_signed` authorization."
    }
  ],
  "links": [
    {
      "label": "writing",
      "url": "/#writing"
    },
    {
      "label": "Chapter IV",
      "url": "/writing/understanding-elliptic-curves/lessons/0004-scalar-multiplication-and-keypairs.html"
    },
    {
      "label": "Glossary",
      "url": "/writing/understanding-elliptic-curves/reference/0001-cryptography-glossary.html"
    },
    {
      "label": "RFC 8032, sections 3.2 through 3.4",
      "url": "https://www.rfc-editor.org/rfc/rfc8032.html#section-3.2"
    },
    {
      "label": "Solana's transaction documentation",
      "url": "https://solana.com/docs/core/transactions"
    },
    {
      "label": "Solana's PDA documentation",
      "url": "https://solana.com/docs/core/pda"
    },
    {
      "label": "Previous: Scalar multiplication and keypairs",
      "url": "/writing/understanding-elliptic-curves/lessons/0004-scalar-multiplication-and-keypairs.html"
    },
    {
      "label": "Next: Solana wallet and PDA authorization",
      "url": "/writing/understanding-elliptic-curves/lessons/0006-solana-wallet-and-pda-authorization.html"
    }
  ]
}
