diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -252,7 +252,10 @@ // Generate the delegation to the session key. DelegationBuilder dgb(*peerData->proof); if (sessionKey.GetPubKey() != peerData->proof->getMaster()) { - dgb.addLevel(masterKey, sessionKey.GetPubKey()); + if (!dgb.addLevel(masterKey, sessionKey.GetPubKey())) { + error = _("The private key does not match the proof."); + return nullptr; + } } peerData->delegation = dgb.build(); } diff --git a/test/functional/abc_rpc_avalancheproof.py b/test/functional/abc_rpc_avalancheproof.py --- a/test/functional/abc_rpc_avalancheproof.py +++ b/test/functional/abc_rpc_avalancheproof.py @@ -366,6 +366,18 @@ match=ErrorMatch.PARTIAL_REGEX, ) + # Master private key mismatch + random_privkey = ECKey() + random_privkey.generate() + node.assert_start_raises_init_error( + self.extra_args[0] + [ + "-avaproof={}".format(proof), + "-avamasterkey={}".format( + bytes_to_wif(random_privkey.get_bytes())), + ], + expected_msg="Error: The private key does not match the proof.", + ) + if __name__ == '__main__': AvalancheProofTest().main()