20 #include <unordered_set>
53 if (!
IsHex(hexProof)) {
54 errorOut =
_(
"Proof must be an hexadecimal string.");
62 }
catch (std::exception &e) {
63 errorOut =
strprintf(
_(
"Proof has invalid format: %s"), e.what());
94 total += s.getStake().getAmount();
101 return (100 * amount) /
COIN;
107 return current + ss.getStake().getAmount();
133 "payout-script-non-standard");
138 "invalid-proof-signature");
142 std::unordered_set<COutPoint, SaltedOutpointHasher> utxos;
144 const Stake &s = ss.getStake();
145 if (s.
getAmount() < stakeUtxoDustThreshold) {
147 "amount-below-dust-threshold",
149 stakeUtxoDustThreshold.
ToString()));
152 if (s.
getId() < prevId) {
154 "wrong-stake-ordering");
158 if (!utxos.insert(s.
getUTXO()).second) {
166 "invalid-stake-signature",
178 if (!
verify(stakeUtxoDustThreshold, state)) {
184 const int64_t tipMedianTimePast =
191 const int64_t stakeUtxoMinConfirmations =
196 const Stake &s = ss.getStake();
200 if (!chainman.ActiveChainstate().CoinsTip().GetCoin(utxo, coin)) {
203 "utxo-missing-or-spent");
206 if ((s.
getHeight() + stakeUtxoMinConfirmations - 1) > activeHeight) {
209 strprintf(
"TxId: %s, block height: %d, chaintip height: %d",
243 "non-standard-destination");
246 PKHash *pkhash = std::get_if<PKHash>(&dest);
251 "destination-type-not-supported");
255 if (*pkhash !=
PKHash(pubkey)) {
258 "destination-mismatch");
static constexpr Amount COIN
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
The block chain is a tree shaped structure starting with the genesis block at the root,...
int64_t GetMedianTimePast() const
Double ended buffer combining vector and stream-like interfaces.
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetHash()
Compute the double-SHA256 hash of all data written to this object.
An outpoint - a combination of a transaction hash and an index n into its vout.
const TxId & GetTxId() const
An encapsulated public key.
bool VerifySchnorr(const uint256 &hash, const std::array< uint8_t, SCHNORR_SIZE > &sig) const
Verify a Schnorr signature (=64 bytes).
Serialized script, used inside transaction inputs and outputs.
An output of a transaction.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
uint32_t GetHeight() const
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
static bool FromHex(Proof &proof, const std::string &hexProof, bilingual_str &errorOut)
bool verify(const Amount &stakeUtxoDustThreshold, ProofValidationState &state) const
Amount getStakedAmount() const
CScript payoutScriptPubKey
std::string ToHex() const
const StakeCommitment getStakeCommitment() const
LimitedProofId limitedProofId
std::vector< SignedStake > stakes
static uint32_t amountToScore(Amount amount)
bool verify(const StakeCommitment &commitment) const
uint256 getHash(const StakeCommitment &commitment) const
const COutPoint & getUTXO() const
const CPubKey & getPubkey() const
const StakeId & getId() const
uint32_t getHeight() const
const uint8_t * data() const
std::string ToString() const
static const uint256 ZERO
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
@ DESTINATION_NOT_SUPPORTED
@ NON_STANDARD_DESTINATION
@ INVALID_PROOF_SIGNATURE
@ INVALID_STAKE_SIGNATURE
static bool IsStandardPayoutScript(const CScript &scriptPubKey)
bool IsStandard(const CScript &scriptPubKey, const std::optional< unsigned > &max_datacarrier_bytes, TxoutType &whichType)
static constexpr int AVALANCHE_DEFAULT_STAKE_UTXO_CONFIRMATIONS
Minimum number of confirmations before a stake utxo is mature enough to be included into a proof.
static constexpr int AVALANCHE_MAX_PROOF_STAKES
How many UTXOs can be used for a single proof.
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for nMaxDatacarrierBytes.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool IsHex(const std::string &str)
Returns true if each character in str is a hex character, and has an even number of hex digits.
std::vector< uint8_t > ParseHex(const char *psz)
static constexpr Amount zero() noexcept
std::string ToString() const
ProofId computeProofId(const CPubKey &proofMaster) const
StakeCommitment(int64_t expirationTime, const CPubKey &master)
bilingual_str _(const char *psz)
Translation function.
static const int PROTOCOL_VERSION
network protocol versioning