Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.cpp
Show All 18 Lines | |||||
namespace avalanche { | namespace avalanche { | ||||
void Stake::computeStakeId() { | void Stake::computeStakeId() { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << *this; | ss << *this; | ||||
stakeid = StakeId(ss.GetHash()); | stakeid = StakeId(ss.GetHash()); | ||||
} | } | ||||
uint256 Stake::getHash(const ProofId &proofid) const { | uint256 Stake::getHash(const StakeCommitment &commitment) const { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << proofid; | ss << commitment; | ||||
ss << *this; | ss << *this; | ||||
return ss.GetHash(); | return ss.GetHash(); | ||||
} | } | ||||
bool SignedStake::verify(const ProofId &proofid) const { | bool SignedStake::verify(const StakeCommitment &commitment) const { | ||||
return stake.getPubkey().VerifySchnorr(stake.getHash(proofid), sig); | return stake.getPubkey().VerifySchnorr(stake.getHash(commitment), sig); | ||||
} | } | ||||
bool Proof::FromHex(Proof &proof, const std::string &hexProof, | bool Proof::FromHex(Proof &proof, const std::string &hexProof, | ||||
bilingual_str &errorOut) { | bilingual_str &errorOut) { | ||||
if (!IsHex(hexProof)) { | if (!IsHex(hexProof)) { | ||||
errorOut = _("Proof must be an hexadecimal string."); | errorOut = _("Proof must be an hexadecimal string."); | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | for (const SignedStake &ss : stakes) { | ||||
} | } | ||||
prevId = s.getId(); | prevId = s.getId(); | ||||
if (!utxos.insert(s.getUTXO()).second) { | if (!utxos.insert(s.getUTXO()).second) { | ||||
return state.Invalid(ProofValidationResult::DUPLICATE_STAKE, | return state.Invalid(ProofValidationResult::DUPLICATE_STAKE, | ||||
"duplicated-stake"); | "duplicated-stake"); | ||||
} | } | ||||
if (!ss.verify(proofid)) { | if (!ss.verify(getStakeCommitment())) { | ||||
return state.Invalid( | return state.Invalid( | ||||
ProofValidationResult::INVALID_STAKE_SIGNATURE, | ProofValidationResult::INVALID_STAKE_SIGNATURE, | ||||
"invalid-stake-signature", | "invalid-stake-signature", | ||||
strprintf("TxId: %s", s.getUTXO().GetTxId().ToString())); | strprintf("TxId: %s", s.getUTXO().GetTxId().ToString())); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |