Skip to content

Commit

Permalink
debug travis failing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
afk11 committed Dec 10, 2019
1 parent 7fb73f8 commit 48a9a76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ before_script:
- if [ "${COVERAGE}" != "true" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then phpenv config-rm xdebug.ini && echo "xdebug disabled"; fi

script:
- vendor/bin/phpunit --filter 'TaprootTest::testScript#20'
- vendor/bin/phpunit --filter 'TaprootTest::testScript#21'
- travis/run_secp256k1_tests.sh || exit 1
- if [ "$COVERAGE" = "true" ]; then pwd && vendor/bin/phpstan analyse src tests -l 1; fi
- make phpunit-ci || exit 1
Expand Down
19 changes: 14 additions & 5 deletions src/Script/Interpreter/Interpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,12 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
}

if ($witnessCount === 0) {
echo "empty witness\n";
return false;
} else if ($witnessCount >= 2 && $scriptWitness->bottom()->getSize() > 0 && ord($scriptWitness->bottom()->getBinary()[0]) === TaprootHasher::TAPROOT_ANNEX_BYTE) {
$annex = $scriptWitness->bottom();
if (($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_ANNEX)) {
echo "uigradable annex\n";
return false;
}
$execContext->setAnnexHash(Hash::sha256($annex));
Expand All @@ -311,6 +313,7 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
// key spend path - doesn't use the interpreter, directly checks signature
$signature = $scriptWitness[count($scriptWitness) - 1];
if (!$checker->checkSigSchnorr($signature, $witnessProgram->getProgram(), SigHash::TAPROOT, $execContext)) {
echo "invalid signature\n";
return false;
}
return true;
Expand All @@ -329,11 +332,13 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
if ($control->getSize() < TAPROOT_CONTROL_BASE_SIZE ||
$control->getSize() > TAPROOT_CONTROL_MAX_SIZE ||
(($control->getSize() - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_BRANCH_SIZE !== 0)) {
echo "invalid control size\n";
return false;
}

$leafHash = null;
if (!$this->verifyTaprootCommitment($control, $witnessProgram->getProgram(), $scriptPubKey, $leafHash)) {
echo "invalid taproot commitment\n";
return false;
}
$execContext->setTapLeafHash($leafHash);
Expand All @@ -344,11 +349,15 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
}

// return true at this stage, need further work to proceed
return $this->executeWitnessProgram($scriptWitness, new Script($scriptPubKey), SigHash::TAPSCRIPT, $flags, $checker, $execContext);
$ret = $this->executeWitnessProgram($scriptWitness, new Script($scriptPubKey), SigHash::TAPSCRIPT, $flags, $checker, $execContext);
var_dump("witnessExec");
var_dump($ret);
return $ret;
}
}

if ($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM) {
echo "upgradable witness program\n";
return false;
}

Expand Down Expand Up @@ -614,9 +623,9 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
}

$mainStack->push($pushData);
// echo " - [pushed '" . $pushData->getHex() . "']\n";
echo " - [pushed '" . $pushData->getHex() . "']\n";
} elseif ($fExec || (Opcodes::OP_IF <= $opCode && $opCode <= Opcodes::OP_ENDIF)) {
// echo "OPCODE - " . $script->getOpcodes()->getOp($opCode) . "\n";
echo "OPCODE - " . $script->getOpcodes()->getOp($opCode) . "\n";
switch ($opCode) {
case Opcodes::OP_1NEGATE:
case Opcodes::OP_1:
Expand Down Expand Up @@ -1248,11 +1257,11 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers

return true;
} catch (ScriptRuntimeException $e) {
// echo "\n Runtime: " . $e->getMessage() . "\n" . $e->getTraceAsString() . PHP_EOL;
echo "\n Runtime: " . $e->getMessage() . "\n" . $e->getTraceAsString() . PHP_EOL;
// Failure due to script tags, can access flag: $e->getFailureFlag()
return false;
} catch (\Exception $e) {
// echo "\n General: " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
echo "\n General: " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
return false;
}
}
Expand Down

0 comments on commit 48a9a76

Please sign in to comment.