From bc576b13b4d3abd1df98f35fc7d30e9500048b7b Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 3 Dec 2016 01:13:24 -0600 Subject: [PATCH] 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. --- txscript/opcode.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/txscript/opcode.go b/txscript/opcode.go index 0d72b663..0a81b45b 100644 --- a/txscript/opcode.go +++ b/txscript/opcode.go @@ -1117,11 +1117,6 @@ func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error { 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 // sequence of 2^32-1. However, scriptNums are signed and therefore a // 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 } + // 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 // consensus constrained. Testing that the transaction's sequence // number does not have this bit set prevents using this property