Skip to content

Commit c9505db

Browse files
committed
debug travis failing cases
1 parent 7fb73f8 commit c9505db

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ before_script:
7878
- if [ "${COVERAGE}" != "true" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then phpenv config-rm xdebug.ini && echo "xdebug disabled"; fi
7979

8080
script:
81+
- vendor/bin/phpunit --filter 'TaprootTest::testScript#20'
82+
- vendor/bin/phpunit --filter 'TaprootTest::testScript#21'
8183
- travis/run_secp256k1_tests.sh || exit 1
8284
- if [ "$COVERAGE" = "true" ]; then pwd && vendor/bin/phpstan analyse src tests -l 1; fi
8385
- make phpunit-ci || exit 1

src/Script/Interpreter/CheckerBase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,26 @@ public function getTaprootSigHash(int $sigHashType, int $sigVersion, ExecutionCo
284284
public function checkSigSchnorr(BufferInterface $sig64, BufferInterface $key32, int $sigVersion, ExecutionContext $execContext): bool
285285
{
286286
if ($sig64->getSize() === 0) {
287+
echo "sig64 = 0\n";
287288
return false;
288289
}
289290
if ($key32->getSize() !== 32) {
291+
echo "key != 32\n";
290292
return false;
291293
}
292294

293295
$hashType = SigHash::TAPDEFAULT;
294296
if ($sig64->getSize() === 65) {
295297
$hashType = (int) $sig64->slice(64, 1)->getInt();
296298
if ($hashType === SigHash::TAPDEFAULT) {
299+
echo "badsighash1\n";
297300
return false;
298301
}
299302
$sig64 = $sig64->slice(0, 64);
300303
}
301304

302305
if ($sig64->getSize() !== 64) {
306+
echo "sig.size!=64\n";
303307
return false;
304308
}
305309

@@ -309,6 +313,7 @@ public function checkSigSchnorr(BufferInterface $sig64, BufferInterface $key32,
309313
$sigHash = $this->getTaprootSigHash($hashType, $sigVersion, $execContext);
310314
return $pubKey->verifySchnorr($sigHash, $sig);
311315
} catch (\Exception $e) {
316+
echo "checksigSchnorr exception: ". $e->getMessage().PHP_EOL;
312317
return false;
313318
}
314319
}

src/Script/Interpreter/Interpreter.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,12 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
295295
}
296296

297297
if ($witnessCount === 0) {
298+
echo "empty witness\n";
298299
return false;
299300
} else if ($witnessCount >= 2 && $scriptWitness->bottom()->getSize() > 0 && ord($scriptWitness->bottom()->getBinary()[0]) === TaprootHasher::TAPROOT_ANNEX_BYTE) {
300301
$annex = $scriptWitness->bottom();
301302
if (($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_ANNEX)) {
303+
echo "uigradable annex\n";
302304
return false;
303305
}
304306
$execContext->setAnnexHash(Hash::sha256($annex));
@@ -311,6 +313,7 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
311313
// key spend path - doesn't use the interpreter, directly checks signature
312314
$signature = $scriptWitness[count($scriptWitness) - 1];
313315
if (!$checker->checkSigSchnorr($signature, $witnessProgram->getProgram(), SigHash::TAPROOT, $execContext)) {
316+
echo "invalid signature\n";
314317
return false;
315318
}
316319
return true;
@@ -329,11 +332,13 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
329332
if ($control->getSize() < TAPROOT_CONTROL_BASE_SIZE ||
330333
$control->getSize() > TAPROOT_CONTROL_MAX_SIZE ||
331334
(($control->getSize() - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_BRANCH_SIZE !== 0)) {
335+
echo "invalid control size\n";
332336
return false;
333337
}
334338

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

346351
// return true at this stage, need further work to proceed
347-
return $this->executeWitnessProgram($scriptWitness, new Script($scriptPubKey), SigHash::TAPSCRIPT, $flags, $checker, $execContext);
352+
$ret = $this->executeWitnessProgram($scriptWitness, new Script($scriptPubKey), SigHash::TAPSCRIPT, $flags, $checker, $execContext);
353+
var_dump("witnessExec");
354+
var_dump($ret);
355+
return $ret;
348356
}
349357
}
350358

351359
if ($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM) {
360+
echo "upgradable witness program\n";
352361
return false;
353362
}
354363

@@ -520,17 +529,21 @@ private function evalChecksigTapscript(BufferInterface $sig, BufferInterface $ke
520529
assert($execContext->hasValidationWeightSet());
521530
$execContext->setValidationWeightLeft($execContext->getValidationWeightLeft() - VALIDATION_WEIGHT_OFFSET);
522531
if ($execContext->getValidationWeightLeft() < 0) {
532+
echo "validation weight failure\n";
523533
return false;
524534
}
525535
}
526536
if ($key->getSize() === 0) {
537+
echo "keysize=0\n";
527538
return false;
528539
} else if ($key->getSize() === 32) {
529540
if ($success && !$checker->checkSigSchnorr($sig, $key, $sigVersion, $execContext)) {
541+
echo "keysize = 32 and checksig failed\n";
530542
return false;
531543
}
532544
} else {
533545
if ($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE) {
546+
echo "upgradable keytype\n";
534547
return false;
535548
}
536549
}
@@ -614,9 +627,9 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
614627
}
615628

616629
$mainStack->push($pushData);
617-
// echo " - [pushed '" . $pushData->getHex() . "']\n";
630+
echo " - [pushed '" . $pushData->getHex() . "']\n";
618631
} elseif ($fExec || (Opcodes::OP_IF <= $opCode && $opCode <= Opcodes::OP_ENDIF)) {
619-
// echo "OPCODE - " . $script->getOpcodes()->getOp($opCode) . "\n";
632+
echo "OPCODE - " . $script->getOpcodes()->getOp($opCode) . "\n";
620633
switch ($opCode) {
621634
case Opcodes::OP_1NEGATE:
622635
case Opcodes::OP_1:
@@ -1081,9 +1094,11 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
10811094

10821095
case Opcodes::OP_CHECKSIGADD:
10831096
if ($sigVersion !== SigHash::TAPSCRIPT) {
1097+
echo "sigVersion != tapscript\n";
10841098
throw new \RuntimeException('Opcode not found');
10851099
}
10861100
if ($mainStack->count() < 3) {
1101+
echo "mainStack count != 3\n";
10871102
return false;
10881103
}
10891104
$pubkey = $mainStack[-1];
@@ -1092,6 +1107,7 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
10921107

10931108
$success = false;
10941109
if (!$this->evalChecksig($sig, $pubkey, $script, $hashStartPos, $flags, $checker, $sigVersion, $execContext, $success)) {
1110+
echo "checksig add - evalChecksig false\n";
10951111
return false;
10961112
}
10971113
$push = Number::gmp($this->math->add($n->getGmp(), gmp_init($success ? 1 : 0, 10)), $this->math)->getBuffer();
@@ -1248,11 +1264,11 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
12481264

12491265
return true;
12501266
} catch (ScriptRuntimeException $e) {
1251-
// echo "\n Runtime: " . $e->getMessage() . "\n" . $e->getTraceAsString() . PHP_EOL;
1267+
echo "\n Runtime: " . $e->getMessage() . "\n" . $e->getTraceAsString() . PHP_EOL;
12521268
// Failure due to script tags, can access flag: $e->getFailureFlag()
12531269
return false;
12541270
} catch (\Exception $e) {
1255-
// echo "\n General: " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
1271+
echo "\n General: " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
12561272
return false;
12571273
}
12581274
}

0 commit comments

Comments
 (0)