diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -286,6 +286,12 @@ CPubKey getSessionPubKey() const; bool sendHello(CNode *pfrom) const; + /** + * Build and return the challenge whose signature we expect a peer to + * include in his AVAHELLO message. + */ + uint256 buildRemoteSighash(CNode *pfrom) const; + std::vector getPeers() const; std::vector getNodeIdsForPeer(PeerId peerId) const; @@ -298,6 +304,12 @@ std::vector getInvsForNextPoll(bool forPoll = true); NodeId getSuitableNodeToQuery(); + /** + * Build and return the challenge whose signature is included in the + * AVAHELLO message that we send to a peer. + */ + uint256 buildLocalSighash(CNode *pfrom) const; + friend struct ::avalanche::AvalancheTest; }; diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -397,6 +397,26 @@ return sessionKey.GetPubKey(); } +uint256 Processor::buildLocalSighash(CNode *pfrom) const { + CHashWriter hasher(SER_GETHASH, 0); + hasher << peerData->delegation.getId(); + hasher << pfrom->GetLocalNonce(); + hasher << pfrom->nRemoteHostNonce; + hasher << pfrom->GetLocalExtraEntropy(); + hasher << pfrom->nRemoteExtraEntropy; + return hasher.GetHash(); +} + +uint256 Processor::buildRemoteSighash(CNode *pfrom) const { + CHashWriter hasher(SER_GETHASH, 0); + hasher << pfrom->m_avalanche_state->delegation.getId(); + hasher << pfrom->nRemoteHostNonce; + hasher << pfrom->GetLocalNonce(); + hasher << pfrom->nRemoteExtraEntropy; + hasher << pfrom->GetLocalExtraEntropy(); + return hasher.GetHash(); +} + bool Processor::sendHello(CNode *pfrom) const { if (!peerData) { // We do not have a delegation to advertise. @@ -407,13 +427,7 @@ SchnorrSig sig; { - CHashWriter hasher(SER_GETHASH, 0); - hasher << peerData->delegation.getId(); - hasher << pfrom->GetLocalNonce(); - hasher << pfrom->nRemoteHostNonce; - hasher << pfrom->GetLocalExtraEntropy(); - hasher << pfrom->nRemoteExtraEntropy; - const uint256 hash = hasher.GetHash(); + const uint256 hash = buildLocalSighash(pfrom); if (!sessionKey.SignSchnorr(hash, sig)) { return false;