Browse Source

fix all script validation tests, yay!

patch-2
Manuel Araoz 10 years ago
parent
commit
50dd4e8e66
  1. 34
      lib/script_interpreter.js
  2. 8
      test/script_interpreter.js

34
lib/script_interpreter.js

@ -167,23 +167,23 @@ ScriptInterpreter.prototype.evaluate = function() {
return false;
}
//try {
while (this.pc < this.script.chunks.length) {
var fSuccess = this.step();
if (!fSuccess) {
return false;
try {
while (this.pc < this.script.chunks.length) {
var fSuccess = this.step();
if (!fSuccess) {
return false;
}
}
}
// Size limits
if (this.stack.length + this.altstack.length > 1000) {
this.errstr = 'SCRIPT_ERR_STACK_SIZE';
// Size limits
if (this.stack.length + this.altstack.length > 1000) {
this.errstr = 'SCRIPT_ERR_STACK_SIZE';
return false;
}
} catch (e) {
this.errstr = 'SCRIPT_ERR_UNKNOWN_ERROR: ' + e;
return false;
}
//} catch (e) {
// this.errstr = 'SCRIPT_ERR_UNKNOWN_ERROR: ' + e;
// return false;
//}
if (this.vfExec.length > 0) {
this.errstr = 'SCRIPT_ERR_UNBALANCED_CONDITIONAL';
@ -888,8 +888,6 @@ ScriptInterpreter.prototype.step = function() {
}
var fSuccess;
var sig = Signature.fromTxFormat(bufSig);
var pubkey = PublicKey.fromBuffer(bufPubkey, false);
try {
var sig = Signature.fromTxFormat(bufSig);
var pubkey = PublicKey.fromBuffer(bufPubkey, false);
@ -998,13 +996,15 @@ ScriptInterpreter.prototype.step = function() {
// If there are more signatures left than keys left,
// then too many signatures have failed
if (nSigsCount > nKeysCount)
if (nSigsCount > nKeysCount) {
fSuccess = false;
}
}
// Clean up stack of actual arguments
while (i-- > 1)
while (i-- > 1) {
this.stack.pop();
}
// A bug causes CHECKMULTISIG to consume one extra argument
// whose contents were not checked in any way.

8
test/script_interpreter.js

@ -208,6 +208,7 @@ describe('ScriptInterpreter', function() {
};
var testFixture = function(vector, expected) {
console.log(vector);
var scriptSig = Script.fromBitcoindString(vector[0]);
var scriptPubkey = Script.fromBitcoindString(vector[1]);
var flags = getFlags(vector[2]);
@ -244,6 +245,9 @@ describe('ScriptInterpreter', function() {
}));
var interp = ScriptInterpreter();
console.log('scriptSig=' + scriptSig.toString());
console.log('scriptPubkey=' + scriptPubkey.toString());
console.log(vector[1]);
console.log(scriptSig.toString() + ' ' + scriptPubkey.toString());
var verified = interp.verify(scriptSig, scriptPubkey, spendtx, 0, flags);
console.log(interp.errstr);
@ -252,7 +256,7 @@ describe('ScriptInterpreter', function() {
describe.only('bitcoind fixtures', function() {
var testAllFixtures = function(set, expected) {
var c = 0;
script_valid.forEach(function(vector) {
set.forEach(function(vector) {
if (vector.length === 1) {
return;
}
@ -260,7 +264,7 @@ describe('ScriptInterpreter', function() {
var descstr = vector[3];
var fullScriptString = vector[0] + ' ' + vector[1];
var comment = descstr ? (' (' + descstr + ')') : '';
it('should pass script_valid vector #' + c + ': ' + fullScriptString + comment, function() {
it('should pass script_' + (expected ? '' : 'in') + 'valid vector #' + c + ': ' + fullScriptString + comment, function() {
testFixture(vector, expected);
});
});

Loading…
Cancel
Save