Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
add minimalif
Browse files Browse the repository at this point in the history
  • Loading branch information
matiu committed Apr 23, 2018
1 parent 50b4b32 commit 4adae85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
23 changes: 22 additions & 1 deletion lib/script/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,13 @@ Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS = (1 << 11);
// See BIP112 for details
Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1 << 10);

//
// Segwit script only: Require the argument of OP_IF/NOTIF to be exactly
// 0x01 or empty vector
//
Interpreter.SCRIPT_VERIFY_MINIMALIF = (1 << 13);


// Signature(s) must be empty vector if an CHECK(MULTI)SIG operation failed
//
Interpreter.SCRIPT_VERIFY_NULLFAIL = (1 << 14);
Expand Down Expand Up @@ -874,11 +881,25 @@ Interpreter.prototype.step = function() {
this.errstr = 'SCRIPT_ERR_UNBALANCED_CONDITIONAL';
return false;
}
buf = this.stack.pop();

buf = this.stack[this.stack.length - 1];

if (this.flags & Interpreter.SCRIPT_VERIFY_MINIMALIF) {
buf = this.stack[this.stack.length - 1];
if (buf.length > 1) {
this.errstr = 'SCRIPT_ERR_MINIMALIF';
return false;
}
if (buf.length == 1 && buf[0]!=1) {
this.errstr = 'SCRIPT_ERR_MINIMALIF';
return false;
}
}
fValue = Interpreter.castToBool(buf);
if (opcodenum === Opcode.OP_NOTIF) {
fValue = !fValue;
}
this.stack.pop();
}
this.vfExec.push(fValue);
}
Expand Down
8 changes: 3 additions & 5 deletions test/script/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,13 @@ describe('Interpreter', function() {
flags = flags | Interpreter.SCRIPT_VERIFY_CLEANSTACK;
}

console.log('[interpreter.js.311]', flagstr); //TODO
if (flagstr.indexOf('WITNESS_PUBKEYTYPE') !== -1) {

console.log('[interpreter.js.314] IN!'); //TODO
flags = flags | Interpreter.SCRIPT_VERIFY_WITNESS_PUBKEYTYPE;
}
if (flagstr.indexOf('MINIMALIF') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_MINIMALIF;
}

console.log('ANTES XXX ', flags & Interpreter.SCRIPT_VERIFY_WITNESS_PUBKEYTYPE); //TODO
console.log('[interpreter.js.320:flags:]',flags); //TODO
return flags;
};

Expand Down

0 comments on commit 4adae85

Please sign in to comment.