Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 4,121 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
if (msg_type == NetMsgType::AVAHELLO) { | if (msg_type == NetMsgType::AVAHELLO) { | ||||
if (!pfrom.m_avalanche_state) { | if (!pfrom.m_avalanche_state) { | ||||
pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | ||||
} | } | ||||
CHashVerifier<CDataStream> verifier(&vRecv); | CHashVerifier<CDataStream> verifier(&vRecv); | ||||
avalanche::Delegation &delegation = pfrom.m_avalanche_state->delegation; | avalanche::Delegation delegation; | ||||
verifier >> delegation; | verifier >> delegation; | ||||
avalanche::DelegationState state; | avalanche::DelegationState state; | ||||
CPubKey pubkey; | CPubKey &pubkey = pfrom.m_avalanche_state->pubkey; | ||||
if (!delegation.verify(state, pubkey)) { | if (!delegation.verify(state, pubkey)) { | ||||
Misbehaving(pfrom, 100, "invalid-delegation"); | Misbehaving(pfrom, 100, "invalid-delegation"); | ||||
return; | return; | ||||
} | } | ||||
CHashWriter sighasher(SER_GETHASH, 0); | CHashWriter sighasher(SER_GETHASH, 0); | ||||
sighasher << pfrom.m_avalanche_state->delegation.getId(); | sighasher << delegation.getId(); | ||||
sighasher << pfrom.nRemoteHostNonce; | sighasher << pfrom.nRemoteHostNonce; | ||||
sighasher << pfrom.GetLocalNonce(); | sighasher << pfrom.GetLocalNonce(); | ||||
sighasher << pfrom.nRemoteExtraEntropy; | sighasher << pfrom.nRemoteExtraEntropy; | ||||
sighasher << pfrom.GetLocalExtraEntropy(); | sighasher << pfrom.GetLocalExtraEntropy(); | ||||
SchnorrSig sig; | SchnorrSig sig; | ||||
verifier >> sig; | verifier >> sig; | ||||
if (!pubkey.VerifySchnorr(sighasher.GetHash(), sig)) { | if (!pubkey.VerifySchnorr(sighasher.GetHash(), sig)) { | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | |||||
if (msg_type == NetMsgType::AVARESPONSE) { | if (msg_type == NetMsgType::AVARESPONSE) { | ||||
// As long as QUIC is not implemented, we need to sign response and | // As long as QUIC is not implemented, we need to sign response and | ||||
// verify response's signatures in order to avoid any manipulation of | // verify response's signatures in order to avoid any manipulation of | ||||
// messages at the transport level. | // messages at the transport level. | ||||
CHashVerifier<CDataStream> verifier(&vRecv); | CHashVerifier<CDataStream> verifier(&vRecv); | ||||
avalanche::Response response; | avalanche::Response response; | ||||
verifier >> response; | verifier >> response; | ||||
if (!g_avalanche->forNode(pfrom.GetId(), [&](const avalanche::Node &n) { | |||||
SchnorrSig sig; | SchnorrSig sig; | ||||
vRecv >> sig; | vRecv >> sig; | ||||
return n.pubkey.VerifySchnorr(verifier.GetHash(), sig); | if (!pfrom.m_avalanche_state || | ||||
})) { | !pfrom.m_avalanche_state->pubkey.VerifySchnorr(verifier.GetHash(), | ||||
sig)) { | |||||
Misbehaving(pfrom, 100, "invalid-ava-response-signature"); | Misbehaving(pfrom, 100, "invalid-ava-response-signature"); | ||||
return; | return; | ||||
} | } | ||||
std::vector<avalanche::BlockUpdate> updates; | std::vector<avalanche::BlockUpdate> updates; | ||||
if (!g_avalanche->registerVotes(pfrom.GetId(), response, updates)) { | if (!g_avalanche->registerVotes(pfrom.GetId(), response, updates)) { | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,554 Lines • Show Last 20 Lines |