| 355 | } |
| 356 | |
| 357 | static bool EvalChecksigTapscript(const valtype& sig, const valtype& pubkey, ScriptExecutionData& execdata, script_verify_flags flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror, bool& success) |
| 358 | { |
| 359 | assert(sigversion == SigVersion::TAPSCRIPT); |
| 360 | |
| 361 | /* |
| 362 | * The following validation sequence is consensus critical. Please note how -- |
| 363 | * upgradable public key versions precede other rules; |
| 364 | * the script execution fails when using empty signature with invalid public key; |
| 365 | * the script execution fails when using non-empty invalid signature. |
| 366 | */ |
| 367 | success = !sig.empty(); |
| 368 | if (success) { |
| 369 | // Implement the sigops/witnesssize ratio test. |
| 370 | // Passing with an upgradable public key version is also counted. |
| 371 | assert(execdata.m_validation_weight_left_init); |
| 372 | execdata.m_validation_weight_left -= VALIDATION_WEIGHT_PER_SIGOP_PASSED; |
| 373 | if (execdata.m_validation_weight_left < 0) { |
| 374 | return set_error(serror, SCRIPT_ERR_TAPSCRIPT_VALIDATION_WEIGHT); |
| 375 | } |
| 376 | } |
| 377 | if (pubkey.size() == 0) { |
| 378 | return set_error(serror, SCRIPT_ERR_TAPSCRIPT_EMPTY_PUBKEY); |
| 379 | } else if (pubkey.size() == 32) { |
| 380 | if (success && !checker.CheckSchnorrSignature(sig, pubkey, sigversion, execdata, serror)) { |
| 381 | return false; // serror is set |
| 382 | } |
| 383 | } else { |
| 384 | /* |
| 385 | * New public key version softforks should be defined before this `else` block. |
| 386 | * Generally, the new code should not do anything but failing the script execution. To avoid |
| 387 | * consensus bugs, it should not modify any existing values (including `success`). |
| 388 | */ |
| 389 | if ((flags & SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE) != 0) { |
| 390 | return set_error(serror, SCRIPT_ERR_DISCOURAGE_UPGRADABLE_PUBKEYTYPE); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | return true; |
| 395 | } |
| 396 | |
| 397 | /** Helper for OP_CHECKSIG, OP_CHECKSIGVERIFY, and (in Tapscript) OP_CHECKSIGADD. |
| 398 | * |
no test coverage detected