Skip to content

Commit

Permalink
tapscript: implement OP_CHECKSIGADD
Browse files Browse the repository at this point in the history
  • Loading branch information
afk11 committed Nov 11, 2019
1 parent bb1571b commit f6c483e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Script/Interpreter/Interpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,27 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
$hashStartPos = $parser->getPosition();
break;

case Opcodes::OP_CHECKSIGADD:
if ($sigVersion !== SigHash::TAPSCRIPT) {
throw new \RuntimeException('Opcode not found');
}
if ($mainStack->count() < 3) {
return false;
}
$pubkey = $mainStack[-1];
$n = Number::buffer($mainStack[-2], $minimal, Number::MAX_NUM_SIZE, $this->math);
$sig = $mainStack[-3];

$success = false;
if (!$this->evalChecksig($sig, $pubkey, $script, $hashStartPos, $flags, $checker, $sigVersion, $execContext, $success)) {
return false;
}
$mainStack->pop();
$mainStack->pop();
$mainStack->pop();
$mainStack->push(Number::gmp($this->math->add($n->getGmp(), gmp_init($success ? 1 : 0, 10)), $this->math));
break;

case Opcodes::OP_CHECKSIG:
case Opcodes::OP_CHECKSIGVERIFY:
if (count($mainStack) < 2) {
Expand Down
2 changes: 2 additions & 0 deletions src/Script/Opcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Opcodes implements \ArrayAccess
const OP_NOP8 = 183;
const OP_NOP9 = 184;
const OP_NOP10 = 185;
const OP_CHECKSIGADD = 186;

/**
* @var array
Expand Down Expand Up @@ -270,6 +271,7 @@ class Opcodes implements \ArrayAccess
self::OP_NOP8 => 'OP_NOP8',
self::OP_NOP9 => 'OP_NOP9',
self::OP_NOP10 => 'OP_NOP10',
self::OP_CHECKSIGADD => 'OP_CHECKSIGADD',
];

/**
Expand Down

0 comments on commit f6c483e

Please sign in to comment.