txscript: Remove ScriptCanonicalSignatures

Remove ScriptCanonicalSignatures and use the new
ScriptVerifyDERSignatures flag.  The ScriptVerifyDERSignatures
flag accomplishes the same functionality.
This commit is contained in:
David Hill 2015-02-14 09:37:47 -05:00
parent bc6be3ba69
commit f79c72f18a
6 changed files with 17 additions and 36 deletions

View file

@ -47,7 +47,7 @@ const (
// different than what is required for the consensus rules in that they // different than what is required for the consensus rules in that they
// are more strict. // are more strict.
standardScriptVerifyFlags = txscript.ScriptBip16 | standardScriptVerifyFlags = txscript.ScriptBip16 |
txscript.ScriptCanonicalSignatures | txscript.ScriptVerifyDERSignatures |
txscript.ScriptStrictMultiSig | txscript.ScriptStrictMultiSig |
txscript.ScriptDiscourageUpgradableNops txscript.ScriptDiscourageUpgradableNops
) )

View file

@ -166,7 +166,7 @@ func ExampleSignTxOutput() {
// Prove that the transaction has been validly signed by executing the // Prove that the transaction has been validly signed by executing the
// script pair. // script pair.
flags := txscript.ScriptBip16 | txscript.ScriptCanonicalSignatures | flags := txscript.ScriptBip16 | txscript.ScriptVerifyDERSignatures |
txscript.ScriptStrictMultiSig | txscript.ScriptStrictMultiSig |
txscript.ScriptDiscourageUpgradableNops txscript.ScriptDiscourageUpgradableNops
s, err := txscript.NewScript(redeemTx.TxIn[0].SignatureScript, s, err := txscript.NewScript(redeemTx.TxIn[0].SignatureScript,

View file

@ -1807,7 +1807,7 @@ func opcodeCheckSig(op *parsedOpcode, s *Script) error {
} }
var signature *btcec.Signature var signature *btcec.Signature
if s.der || s.verifyStrictEncoding || s.verifyDERSignatures { if s.verifyStrictEncoding || s.verifyDERSignatures {
signature, err = btcec.ParseDERSignature(sigStr, btcec.S256()) signature, err = btcec.ParseDERSignature(sigStr, btcec.S256())
} else { } else {
signature, err = btcec.ParseSignature(sigStr, btcec.S256()) signature, err = btcec.ParseSignature(sigStr, btcec.S256())
@ -1967,7 +1967,7 @@ func opcodeCheckMultiSig(op *parsedOpcode, s *Script) error {
// Parse the signature. // Parse the signature.
var err error var err error
if s.der || s.verifyStrictEncoding || s.verifyDERSignatures { if s.verifyStrictEncoding || s.verifyDERSignatures {
parsedSig, err = btcec.ParseDERSignature(signature, parsedSig, err = btcec.ParseDERSignature(signature,
btcec.S256()) btcec.S256())
} else { } else {

View file

@ -19,7 +19,7 @@ func TestScripts(t *testing.T) {
tests := []struct { tests := []struct {
script []byte script []byte
canonical bool strictSigs bool
shouldPass bool shouldPass bool
shouldFail error shouldFail error
}{ }{
@ -383,7 +383,6 @@ func TestScripts(t *testing.T) {
0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70,
0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c,
txscript.OP_1, txscript.OP_CHECKMULTISIG}, txscript.OP_1, txscript.OP_CHECKMULTISIG},
canonical: false,
shouldPass: false}, shouldPass: false},
{script: []byte{txscript.OP_1, txscript.OP_1, txscript.OP_DATA_65, {script: []byte{txscript.OP_1, txscript.OP_1, txscript.OP_DATA_65,
0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13,
@ -394,7 +393,7 @@ func TestScripts(t *testing.T) {
0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70,
0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c,
txscript.OP_1, txscript.OP_CHECKMULTISIG}, txscript.OP_1, txscript.OP_CHECKMULTISIG},
canonical: true, strictSigs: true,
shouldPass: false}, shouldPass: false},
/* up here because no defined error case. */ /* up here because no defined error case. */
{script: []byte{txscript.OP_1, txscript.OP_1, txscript.OP_DATA_65, {script: []byte{txscript.OP_1, txscript.OP_1, txscript.OP_DATA_65,
@ -504,8 +503,8 @@ func TestScripts(t *testing.T) {
for i, test := range tests { for i, test := range tests {
// Parse and execute the test script. // Parse and execute the test script.
var flags txscript.ScriptFlags var flags txscript.ScriptFlags
if test.canonical { if test.strictSigs {
flags = txscript.ScriptCanonicalSignatures flags = txscript.ScriptVerifyDERSignatures
} }
mockTx.TxOut[0].PkScript = test.script mockTx.TxOut[0].PkScript = test.script
sigScript := mockTx.TxIn[0].SignatureScript sigScript := mockTx.TxIn[0].SignatureScript

View file

@ -210,7 +210,6 @@ type Script struct {
condStack []int condStack []int
numOps int numOps int
bip16 bool // treat execution as pay-to-script-hash bip16 bool // treat execution as pay-to-script-hash
der bool // enforce DER encoding
strictMultiSig bool // verify multisig stack item is zero length strictMultiSig bool // verify multisig stack item is zero length
discourageUpgradableNops bool // NOP1 to NOP10 are reserved for future soft-fork upgrades discourageUpgradableNops bool // NOP1 to NOP10 are reserved for future soft-fork upgrades
verifyStrictEncoding bool // verify strict encoding of signatures verifyStrictEncoding bool // verify strict encoding of signatures
@ -623,20 +622,6 @@ const (
// pay-to-script hash transactions will be fully validated. // pay-to-script hash transactions will be fully validated.
ScriptBip16 ScriptFlags = 1 << iota ScriptBip16 ScriptFlags = 1 << iota
// ScriptCanonicalSignatures defines whether additional canonical
// signature checks are performed when parsing a signature.
//
// Canonical (DER) signatures are not required in the tx rules for
// block acceptance, but are checked in recent versions of bitcoind
// when accepting transactions to the mempool. Non-canonical (valid
// BER but not valid DER) transactions can potentially be changed
// before mined into a block, either by adding extra padding or
// flipping the sign of the R or S value in the signature, creating a
// transaction that still validates and spends the inputs, but is not
// recognized by creator of the transaction. Performing a canonical
// check enforces script signatures use a unique DER format.
ScriptCanonicalSignatures
// ScriptStrictMultiSig defines whether to verify the stack item // ScriptStrictMultiSig defines whether to verify the stack item
// used by CHECKMULTISIG is zero length. // used by CHECKMULTISIG is zero length.
ScriptStrictMultiSig ScriptStrictMultiSig
@ -703,9 +688,6 @@ func NewScript(scriptSig []byte, scriptPubKey []byte, txidx int, tx *wire.MsgTx,
} }
m.bip16 = true m.bip16 = true
} }
if flags&ScriptCanonicalSignatures == ScriptCanonicalSignatures {
m.der = true
}
if flags&ScriptStrictMultiSig == ScriptStrictMultiSig { if flags&ScriptStrictMultiSig == ScriptStrictMultiSig {
m.strictMultiSig = true m.strictMultiSig = true
} }

View file

@ -136,7 +136,7 @@ type txTest struct {
pkScript []byte // output script of previous tx pkScript []byte // output script of previous tx
idx int // tx idx to be run. idx int // tx idx to be run.
bip16 bool // is bip16 active? bip16 bool // is bip16 active?
canonicalSigs bool // should signatures be validated as canonical? strictSigs bool // should signatures be validated as strict?
parseErr error // failure of NewScript parseErr error // failure of NewScript
err error // Failure of Executre err error // Failure of Executre
shouldFail bool // Execute should fail with nonspecified error. shouldFail bool // Execute should fail with nonspecified error.
@ -844,7 +844,7 @@ var txTests = []txTest{
txscript.OP_CHECKSIG, txscript.OP_CHECKSIG,
}, },
idx: 0, idx: 0,
canonicalSigs: true, strictSigs: true,
shouldFail: true, shouldFail: true,
nSigOps: 1, nSigOps: 1,
scriptInfo: txscript.ScriptInfo{ scriptInfo: txscript.ScriptInfo{
@ -1619,8 +1619,8 @@ func testTx(t *testing.T, test txTest) {
if test.bip16 { if test.bip16 {
flags |= txscript.ScriptBip16 flags |= txscript.ScriptBip16
} }
if test.canonicalSigs { if test.strictSigs {
flags |= txscript.ScriptCanonicalSignatures flags |= txscript.ScriptVerifyDERSignatures
} }
engine, err := txscript.NewScript( engine, err := txscript.NewScript(
test.tx.TxIn[test.idx].SignatureScript, test.pkScript, test.tx.TxIn[test.idx].SignatureScript, test.pkScript,
@ -2867,7 +2867,7 @@ nexttest:
} }
// Validate tx input scripts // Validate tx input scripts
scriptFlags := txscript.ScriptBip16 | txscript.ScriptCanonicalSignatures scriptFlags := txscript.ScriptBip16 | txscript.ScriptVerifyDERSignatures
for j, txin := range tx.TxIn { for j, txin := range tx.TxIn {
engine, err := txscript.NewScript(txin.SignatureScript, engine, err := txscript.NewScript(txin.SignatureScript,
SigScriptTests[i].inputs[j].txout.PkScript, SigScriptTests[i].inputs[j].txout.PkScript,
@ -3297,7 +3297,7 @@ func checkScripts(msg string, tx *wire.MsgTx, idx int,
sigScript, pkScript []byte) error { sigScript, pkScript []byte) error {
engine, err := txscript.NewScript(sigScript, pkScript, idx, tx, engine, err := txscript.NewScript(sigScript, pkScript, idx, tx,
txscript.ScriptBip16| txscript.ScriptBip16|
txscript.ScriptCanonicalSignatures) txscript.ScriptVerifyDERSignatures)
if err != nil { if err != nil {
return fmt.Errorf("failed to make script engine for %s: %v", return fmt.Errorf("failed to make script engine for %s: %v",
msg, err) msg, err)