@@ -260,7 +260,7 @@ interpreter.prototype.nextStep = function (mainstack, altstack, script, index) {
260260 if ( mainstack . pop ( ) == null ) return - 1 ;
261261 break ;
262262 case "OP_DUP" :
263- var toPeek = mainstack . peek ( 0 ) ;
263+ var toPeek = mainstack . peek ( 1 ) ;
264264 if ( toPeek == null ) return - 1 ;
265265 mainstack . push ( toPeek ) ;
266266 break ;
@@ -633,8 +633,11 @@ interpreter.prototype.nextStep = function (mainstack, altstack, script, index) {
633633 code_separator_index = index ;
634634 break ;
635635 case "OP_CHECKSIG" :
636- //var pubKey = mainstack.pop();
637- //var sig = mainstack.pop();
636+ var pubKey = mainstack . pop ( ) ;
637+ if ( pubKey == null ) return - 1 ;
638+
639+ var sig = mainstack . pop ( ) ;
640+ if ( sig == null ) return - 1 ;
638641
639642 //var sub_script = new Array();
640643 //for (var i = code_separator_index; i < script.length; i++) {
@@ -645,8 +648,20 @@ interpreter.prototype.nextStep = function (mainstack, altstack, script, index) {
645648 // see https://en.bitcoin.it/wiki/OP_CHECKSIG
646649 // use secp256k1 elliptic curve for signature verification
647650 case "OP_CHECKSIGVERIFY" :
648- mainstack . push ( 1 ) ;
649- mainstack . pop ( ) ;
651+ var pubKey = mainstack . pop ( ) ;
652+ if ( pubKey == null ) return - 1 ;
653+
654+ var sig = mainstack . pop ( ) ;
655+ if ( sig == null ) return - 1 ;
656+
657+ //var sub_script = new Array();
658+ //for (var i = code_separator_index; i < script.length; i++) {
659+ // if (script[i] !== sig) sub_script.push(script[i]);
660+ //}
661+ mainstack . push ( "1" ) ;
662+
663+ if ( mainstack . pop ( ) === 0 )
664+ return - 1 ;
650665 break ;
651666 case "OP_CHECKMULTISIG" :
652667 mainstack . push ( 1 ) ;
0 commit comments