Script Validation

Lesson, slides, and applied problem sets.

View Slides

Lesson

Script Validation (P2PKH-lite)

Why this module exists

Bitcoin uses a stack-based scripting language to express spending rules. Even a minimal subset reveals the structure of real validation.


1) P2PKH flow

Pay-to-PubKey-Hash uses two scripts:

  • scriptSig: pushes signature and pubkey
  • scriptPubKey: verifies hash + signature

Execution steps:

  1. Push sig + pubkey
  2. Duplicate pubkey
  3. Hash pubkey and compare to expected
  4. Verify signature

2) Hashing and signatures

  • We use HASH256 (double SHA-256) instead of HASH160
  • ECDSA over P-256 (toy stand-in for secp256k1)
  • Signature hash is simplified but deterministic

3) Failure modes

  • Stack underflow or invalid opcodes
  • Incorrect pubkey hash
  • Signature mismatch

Any failure must make the script invalid.


What you will build

  1. Script parsing (pushdata + opcodes)
  2. Stack execution for P2PKH
  3. ECDSA signature verification

Key takeaways

  • Script execution is deterministic and strict.
  • Small parsing errors lead to consensus splits.
  • Validation is the core of trustlessness.

Module Items