mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Switch Alerts to use a scriptPubKey instead of a static key
This commit is contained in:
parent
0b7c7c9234
commit
80dbffe3ec
4 changed files with 34 additions and 16 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "chainparams.h"
|
||||
#include "clientversion.h"
|
||||
#include "hash.h"
|
||||
#include "net.h"
|
||||
#include "pubkey.h"
|
||||
#include "timedata.h"
|
||||
|
|
@ -86,7 +87,7 @@ void CAlert::SetNull()
|
|||
{
|
||||
CUnsignedAlert::SetNull();
|
||||
vchMsg.clear();
|
||||
vchSig.clear();
|
||||
scriptSig.clear();
|
||||
}
|
||||
|
||||
bool CAlert::IsNull() const
|
||||
|
|
@ -145,16 +146,34 @@ bool CAlert::RelayTo(CNode* pnode) const
|
|||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
class NaiveSignatureChecker : public BaseSignatureChecker
|
||||
{
|
||||
protected:
|
||||
uint256 hash;
|
||||
|
||||
public:
|
||||
NaiveSignatureChecker(const std::vector<unsigned char>& vchMsg)
|
||||
{
|
||||
CSHA256().Write(&vchMsg[0], vchMsg.size()).Finalize(hash.begin());
|
||||
}
|
||||
|
||||
bool CheckSig(const std::vector<unsigned char>& vchSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
|
||||
{
|
||||
CPubKey pubkey(vchPubKey);
|
||||
if (!pubkey.IsValid())
|
||||
return false;
|
||||
return pubkey.Verify(hash, vchSig);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool CAlert::CheckSignature() const
|
||||
{
|
||||
CPubKey key(Params().AlertKey());
|
||||
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
|
||||
return error("CAlert::CheckSignature() : verify signature failed");
|
||||
|
||||
// Now unserialize the data
|
||||
CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
|
||||
sMsg >> *(CUnsignedAlert*)this;
|
||||
return true;
|
||||
const CScript& scriptPubKey = Params().AlertKey();
|
||||
NaiveSignatureChecker checker(vchMsg);
|
||||
unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC | SCRIPT_VERIFY_NULLDUMMY | SCRIPT_VERIFY_SIGPUSHONLY | SCRIPT_VERIFY_MINIMALDATA | SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS;
|
||||
return VerifyScript(scriptSig, scriptPubKey, flags, checker, NULL);
|
||||
}
|
||||
|
||||
CAlert CAlert::getAlertByHash(const uint256 &hash)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#ifndef BITCOIN_ALERT_H
|
||||
#define BITCOIN_ALERT_H
|
||||
|
||||
#include "script/interpreter.h"
|
||||
#include "serialize.h"
|
||||
#include "sync.h"
|
||||
|
||||
|
|
@ -77,7 +78,7 @@ class CAlert : public CUnsignedAlert
|
|||
{
|
||||
public:
|
||||
std::vector<unsigned char> vchMsg;
|
||||
std::vector<unsigned char> vchSig;
|
||||
CScript scriptSig;
|
||||
|
||||
CAlert()
|
||||
{
|
||||
|
|
@ -89,7 +90,7 @@ public:
|
|||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
READWRITE(vchMsg);
|
||||
READWRITE(vchSig);
|
||||
READWRITE(scriptSig);
|
||||
}
|
||||
|
||||
void SetNull();
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public:
|
|||
pchMessageStart[1] = 0xbe;
|
||||
pchMessageStart[2] = 0xb4;
|
||||
pchMessageStart[3] = 0xd9;
|
||||
vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
|
||||
scriptAlert = CScript() << OP_TRUE;
|
||||
nDefaultPort = 8333;
|
||||
bnProofOfWorkLimit = ~uint256(0) >> 32;
|
||||
nSubsidyHalvingInterval = 210000;
|
||||
|
|
@ -176,7 +176,6 @@ public:
|
|||
pchMessageStart[1] = 0x11;
|
||||
pchMessageStart[2] = 0x09;
|
||||
pchMessageStart[3] = 0x07;
|
||||
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
|
||||
nDefaultPort = 18333;
|
||||
nEnforceBlockUpgradeMajority = 51;
|
||||
nRejectBlockOutdatedMajority = 75;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
const uint256& HashGenesisBlock() const { return hashGenesisBlock; }
|
||||
const MessageStartChars& MessageStart() const { return pchMessageStart; }
|
||||
const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
|
||||
const CScript& AlertKey() const { return scriptAlert; }
|
||||
int GetDefaultPort() const { return nDefaultPort; }
|
||||
const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
|
||||
int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; }
|
||||
|
|
@ -85,8 +85,7 @@ protected:
|
|||
|
||||
uint256 hashGenesisBlock;
|
||||
MessageStartChars pchMessageStart;
|
||||
//! Raw pub key bytes for the broadcast alert signing key.
|
||||
std::vector<unsigned char> vAlertPubKey;
|
||||
CScript scriptAlert;
|
||||
int nDefaultPort;
|
||||
uint256 bnProofOfWorkLimit;
|
||||
int nSubsidyHalvingInterval;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue