Script Validation (P2PKH-lite)
Implementation-first walk through of a strict, minimal script engine.
1 / 12
Implementation-first walk through of a strict, minimal script engine.
HASH256 (double SHA-256)P-256 (toy stand-in)0x76 DUP0xAA HASH2560x88 EQUALVERIFY0xAC CHECKSIGAnything else is invalid.
At byte script[i]:
1..75 => pushdata length n, then push next n bytesMalformed push length => fail immediately.
Execute:
scriptSig (push signature + pubkey)scriptPubKey (DUP HASH256 <hash> EQUALVERIFY CHECKSIG)Single shared stack across both scripts.
DUP: duplicate topHASH256: replace top with hashEQUALVERIFY: pop 2, compare, fail if mismatchCHECKSIG: pop pubkey then signature, verify, push 1/0Any underflow => fail.
0x04 || X(32) || Y(32)P-256 curveecdsa.VerifyASN1S = HASH256(tx.ID || uint32_le(inputIndex) || scriptPubKey)
Gotchas:
Script succeeds iff:
Otherwise fail.
Must return false on:
i