Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <policy/policy.h> | |||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <unordered_set> | #include <unordered_set> | ||||
Show All 34 Lines | bool Proof::FromHex(Proof &proof, const std::string &hexProof, | ||||
return true; | return true; | ||||
} | } | ||||
void Proof::computeProofId() { | void Proof::computeProofId() { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << sequence; | ss << sequence; | ||||
ss << expirationTime; | ss << expirationTime; | ||||
if (!useLegacy(gArgs)) { | |||||
ss << payoutScriptPubKey; | |||||
} | |||||
WriteCompactSize(ss, stakes.size()); | WriteCompactSize(ss, stakes.size()); | ||||
for (const SignedStake &s : stakes) { | for (const SignedStake &s : stakes) { | ||||
ss << s.getStake(); | ss << s.getStake(); | ||||
} | } | ||||
limitedProofId = LimitedProofId(ss.GetHash()); | limitedProofId = LimitedProofId(ss.GetHash()); | ||||
proofid = limitedProofId.computeProofId(master); | proofid = limitedProofId.computeProofId(master); | ||||
Show All 14 Lines | bool Proof::verify(ProofValidationState &state) const { | ||||
} | } | ||||
if (stakes.size() > AVALANCHE_MAX_PROOF_STAKES) { | if (stakes.size() > AVALANCHE_MAX_PROOF_STAKES) { | ||||
return state.Invalid( | return state.Invalid( | ||||
ProofValidationResult::TOO_MANY_UTXOS, "too-many-utxos", | ProofValidationResult::TOO_MANY_UTXOS, "too-many-utxos", | ||||
strprintf("%u > %u", stakes.size(), AVALANCHE_MAX_PROOF_STAKES)); | strprintf("%u > %u", stakes.size(), AVALANCHE_MAX_PROOF_STAKES)); | ||||
} | } | ||||
if (!useLegacy(gArgs)) { | |||||
TxoutType scriptType; | |||||
if (!IsStandard(payoutScriptPubKey, scriptType)) { | |||||
return state.Invalid(ProofValidationResult::INVALID_PAYOUT_SCRIPT, | |||||
"payout-script-non-standard"); | |||||
} | |||||
} | |||||
StakeId prevId = uint256::ZERO; | StakeId prevId = uint256::ZERO; | ||||
std::unordered_set<COutPoint, SaltedOutpointHasher> utxos; | std::unordered_set<COutPoint, SaltedOutpointHasher> utxos; | ||||
for (const SignedStake &ss : stakes) { | for (const SignedStake &ss : stakes) { | ||||
const Stake &s = ss.getStake(); | const Stake &s = ss.getStake(); | ||||
if (s.getAmount() < PROOF_DUST_THRESHOLD) { | if (s.getAmount() < PROOF_DUST_THRESHOLD) { | ||||
return state.Invalid(ProofValidationResult::DUST_THRESOLD, | return state.Invalid(ProofValidationResult::DUST_THRESOLD, | ||||
"amount-below-dust-threshold", | "amount-below-dust-threshold", | ||||
strprintf("%s < %s", s.getAmount().ToString(), | strprintf("%s < %s", s.getAmount().ToString(), | ||||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |