nostr:npub1e0z776cpe0gllgktjk54fuzv8pdfxmq6smsmh8xd7t8s7n474n9smk0txy recently mentioned that sighash flags are neater than raw script opcodes to achieve the same thing. I want to gently disagree: I think of sighhash flags as a shortcut, which ideally would *expand* into script. Something like (untested!):
# Split flags word(s) off from signature, leaving
OP_DUP OP_SIZE 64 OP_SUB OP_LEFT:
# Enforce any "you must set this" flags.
# Extract those parts of the tx onto the stack, append the flags, and hash them.
OP_DUP OP_TX OP_SWAP OP_CAT OP_SHA256
# Now cut the flags word(s) off the signature copy, leaving "
OP_SWAP OP_SIZE 64 OP_SUB OP_RIGHT
# Check the signature.
OP_CHECKSIGFROMSTACK OP_VERIFY
You can actually see how OP_SPLIT would help us here, but also you can see exactly how much work OP_CHECKSIG does under the covers!