@@ -295,10 +295,12 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
295
295
}
296
296
297
297
if ($ witnessCount === 0 ) {
298
+ echo "empty witness \n" ;
298
299
return false ;
299
300
} else if ($ witnessCount >= 2 && $ scriptWitness ->bottom ()->getSize () > 0 && ord ($ scriptWitness ->bottom ()->getBinary ()[0 ]) === TaprootHasher::TAPROOT_ANNEX_BYTE ) {
300
301
$ annex = $ scriptWitness ->bottom ();
301
302
if (($ flags & self ::VERIFY_DISCOURAGE_UPGRADABLE_ANNEX )) {
303
+ echo "uigradable annex \n" ;
302
304
return false ;
303
305
}
304
306
$ execContext ->setAnnexHash (Hash::sha256 ($ annex ));
@@ -311,6 +313,7 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
311
313
// key spend path - doesn't use the interpreter, directly checks signature
312
314
$ signature = $ scriptWitness [count ($ scriptWitness ) - 1 ];
313
315
if (!$ checker ->checkSigSchnorr ($ signature , $ witnessProgram ->getProgram (), SigHash::TAPROOT , $ execContext )) {
316
+ echo "invalid signature \n" ;
314
317
return false ;
315
318
}
316
319
return true ;
@@ -329,11 +332,13 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
329
332
if ($ control ->getSize () < TAPROOT_CONTROL_BASE_SIZE ||
330
333
$ control ->getSize () > TAPROOT_CONTROL_MAX_SIZE ||
331
334
(($ control ->getSize () - TAPROOT_CONTROL_BASE_SIZE ) % TAPROOT_CONTROL_BRANCH_SIZE !== 0 )) {
335
+ echo "invalid control size \n" ;
332
336
return false ;
333
337
}
334
338
335
339
$ leafHash = null ;
336
340
if (!$ this ->verifyTaprootCommitment ($ control , $ witnessProgram ->getProgram (), $ scriptPubKey , $ leafHash )) {
341
+ echo "invalid taproot commitment \n" ;
337
342
return false ;
338
343
}
339
344
$ execContext ->setTapLeafHash ($ leafHash );
@@ -344,11 +349,15 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
344
349
}
345
350
346
351
// 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 ;
348
356
}
349
357
}
350
358
351
359
if ($ flags & self ::VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM ) {
360
+ echo "upgradable witness program \n" ;
352
361
return false ;
353
362
}
354
363
@@ -520,17 +529,21 @@ private function evalChecksigTapscript(BufferInterface $sig, BufferInterface $ke
520
529
assert ($ execContext ->hasValidationWeightSet ());
521
530
$ execContext ->setValidationWeightLeft ($ execContext ->getValidationWeightLeft () - VALIDATION_WEIGHT_OFFSET );
522
531
if ($ execContext ->getValidationWeightLeft () < 0 ) {
532
+ echo "validation weight failure \n" ;
523
533
return false ;
524
534
}
525
535
}
526
536
if ($ key ->getSize () === 0 ) {
537
+ echo "keysize=0 \n" ;
527
538
return false ;
528
539
} else if ($ key ->getSize () === 32 ) {
529
540
if ($ success && !$ checker ->checkSigSchnorr ($ sig , $ key , $ sigVersion , $ execContext )) {
541
+ echo "keysize = 32 and checksig failed \n" ;
530
542
return false ;
531
543
}
532
544
} else {
533
545
if ($ flags & self ::VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE ) {
546
+ echo "upgradable keytype \n" ;
534
547
return false ;
535
548
}
536
549
}
@@ -614,9 +627,9 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
614
627
}
615
628
616
629
$ mainStack ->push ($ pushData );
617
- // echo " - [pushed '" . $pushData->getHex() . "']\n";
630
+ echo " - [pushed ' " . $ pushData ->getHex () . "'] \n" ;
618
631
} 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" ;
620
633
switch ($ opCode ) {
621
634
case Opcodes::OP_1NEGATE :
622
635
case Opcodes::OP_1 :
@@ -1081,9 +1094,11 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
1081
1094
1082
1095
case Opcodes::OP_CHECKSIGADD :
1083
1096
if ($ sigVersion !== SigHash::TAPSCRIPT ) {
1097
+ echo "sigVersion != tapscript \n" ;
1084
1098
throw new \RuntimeException ('Opcode not found ' );
1085
1099
}
1086
1100
if ($ mainStack ->count () < 3 ) {
1101
+ echo "mainStack count != 3 \n" ;
1087
1102
return false ;
1088
1103
}
1089
1104
$ pubkey = $ mainStack [-1 ];
@@ -1092,6 +1107,7 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
1092
1107
1093
1108
$ success = false ;
1094
1109
if (!$ this ->evalChecksig ($ sig , $ pubkey , $ script , $ hashStartPos , $ flags , $ checker , $ sigVersion , $ execContext , $ success )) {
1110
+ echo "checksig add - evalChecksig false \n" ;
1095
1111
return false ;
1096
1112
}
1097
1113
$ 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
1248
1264
1249
1265
return true ;
1250
1266
} 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 ;
1252
1268
// Failure due to script tags, can access flag: $e->getFailureFlag()
1253
1269
return false ;
1254
1270
} 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 ;
1256
1272
return false ;
1257
1273
}
1258
1274
}
0 commit comments