33 bool found_header =
false;
38 std::vector<uint8_t> pushdata;
39 while (witness_commitment.
GetOp(pc, opcode, pushdata)) {
40 if (pushdata.size() > 0) {
41 if (!found_header && pushdata.size() > (
size_t)header.
size() &&
Span{pushdata}.
first(header.
size()) == header) {
43 result.insert(result.end(), pushdata.begin() + header.
size(), pushdata.end());
44 pushdata.erase(pushdata.begin() + header.
size(), pushdata.end());
47 replacement << pushdata;
49 replacement << opcode;
53 if (found_header) witness_commitment = replacement;
59 std::vector<uint256> leaves;
60 leaves.resize(block.
vtx.size());
62 for (
size_t s = 1; s < block.
vtx.size(); ++s) {
63 leaves[s] = block.
vtx[s]->GetHash();
74 tx_to_spend.
vout.emplace_back(0, challenge);
86 if (block.
vtx.empty())
return std::nullopt;
94 CScript& witness_commitment = modified_cb.
vout.at(cidx).scriptPubKey;
96 std::vector<uint8_t> signet_solution;
102 v >> tx_spending.
vin[0].scriptSig;
103 v >> tx_spending.
vin[0].scriptWitness.stack;
104 if (!v.empty())
return std::nullopt;
105 }
catch (
const std::exception&) {
111 std::vector<uint8_t> block_data;
115 writer << signet_merkle;
116 writer << block.
nTime;
117 tx_to_spend.
vin[0].scriptSig << block_data;
120 return SignetTxs{tx_to_spend, tx_spending};
139 const CScript& scriptSig = signet_txs->m_to_sign.vin[0].scriptSig;
140 const CScriptWitness& witness = signet_txs->m_to_sign.vin[0].scriptWitness;
143 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 LogPrint(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.