Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/delegation.cpp
Show All 31 Lines | |||||
} | } | ||||
DelegationId Delegation::computeDelegationId() const { | DelegationId Delegation::computeDelegationId() const { | ||||
uint256 hash = proofid; | uint256 hash = proofid; | ||||
reduceLevels(hash, levels); | reduceLevels(hash, levels); | ||||
return DelegationId(hash); | return DelegationId(hash); | ||||
} | } | ||||
bool Delegation::verify(DelegationState &state, const Proof &proof, | bool Delegation::verify(DelegationState &state, const CPubKey &proofMaster, | ||||
const LimitedProofId &limitedProofId, | |||||
CPubKey &auth) const { | CPubKey &auth) const { | ||||
if (proof.getId() != proofid) { | ProofId computedProofId = | ||||
Proof::computeIdFromLimitedId(limitedProofId, proofMaster); | |||||
if (computedProofId != proofid) { | |||||
return state.Invalid(DelegationResult::INCORRECT_PROOF); | return state.Invalid(DelegationResult::INCORRECT_PROOF); | ||||
} | } | ||||
uint256 hash = proofid; | uint256 hash = proofid; | ||||
const CPubKey *pauth = &proof.getMaster(); | const CPubKey *pauth = &proofMaster; | ||||
bool ret = reduceLevels(hash, levels, [&](const Level &l) { | bool ret = reduceLevels(hash, levels, [&](const Level &l) { | ||||
if (!pauth->VerifySchnorr(hash, l.sig)) { | if (!pauth->VerifySchnorr(hash, l.sig)) { | ||||
return state.Invalid(DelegationResult::INVALID_SIGNATURE); | return state.Invalid(DelegationResult::INVALID_SIGNATURE); | ||||
} | } | ||||
// This key is valid, now up to the next delegation level. | // This key is valid, now up to the next delegation level. | ||||
pauth = &l.pubkey; | pauth = &l.pubkey; | ||||
return true; | return true; | ||||
}); | }); | ||||
auth = *pauth; | auth = *pauth; | ||||
return ret; | return ret; | ||||
} | } | ||||
std::optional<CPubKey> Delegation::getMaster() const { | |||||
deadalnix: You are calling two different thing master. | |||||
return levels.size() == 0 | |||||
? std::nullopt | |||||
: std::make_optional<CPubKey>(levels.back().pubkey); | |||||
} | |||||
} // namespace avalanche | } // namespace avalanche |
You are calling two different thing master.