34 bool found_header =
false;
39 std::vector<uint8_t> pushdata;
40 while (witness_commitment.
GetOp(pc, opcode, pushdata)) {
41 if (pushdata.size() > 0) {
42 if (!found_header && pushdata.size() > header.
size() && std::ranges::equal(
Span{pushdata}.
first(header.
size()), header)) {
44 result.insert(result.end(), pushdata.begin() + header.
size(), pushdata.end());
45 pushdata.erase(pushdata.begin() + header.
size(), pushdata.end());
48 replacement << pushdata;
50 replacement << opcode;
54 if (found_header) witness_commitment = replacement;
60 std::vector<uint256> leaves;
61 leaves.resize(block.
vtx.size());
63 for (
size_t s = 1;
s < block.
vtx.size(); ++
s) {
64 leaves[
s] = block.
vtx[
s]->GetHash();
75 tx_to_spend.
vout.emplace_back(0, challenge);
87 if (block.
vtx.empty())
return std::nullopt;
95 CScript& witness_commitment = modified_cb.
vout.at(cidx).scriptPubKey;
97 std::vector<uint8_t> signet_solution;
103 v >> tx_spending.
vin[0].scriptSig;
104 v >> tx_spending.
vin[0].scriptWitness.stack;
105 if (!v.empty())
return std::nullopt;
106 }
catch (
const std::exception&) {
112 std::vector<uint8_t> block_data;
116 writer << signet_merkle;
117 writer << block.
nTime;
118 tx_to_spend.
vin[0].scriptSig << block_data;
121 return SignetTxs{tx_to_spend, tx_spending};
140 const CScript& scriptSig = signet_txs->m_to_sign.vin[0].scriptSig;
141 const CScriptWitness& witness = signet_txs->m_to_sign.vin[0].scriptWitness;
144 txdata.
Init(signet_txs->m_to_sign, {signet_txs->m_to_spend.vout[0]});
std::vector< CTransactionRef > vtx
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
Generate the signet tx corresponding to the given block.
static std::optional< SignetTxs > Create(const CBlock &block, const CScript &challenge)
A Span is an object that can refer to a contiguous sequence of objects.
constexpr std::size_t size() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
Minimal stream for reading from an existing byte array by Span.
static constexpr int NO_WITNESS_COMMITMENT
Index marker for when no witness commitment is present in a coinbase transaction.
int GetWitnessCommitmentIndex(const CBlock &block)
Compute at which vout of the block's coinbase transaction the witness commitment occurs,...
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
@ SCRIPT_VERIFY_NULLDUMMY
@ ASSERT_FAIL
Abort execution through assertion failure (for consensus code)
#define LogDebug(category,...)
uint256 ComputeMerkleRoot(std::vector< uint256 > hashes, bool *mutated)
opcodetype
Script opcodes.
static constexpr unsigned int BLOCK_SCRIPT_VERIFY_FLAGS
bool CheckSignetBlockSolution(const CBlock &block, const Consensus::Params &consensusParams)
Extract signature and check whether a block has a valid solution.
static bool FetchAndClearCommitmentSection(const Span< const uint8_t > header, CScript &witness_commitment, std::vector< uint8_t > &result)
static constexpr uint8_t SIGNET_HEADER[4]
static uint256 ComputeModifiedMerkleRoot(const CMutableTransaction &cb, const CBlock &block)
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Parameters that influence chain consensus.
std::vector< uint8_t > signet_challenge
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.