fix all script validation tests, yay!
This commit is contained in:
parent
7f0a2dc050
commit
50dd4e8e66
@ -167,23 +167,23 @@ ScriptInterpreter.prototype.evaluate = function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//try {
|
try {
|
||||||
while (this.pc < this.script.chunks.length) {
|
while (this.pc < this.script.chunks.length) {
|
||||||
var fSuccess = this.step();
|
var fSuccess = this.step();
|
||||||
if (!fSuccess) {
|
if (!fSuccess) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size limits
|
||||||
|
if (this.stack.length + this.altstack.length > 1000) {
|
||||||
|
this.errstr = 'SCRIPT_ERR_STACK_SIZE';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} catch (e) {
|
||||||
|
this.errstr = 'SCRIPT_ERR_UNKNOWN_ERROR: ' + e;
|
||||||
// Size limits
|
|
||||||
if (this.stack.length + this.altstack.length > 1000) {
|
|
||||||
this.errstr = 'SCRIPT_ERR_STACK_SIZE';
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//} catch (e) {
|
|
||||||
// this.errstr = 'SCRIPT_ERR_UNKNOWN_ERROR: ' + e;
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (this.vfExec.length > 0) {
|
if (this.vfExec.length > 0) {
|
||||||
this.errstr = 'SCRIPT_ERR_UNBALANCED_CONDITIONAL';
|
this.errstr = 'SCRIPT_ERR_UNBALANCED_CONDITIONAL';
|
||||||
@ -888,8 +888,6 @@ ScriptInterpreter.prototype.step = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fSuccess;
|
var fSuccess;
|
||||||
var sig = Signature.fromTxFormat(bufSig);
|
|
||||||
var pubkey = PublicKey.fromBuffer(bufPubkey, false);
|
|
||||||
try {
|
try {
|
||||||
var sig = Signature.fromTxFormat(bufSig);
|
var sig = Signature.fromTxFormat(bufSig);
|
||||||
var pubkey = PublicKey.fromBuffer(bufPubkey, false);
|
var pubkey = PublicKey.fromBuffer(bufPubkey, false);
|
||||||
@ -998,13 +996,15 @@ ScriptInterpreter.prototype.step = function() {
|
|||||||
|
|
||||||
// If there are more signatures left than keys left,
|
// If there are more signatures left than keys left,
|
||||||
// then too many signatures have failed
|
// then too many signatures have failed
|
||||||
if (nSigsCount > nKeysCount)
|
if (nSigsCount > nKeysCount) {
|
||||||
fSuccess = false;
|
fSuccess = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up stack of actual arguments
|
// Clean up stack of actual arguments
|
||||||
while (i-- > 1)
|
while (i-- > 1) {
|
||||||
this.stack.pop();
|
this.stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
// A bug causes CHECKMULTISIG to consume one extra argument
|
// A bug causes CHECKMULTISIG to consume one extra argument
|
||||||
// whose contents were not checked in any way.
|
// whose contents were not checked in any way.
|
||||||
|
|||||||
@ -208,6 +208,7 @@ describe('ScriptInterpreter', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var testFixture = function(vector, expected) {
|
var testFixture = function(vector, expected) {
|
||||||
|
console.log(vector);
|
||||||
var scriptSig = Script.fromBitcoindString(vector[0]);
|
var scriptSig = Script.fromBitcoindString(vector[0]);
|
||||||
var scriptPubkey = Script.fromBitcoindString(vector[1]);
|
var scriptPubkey = Script.fromBitcoindString(vector[1]);
|
||||||
var flags = getFlags(vector[2]);
|
var flags = getFlags(vector[2]);
|
||||||
@ -244,6 +245,9 @@ describe('ScriptInterpreter', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
var interp = ScriptInterpreter();
|
var interp = ScriptInterpreter();
|
||||||
|
console.log('scriptSig=' + scriptSig.toString());
|
||||||
|
console.log('scriptPubkey=' + scriptPubkey.toString());
|
||||||
|
console.log(vector[1]);
|
||||||
console.log(scriptSig.toString() + ' ' + scriptPubkey.toString());
|
console.log(scriptSig.toString() + ' ' + scriptPubkey.toString());
|
||||||
var verified = interp.verify(scriptSig, scriptPubkey, spendtx, 0, flags);
|
var verified = interp.verify(scriptSig, scriptPubkey, spendtx, 0, flags);
|
||||||
console.log(interp.errstr);
|
console.log(interp.errstr);
|
||||||
@ -252,7 +256,7 @@ describe('ScriptInterpreter', function() {
|
|||||||
describe.only('bitcoind fixtures', function() {
|
describe.only('bitcoind fixtures', function() {
|
||||||
var testAllFixtures = function(set, expected) {
|
var testAllFixtures = function(set, expected) {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
script_valid.forEach(function(vector) {
|
set.forEach(function(vector) {
|
||||||
if (vector.length === 1) {
|
if (vector.length === 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -260,7 +264,7 @@ describe('ScriptInterpreter', function() {
|
|||||||
var descstr = vector[3];
|
var descstr = vector[3];
|
||||||
var fullScriptString = vector[0] + ' ' + vector[1];
|
var fullScriptString = vector[0] + ' ' + vector[1];
|
||||||
var comment = descstr ? (' (' + descstr + ')') : '';
|
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);
|
testFixture(vector, expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user