10
10
#include " util.h"
11
11
#include " utilstrencodings.h"
12
12
#include " amount.h"
13
+ #include " crypto/ripemd160.h"
13
14
14
15
#include < assert.h>
15
16
16
17
#include < boost/assign/list_of.hpp>
17
18
18
19
#include " chainparamsseeds.h"
19
20
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
+
20
33
static CScript StrHexToScriptWithDefault (std::string strScript, const CScript defaultScript)
21
34
{
22
35
CScript returnScript;
@@ -29,14 +42,15 @@ static CScript StrHexToScriptWithDefault(std::string strScript, const CScript de
29
42
return returnScript;
30
43
}
31
44
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)
33
46
{
34
47
// Shards must be evenly divisible
35
48
assert (MAX_MONEY % rewardShards == 0 );
36
49
CMutableTransaction txNew;
37
50
txNew.nVersion = 1 ;
38
51
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));
40
54
txNew.vout .resize (rewardShards);
41
55
for (unsigned int i = 0 ; i < rewardShards; i++) {
42
56
txNew.vout [i].nValue = genesisReward/rewardShards;
@@ -128,7 +142,7 @@ class CElementsParams : public CChainParams {
128
142
129
143
parentGenesisBlockHash = uint256S (" 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943" );
130
144
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);
132
146
consensus.hashGenesisBlock = genesis.GetHash ();
133
147
134
148
scriptCoinbaseDestination = CScript () << ParseHex (" 0229536c4c83789f59c30b93eb40d4abbd99b8dcc99ba8bd748f29e33c1d279e3c" ) << OP_CHECKSIG;
@@ -229,7 +243,7 @@ class CRegTestParams : public CChainParams {
229
243
nDefaultPort = 7042 ;
230
244
nPruneAfterHeight = 1000 ;
231
245
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);
233
247
consensus.hashGenesisBlock = genesis.GetHash ();
234
248
235
249
parentGenesisBlockHash = uint256S (" 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206" );
0 commit comments