txscript: Only do CSV txver check if enabled.

The CSV consensus rules dictate that the opcode fails when the
transaction version is not at least version 2, however that only applies
if the disable flag is not set in the sequence.

This is not an issue at the current time because we do not yet enforce
CSV at a consensus level, however, I noticed this discrepancy when doing
a thorough audit of the CSV paths due to the ongoing work to add full
consensus-enforced CSV support.

As a result, this must be merged prior to enabling consensus enforcement
for CSV or it would open up the potential for a hard fork.
This commit is contained in:
Dave Collins 2016-12-03 01:13:24 -06:00
parent 318c4760c0
commit bc576b13b4
No known key found for this signature in database
GPG key ID: B8904D9D9C93D1F2

View file

@ -1117,11 +1117,6 @@ func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error {
return nil return nil
} }
if vm.tx.Version < 2 {
return fmt.Errorf("invalid transaction version: %d",
vm.tx.Version)
}
// The current transaction sequence is a uint32 resulting in a maximum // The current transaction sequence is a uint32 resulting in a maximum
// sequence of 2^32-1. However, scriptNums are signed and therefore a // sequence of 2^32-1. However, scriptNums are signed and therefore a
// standard 4-byte scriptNum would only support up to a maximum of // standard 4-byte scriptNum would only support up to a maximum of
@ -1156,6 +1151,13 @@ func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error {
return nil return nil
} }
// Transaction version numbers not high enough to trigger CSV rules must
// fail.
if vm.tx.Version < 2 {
return fmt.Errorf("invalid transaction version: %d",
vm.tx.Version)
}
// Sequence numbers with their most significant bit set are not // Sequence numbers with their most significant bit set are not
// consensus constrained. Testing that the transaction's sequence // consensus constrained. Testing that the transaction's sequence
// number does not have this bit set prevents using this property // number does not have this bit set prevents using this property