txscript: Make isSmallInt accept raw opcode.
This converts the isSmallInt function to accept an opcode as a byte instead of the internal opcode data struct in order to make it more flexible for raw script analysis. The comment is modified to explicitly call out the script version semantics. Finally, it updates all callers accordingly.
This commit is contained in:
parent
c6f4cafe57
commit
583b74040d
2 changed files with 13 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
// Copyright (c) 2013-2017 The btcsuite developers
|
// Copyright (c) 2013-2017 The btcsuite developers
|
||||||
|
// Copyright (c) 2015-2019 The Decred developers
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
@ -45,11 +46,12 @@ const (
|
||||||
|
|
||||||
// isSmallInt returns whether or not the opcode is considered a small integer,
|
// isSmallInt returns whether or not the opcode is considered a small integer,
|
||||||
// which is an OP_0, or OP_1 through OP_16.
|
// which is an OP_0, or OP_1 through OP_16.
|
||||||
func isSmallInt(op *opcode) bool {
|
//
|
||||||
if op.value == OP_0 || (op.value >= OP_1 && op.value <= OP_16) {
|
// NOTE: This function is only valid for version 0 opcodes. Since the function
|
||||||
return true
|
// does not accept a script version, the results are undefined for other script
|
||||||
}
|
// versions.
|
||||||
return false
|
func isSmallInt(op byte) bool {
|
||||||
|
return op == OP_0 || (op >= OP_1 && op <= OP_16)
|
||||||
}
|
}
|
||||||
|
|
||||||
// isScriptHash returns true if the script passed is a pay-to-script-hash
|
// isScriptHash returns true if the script passed is a pay-to-script-hash
|
||||||
|
@ -136,7 +138,7 @@ func IsWitnessProgram(script []byte) bool {
|
||||||
// bytes.
|
// bytes.
|
||||||
func isWitnessProgram(pops []parsedOpcode) bool {
|
func isWitnessProgram(pops []parsedOpcode) bool {
|
||||||
return len(pops) == 2 &&
|
return len(pops) == 2 &&
|
||||||
isSmallInt(pops[0].opcode) &&
|
isSmallInt(pops[0].opcode.value) &&
|
||||||
canonicalPush(pops[1]) &&
|
canonicalPush(pops[1]) &&
|
||||||
(len(pops[1].data) >= 2 && len(pops[1].data) <= 40)
|
(len(pops[1].data) >= 2 && len(pops[1].data) <= 40)
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,10 +115,10 @@ func isMultiSig(pops []parsedOpcode) bool {
|
||||||
if l < 4 {
|
if l < 4 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !isSmallInt(pops[0].opcode) {
|
if !isSmallInt(pops[0].opcode.value) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !isSmallInt(pops[l-2].opcode) {
|
if !isSmallInt(pops[l-2].opcode.value) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if pops[l-1].opcode.value != OP_CHECKMULTISIG {
|
if pops[l-1].opcode.value != OP_CHECKMULTISIG {
|
||||||
|
@ -153,7 +153,7 @@ func isNullData(pops []parsedOpcode) bool {
|
||||||
|
|
||||||
return l == 2 &&
|
return l == 2 &&
|
||||||
pops[0].opcode.value == OP_RETURN &&
|
pops[0].opcode.value == OP_RETURN &&
|
||||||
(isSmallInt(pops[1].opcode) || pops[1].opcode.value <=
|
(isSmallInt(pops[1].opcode.value) || pops[1].opcode.value <=
|
||||||
OP_PUSHDATA4) &&
|
OP_PUSHDATA4) &&
|
||||||
len(pops[1].data) <= MaxDataCarrierSize
|
len(pops[1].data) <= MaxDataCarrierSize
|
||||||
}
|
}
|
||||||
|
@ -705,7 +705,7 @@ func ExtractAtomicSwapDataPushes(version uint16, pkScript []byte) (*AtomicSwapDa
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
pushes.SecretSize = int64(locktime)
|
pushes.SecretSize = int64(locktime)
|
||||||
} else if op := pops[2].opcode; isSmallInt(op) {
|
} else if op := pops[2].opcode; isSmallInt(op.value) {
|
||||||
pushes.SecretSize = int64(asSmallInt(op))
|
pushes.SecretSize = int64(asSmallInt(op))
|
||||||
} else {
|
} else {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -716,7 +716,7 @@ func ExtractAtomicSwapDataPushes(version uint16, pkScript []byte) (*AtomicSwapDa
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
pushes.LockTime = int64(locktime)
|
pushes.LockTime = int64(locktime)
|
||||||
} else if op := pops[11].opcode; isSmallInt(op) {
|
} else if op := pops[11].opcode; isSmallInt(op.value) {
|
||||||
pushes.LockTime = int64(asSmallInt(op))
|
pushes.LockTime = int64(asSmallInt(op))
|
||||||
} else {
|
} else {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
Loading…
Reference in a new issue