Script Validation
Lesson, slides, and applied problem sets.
View SlidesLesson
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 pubkeyscriptPubKey: verifies hash + signature
Execution steps:
- Push sig + pubkey
- Duplicate pubkey
- Hash pubkey and compare to expected
- 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
- Script parsing (pushdata + opcodes)
- Stack execution for P2PKH
- ECDSA signature verification
Key takeaways
- Script execution is deterministic and strict.
- Small parsing errors lead to consensus splits.
- Validation is the core of trustlessness.