Tighten the check for pay-to-pubkey scripts.

This commit tightens the check for a pay-to-pubkey script by ensuring the
length of the pubkey is one of the two valid values of 33 or 65.  This
mirrors the checks in the multisig script type check as well.

ok @owainga
This commit is contained in:
Dave Collins 2014-02-21 02:11:11 -06:00
parent 982f282e10
commit da1fcc6dbd

View file

@ -204,9 +204,9 @@ func isSmallInt(op *opcode) bool {
// isPubkey returns true if the script passed is a pubkey transaction, false // isPubkey returns true if the script passed is a pubkey transaction, false
// otherwise. // otherwise.
func isPubkey(pops []parsedOpcode) bool { func isPubkey(pops []parsedOpcode) bool {
// valid pubkeys are either 33 or 65 bytes
return len(pops) == 2 && return len(pops) == 2 &&
pops[0].opcode.value > OP_FALSE && (len(pops[0].data) == 33 || len(pops[0].data) == 65) &&
pops[0].opcode.value <= OP_DATA_75 &&
pops[1].opcode.value == OP_CHECKSIG pops[1].opcode.value == OP_CHECKSIG
} }