Skip to content

Commit db42451

Browse files
instagibbsjtimon
authored andcommitted
HF: Genesis block includes fedpegscript
1 parent 8d1b552 commit db42451

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/chainparams.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@
1010
#include "util.h"
1111
#include "utilstrencodings.h"
1212
#include "amount.h"
13+
#include "crypto/ripemd160.h"
1314

1415
#include <assert.h>
1516

1617
#include <boost/assign/list_of.hpp>
1718

1819
#include "chainparamsseeds.h"
1920

21+
// Safer for users if they load incorrect parameters via arguments.
22+
static std::vector<unsigned char> CommitToArguments(const Consensus::Params& params, const std::string& networkID, const CScript& signblockscript)
23+
{
24+
CRIPEMD160 ripemd;
25+
unsigned char commitment[20];
26+
ripemd.Write((const unsigned char*)networkID.c_str(), networkID.length());
27+
ripemd.Write((const unsigned char*)HexStr(params.fedpegScript).c_str(), HexStr(params.fedpegScript).length());
28+
ripemd.Write((const unsigned char*)HexStr(signblockscript).c_str(), HexStr(signblockscript).length());
29+
ripemd.Finalize(commitment);
30+
return std::vector<unsigned char>(commitment, commitment + 20);
31+
}
32+
2033
static CScript StrHexToScriptWithDefault(std::string strScript, const CScript defaultScript)
2134
{
2235
CScript returnScript;
@@ -29,14 +42,15 @@ static CScript StrHexToScriptWithDefault(std::string strScript, const CScript de
2942
return returnScript;
3043
}
3144

32-
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, const CScript& scriptChallenge, int32_t nVersion, const CAmount& genesisReward, const uint32_t rewardShards, const CAsset& asset)
45+
static CBlock CreateGenesisBlock(const Consensus::Params& params, const std::string& networkID, const CScript& genesisOutputScript, uint32_t nTime, const CScript& scriptChallenge, int32_t nVersion, const CAmount& genesisReward, const uint32_t rewardShards, const CAsset& asset)
3346
{
3447
// Shards must be evenly divisible
3548
assert(MAX_MONEY % rewardShards == 0);
3649
CMutableTransaction txNew;
3750
txNew.nVersion = 1;
3851
txNew.vin.resize(1);
39-
txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
52+
// Any consensus-related values that are command-line set can be added here for anti-footgun
53+
txNew.vin[0].scriptSig = CScript(CommitToArguments(params, networkID, scriptChallenge));
4054
txNew.vout.resize(rewardShards);
4155
for (unsigned int i = 0; i < rewardShards; i++) {
4256
txNew.vout[i].nValue = genesisReward/rewardShards;
@@ -128,7 +142,7 @@ class CElementsParams : public CChainParams {
128142

129143
parentGenesisBlockHash = uint256S("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943");
130144
CScript scriptDestination(CScript() << std::vector<unsigned char>(parentGenesisBlockHash.begin(), parentGenesisBlockHash.end()) << OP_WITHDRAWPROOFVERIFY);
131-
genesis = CreateGenesisBlock(strNetworkID.c_str(), scriptDestination, 1231006505, genesisChallengeScript, 1, MAX_MONEY, 100, BITCOINID);
145+
genesis = CreateGenesisBlock(consensus, strNetworkID, scriptDestination, 1231006505, genesisChallengeScript, 1, MAX_MONEY, 100, BITCOINID);
132146
consensus.hashGenesisBlock = genesis.GetHash();
133147

134148
scriptCoinbaseDestination = CScript() << ParseHex("0229536c4c83789f59c30b93eb40d4abbd99b8dcc99ba8bd748f29e33c1d279e3c") << OP_CHECKSIG;
@@ -229,7 +243,7 @@ class CRegTestParams : public CChainParams {
229243
nDefaultPort = 7042;
230244
nPruneAfterHeight = 1000;
231245

232-
genesis = CreateGenesisBlock(strNetworkID.c_str(), defaultRegtestScript, 1296688602, genesisChallengeScript, 1, MAX_MONEY, 100, BITCOINID);
246+
genesis = CreateGenesisBlock(consensus, strNetworkID, defaultRegtestScript, 1296688602, genesisChallengeScript, 1, MAX_MONEY, 100, BITCOINID);
233247
consensus.hashGenesisBlock = genesis.GetHash();
234248

235249
parentGenesisBlockHash = uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206");

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14771477
// If the loaded chain has a wrong genesis, bail out immediately
14781478
// (we're likely using a testnet datadir, or the other way around).
14791479
if (!mapBlockIndex.empty() && mapBlockIndex.count(chainparams.GetConsensus().hashGenesisBlock) == 0)
1480-
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
1480+
return InitError(_("Incorrect or no genesis block found. Wrong `-fedpegscript`, `-signblockscript`, or datadir for network?"));
14811481

14821482
// Initialize the block index (no-op if non-empty database was already loaded)
14831483
if (!InitBlockIndex(chainparams)) {

0 commit comments

Comments
 (0)