Signet block solution checker
| 123 | |
| 124 | // Signet block solution checker |
| 125 | bool CheckSignetBlockSolution(const CBlock& block, const Consensus::Params& consensusParams) |
| 126 | { |
| 127 | if (block.GetHash() == consensusParams.hashGenesisBlock) { |
| 128 | // genesis block solution is always valid |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | const CScript challenge(consensusParams.signet_challenge.begin(), consensusParams.signet_challenge.end()); |
| 133 | const std::optional<SignetTxs> signet_txs = SignetTxs::Create(block, challenge); |
| 134 | |
| 135 | if (!signet_txs) { |
| 136 | LogPrint(BCLog::VALIDATION, "CheckSignetBlockSolution: Errors in block (block solution parse failure)\n"); |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | const CScript& scriptSig = signet_txs->m_to_sign.vin[0].scriptSig; |
| 141 | const CScriptWitness& witness = signet_txs->m_to_sign.witness.vtxinwit[0].scriptWitness; |
| 142 | |
| 143 | PrecomputedTransactionData txdata; |
| 144 | txdata.Init(signet_txs->m_to_sign, {signet_txs->m_to_spend.vout[0]}); |
| 145 | TransactionSignatureChecker sigcheck(&signet_txs->m_to_sign, /* nInIn= */ 0, /* amountIn= */ signet_txs->m_to_spend.vout[0].nValue, txdata, MissingDataBehavior::ASSERT_FAIL); |
| 146 | |
| 147 | if (!VerifyScript(scriptSig, signet_txs->m_to_spend.vout[0].scriptPubKey, &witness, BLOCK_SCRIPT_VERIFY_FLAGS, sigcheck)) { |
| 148 | LogPrint(BCLog::VALIDATION, "CheckSignetBlockSolution: Errors in block (block solution invalid)\n"); |
| 149 | return false; |
| 150 | } |
| 151 | return true; |
| 152 | } |