07 - hashSequence

The hashSequence field is the hash of the concatenation of the nSequence values of all inputs being signed. The make-up of the Hash of nSequence is dependent on whether SIGHASH_ANYONECANPAY flag is used.

If SIGHASH_ANYONECANPAY is NOT used, the hash value is a SHA256 hash of a concatenated list of the sequence number of each of the transaction's inputs.

If SIGHASH_ANYONECANPAY is used, the value is a 32 byte null string.

Example: Check all sequence values are final

In this example, the script checks that two inputs are used, and that the input is final. To perform the check, the hash of sequence will be split from r_tx_preimg and tested against a hash of the expected value.

It is assumed that version and hash_prevouts have both been removed from r_tx_preimage.

Stack
Script
Description

<r_tx_preimg>

...

nVersion field and hashPrevouts have been removed

<r_tx_preimg>

0x20

add hash_nSequence length to the stack

<r_tx_preimg> 0x20

OP_SPLIT

Split hash_nSequence from pre-image

<hash_nSequence> <rr_tx_preimg>

OP_SWAP

Swap hash_nSequence to front

<rr_tx_preimg> <hash_nSequence>

0xffffffffffffffff

Expected sequence value if two final inputs are used

<rr_tx_preimg> <hash_nSequence> 0xffffffffffffffff

OP_SHA256

Hash sequence value

<rr_tx_preimg> <hash_nSequence> <sha256_ffffffff>

OP_EQUALVERIFY

Check it is equal - fail if not

<rr_tx_preimg>

...

rest of script

This gives us a useful tool for managing closure of payment channels, providing an optimal processing path for channels submitted with fully final inputs.

Last updated

Was this helpful?