Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: CryptoCurious80 on April 26, 2018, 11:28:39 AM



Title: How do I get the genesis code to work well? Please, Someone Help me~!^
Post by: CryptoCurious80 on April 26, 2018, 11:28:39 AM
I am a regular person who became interested in crypto programming this time.

But I have a problem programming, so I write this. Please, I would appreciate your help. really thank you.


============================================================
The problem is that in making individual coins folk, there is no answer to how to form the Genesis block.

I chose just "nihilo coin source" for the exercise!

I can modify several coin features and do it right way.

But I don't know, how to make new genesis block hash value.

I did some searching. and find this "Genesis Block Generator, https://bitcointalk.org/index.php?topic=181981.0"

and I used that code for generating genesis block and hash and nnonce value.

and I put that value in my source at  chainparams.cpp and checkpoints.cpp .

and Run "make -f makefile.unix USE_UPNP=- "
But It doesn't work with this error AGAIN AGAIN AGAIN... :-[ :-[ :-[ :-[
============================================================
 
Code:
ubuntu@ubuntu-VirtualBox:~/Desktop/test/src$ ./testd
testd: chainparams.cpp:94: CMainParams::CMainParams(): Assertion `hashGenesisBlock == uint256("0x803a095a9705f06c6e52f1308374ef5be3ba7a842559b218eb324e38c5444e16")' failed.
Aborted (core dumped)
============================================================
And this is chainparams.cpp

Code:
// Copyright (c) 2010 Satoshi Nakamoto
/// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "assert.h"

#include "chainparams.h"
#include "main.h"
#include "util.h"

#include <boost/assign/list_of.hpp>

using namespace boost::assign;

struct SeedSpec6 {
   uint8_t addr[16];
   uint16_t port;
};

#include "chainparamsseeds.h"

//
// Main network
//

// Convert the pnSeeds array into usable address objects.
static void convertSeeds(std::vector<CAddress> &vSeedsOut, const unsigned int *data, unsigned int count, int port)
{
    // It'll only connect to one or two seed nodes because once it connects,
    // it'll get a pile of addresses with newer timestamps.
    // Seed nodes are given a random 'last seen time' of between one and two
    // weeks ago.
    const int64_t nOneWeek = 7*24*60*60;
   for (unsigned int k = 0; k < count; ++k)
   {
       struct in_addr ip;
       unsigned int i = data[k], t;
       
       // -- convert to big endian
       t =   (i & 0x000000ff) << 24u
           | (i & 0x0000ff00) << 8u
           | (i & 0x00ff0000) >> 8u
           | (i & 0xff000000) >> 24u;
       
       memcpy(&ip, &t, sizeof(ip));
       
       CAddress addr(CService(ip, port));
       addr.nTime = GetTime()-GetRand(nOneWeek)-nOneWeek;
       vSeedsOut.push_back(addr);
   }
}

class CMainParams : public CChainParams {
public:
   CMainParams() {
       // The message start string is designed to be unlikely to occur in normal data.
       // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
       // a large 4-byte int at any alignment.
       pchMessageStart[0] = 0xb1;
       pchMessageStart[1] = 0xc2;
       pchMessageStart[2] = 0x3c;
       pchMessageStart[3] = 0xd1;
       vAlertPubKey = ParseHex("0498041d17a04788c7490899e35c8314a3a9fd369332900eec05e2b0589cd2147478985144d91956b6c732c9427fb3e8b153a7ae7681aa05729c91bb4b7536f9c3");
       nDefaultPort = 18858;
       nRPCPort = 13858;
       bnProofOfWorkLimit = CBigNum(~uint256(0) >> 16);

       // Build the genesis block. Note that the output of the genesis coinbase cannot
       // be spent as it did not originally exist in the database.
       //
       //CBlock(hash=000001faef25dec4fbcf906e6242621df2c183bf232f263d0ba5b101911e4563, ver=1, hashPrevBlock=0000000000000000000000000000000000000000000000000000000000000000, hashMerkleRoot=12630d16a97f24b287c8c2594dda5fb98c9e6c70fc61d44191931ea2aa08dc90, nTime=1393221600, nBits=1e0fffff, nNonce=164482, vtx=1, vchBlockSig=)
       //  Coinbase(hash=12630d16a9, nTime=1393221600, ver=1, vin.size=1, vout.size=1, nLockTime=0)
       //    CTxIn(COutPoint(0000000000, 4294967295), coinbase 00012a24323020466562203230313420426974636f696e2041544d7320636f6d6520746f20555341)
       //    CTxOut(empty)
       //  vMerkleTree: 12630d16a9
       const char* pszTimestamp = "This is test";
       std::vector<CTxIn> vin;
       vin.resize(1);
       vin[0].scriptSig = CScript() << 0 << CBigNum(42) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
       std::vector<CTxOut> vout;
       vout.resize(1);
       vout[0].SetEmpty();
       CTransaction txNew(1, 1524734223, vin, vout, 0);
       genesis.vtx.push_back(txNew);
       genesis.hashPrevBlock = 0;
       genesis.hashMerkleRoot = genesis.BuildMerkleTree();
       genesis.nVersion = 1;
       genesis.nTime    = 1524734223;
       genesis.nBits    = 0x1f00ffff;
       genesis.nNonce   = 289220;
       
       hashGenesisBlock = genesis.GetHash();
       assert(hashGenesisBlock == uint256("0x803a095a9705f06c6e52f1308374ef5be3ba7a842559b218eb324e38c5444e16"));
       assert(genesis.hashMerkleRoot == uint256("0x055a67b1b326ce2701e15876d87f9035dd930e7dea8627e92e1ba7bbe8f1c850"));

       base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,53);
       base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,112);
       base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1,181);
       base58Prefixes[STEALTH_ADDRESS] = std::vector<unsigned char>(1,40);
       base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();
       base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
       vSeeds.push_back(CDNSSeedData("1",  "127.0.0.1"));
      // vSeeds.push_back(CDNSSeedData("2",  "ns2.test.space"));//
      // vSeeds.push_back(CDNSSeedData("3",  "ns3.test.space"));//
       //vSeeds.push_back(CDNSSeedData("4",  "ns4.test.space"));//
       //vSeeds.push_back(CDNSSeedData("5",  "ns5.test.space"));//
      // vSeeds.push_back(CDNSSeedData("6",  "ns6.test.space"));//
      // vSeeds.push_back(CDNSSeedData("7",  "ns7.test.space"));//
      // vSeeds.push_back(CDNSSeedData("8",  "ns8.test.space"));//
      // vSeeds.push_back(CDNSSeedData("9",  "ns9.test.space"));//
      // vSeeds.push_back(CDNSSeedData("10", "ns10.test.space"));//
      // convertSeeds(vFixedSeeds, pnSeed, ARRAYLEN(pnSeed), nDefaultPort);

       nPoolMaxTransactions = 3;
       //strSporkKey = "046f78dcf911fbd61910136f7f0f8d90578f68d0b3ac973b5040fb7afb501b5939f39b108b0569dca71488f5bbf498d92e4d1194f6f941307ffd95f75e76869f0e";
       //strMasternodePaymentsPubKey = "046f78dcf911fbd61910136f7f0f8d90578f68d0b3ac973b5040fb7afb501b5939f39b108b0569dca71488f5bbf498d92e4d1194f6f941307ffd95f75e76869f0e";
       strDarksendPoolDummyAddress = "NVVUpZWDQYSfb2mF6yqtK1P6j6Kd3gbrK8";
       nLastPOWBlock = 100;
       nPOSStartBlock = 1;
   }

   virtual const CBlock& GenesisBlock() const { return genesis; }
   virtual Network NetworkID() const { return CChainParams::MAIN; }

   virtual const vector<CAddress>& FixedSeeds() const {
       return vFixedSeeds;
   }
protected:
   CBlock genesis;
   vector<CAddress> vFixedSeeds;
};
static CMainParams mainParams;


//
// Testnet
//

class CTestNetParams : public CMainParams {
public:
   CTestNetParams() {
       // The message start string is designed to be unlikely to occur in normal data.
       // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
       // a large 4-byte int at any alignment.
       pchMessageStart[0] = 0xd2;
       pchMessageStart[1] = 0xc2;
       pchMessageStart[2] = 0xb1;
       pchMessageStart[3] = 0xd4;
       bnProofOfWorkLimit = CBigNum(~uint256(0) >> 16);
       vAlertPubKey = ParseHex("04263773dcadb756271c7a3e915d493284472c02e9bf639dca63bff3d937b8cd82064b279fd8a02da94112c0902e90a1de65ba686cfe8affc9b79b88f8944c8d5b");
       nDefaultPort = 18857;
       nRPCPort = 13857;
       strDataDir = "testnet";

       // Modify the testnet genesis block so the timestamp is valid for a later start.
       genesis.nBits  = 1524734223;
       genesis.nNonce = 289220;
 
       assert(hashGenesisBlock == uint256("0x803a095a9705f06c6e52f1308374ef5be3ba7a842559b218eb324e38c5444e16"));

       vFixedSeeds.clear();
       vSeeds.clear();

       base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,9);
       base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
       base58Prefixes[SECRET_KEY]     = std::vector<unsigned char>(1,239);
       base58Prefixes[STEALTH_ADDRESS] = std::vector<unsigned char>(1,40);
       base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
       base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();

       convertSeeds(vFixedSeeds, pnTestnetSeed, ARRAYLEN(pnTestnetSeed), nDefaultPort);

       nLastPOWBlock = 0x7fffffff;
   }
   virtual Network NetworkID() const { return CChainParams::TESTNET; }
};
static CTestNetParams testNetParams;


static CChainParams *pCurrentParams = &mainParams;

const CChainParams &Params() {
   return *pCurrentParams;
}

void SelectParams(CChainParams::Network network) {
   switch (network) {
       case CChainParams::MAIN:
           pCurrentParams = &mainParams;
           break;
       case CChainParams::TESTNET:
           pCurrentParams = &testNetParams;
           break;
       default:
           assert(false && "Unimplemented network");
           return;
   }
}

bool SelectParamsFromCommandLine() {
   
   bool fTestNet = GetBoolArg("-testnet", false);
   
   if (fTestNet) {
       SelectParams(CChainParams::TESTNET);
   } else {
       SelectParams(CChainParams::MAIN);
   }
   return true;
}
============================================================
how to get new genesisblockhash and nnonce value??
Please tell me where I can get code for generating.
I haven't been able to solve the problem for days.
plz.....

============================================================
And it doesnt working ...... this is code for searching genesis block .. it works good at litecoin0.8 source. but not working at nihilo coin source. How to fix it... plz someone help me. It's driving me crazy.

Code:
if (true && block.GetHash() != hashGenesisBlock)
        {
            printf("Searching for genesis block...\n");
            // This will figure out a valid hash and Nonce if you're
            // creating a different genesis block:
            uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256();
            uint256 thash;
            char scratchpad[SCRYPT_SCRATCHPAD_SIZE];
 
            loop
            {
#if defined(USE_SSE2)
                // Detection would work, but in cases where we KNOW it always has SSE2,
                // it is faster to use directly than to use a function pointer or conditional.
#if defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64) || (defined(MAC_OSX) && defined(__i386__))
                // Always SSE2: x86_64 or Intel MacOS X
                scrypt_1024_1_1_256_sp_sse2(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#else
                // Detect SSE2: 32bit x86 Linux or Windows
                scrypt_1024_1_1_256_sp(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#endif
#else
                // Generic scrypt
                scrypt_1024_1_1_256_sp_generic(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#endif
                if (thash <= hashTarget)
                    break;
                if ((block.nNonce & 0xFFF) == 0)
                {
                    printf("nonce %08X: hash = %s (target = %s)\n", block.nNonce, thash.ToString().c_str(), hashTarget.ToString().c_str());
                }
                ++block.nNonce;
                if (block.nNonce == 0)
                {
                    printf("NONCE WRAPPED, incrementing time\n");
                    ++block.nTime;
                }
            }
            printf("block.nTime = %u \n", block.nTime);
            printf("block.nNonce = %u \n", block.nNonce);
            printf("block.GetHash = %s\n", block.GetHash().ToString().c_str());
        }


Title: Re: How do I get the genesis code to work well? Please, Someone Help me~!^
Post by: starmyc on April 26, 2018, 01:40:44 PM
The Nihilo coin, if my google skills didn't lie to me, is that thing: https://bitcointalk.org/index.php?topic=2939377.0;all

It can be read:
Code:
Coin Name : NIHILO
Coin abbreviation : NIHL
Coin Type : Full POS
Algorith : SHA256

And I can see in your code:

Code:
                // Generic scrypt
                scrypt_1024_1_1_256_sp_generic(BEGIN(block.nVersion), BEGIN(thash), scratchpad);

You're trying to generate a new genesis hash using scrypt as POW for a coin that is using a sha256 hash ? I don't think that'll work. You should try another way to mine your genesis block.


Title: Re: How do I get the genesis code to work well? Please, Someone Help me~!^
Post by: starmyc on April 26, 2018, 04:00:32 PM
Use the C++ code instead:

Code:
        if (genesis.GetHash() != hashGenesisBlock) {
            printf("Searching for genesis block...\n");
            uint256 hashTarget = CBigNum().SetCompact(genesis.nBits).getuint256();

            uint256 thash;
            while (true) {
                thash = genesis.GetHash();
                if (thash <= hashTarget)
                    break;
                if ((genesis.nNonce & 0xFFF) == 0) {
                    printf("nonce %08X: hash = %s (target = %s)\n", genesis.nNonce, thash.ToString().c_str(), hashTarget.ToString().c_str());
                }
                ++genesis.nNonce;
                if (genesis.nNonce == 0) {
                    printf("NONCE WRAPPED, incrementing time\n");
                    ++genesis.nTime;
                }
            }
            printf("genesis.nTime = %u \n", genesis.nTime);
            printf("genesis.nNonce = %u \n", genesis.nNonce);
            printf("genesis.nVersion = %u \n", genesis.nVersion);
            printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str());

            exit(0);
        }

Recompile your wallet, and it will start finding a new hash. Once done, it will show:

Code:
nonce 0001E000: hash = e571a0595cff9b31411fbeb2ae8d4cfe4714ac340c9366a57cd4dabc35116038 (target = 0000ffff00000000000000000000000000000000000000000000000000000000)
nonce 0001F000: hash = 0d54e490dc03f51b7b0259017222f0ac202a34ff7367158196ad59f72c56a151 (target = 0000ffff00000000000000000000000000000000000000000000000000000000)
nonce 00020000: hash = c71c1cf88208687023932cfce2fada773669ab5ab7c0e685ed5682a0d0854795 (target = 0000ffff00000000000000000000000000000000000000000000000000000000)
nonce 00021000: hash = 3e4e8d279638da295b808e952b0f10656cea4ced6785c7ef3eea6db5ded6fce6 (target = 0000ffff00000000000000000000000000000000000000000000000000000000)
nonce 00022000: hash = 5bfe00c0c1909a07e0107cd3a148dba055cca6e43ae1c914a8805e0f4d6028f6 (target = 0000ffff00000000000000000000000000000000000000000000000000000000)
nonce 00023000: hash = 082b9b8c2912eced64d3460e2403bb3fe304eb570f8b8b40f898a7db5e8236aa (target = 0000ffff00000000000000000000000000000000000000000000000000000000)
genesis.nTime = 1519969226
genesis.nNonce = 145652
genesis.nVersion = 1
genesis.GetHash = 00000f950479e4c3ff0d0022287cb7a21fa51d8294ff6a8e342ba547c98b3e67

Report the hash value and the nonce value in your code, and you'll be good!


Title: Re: How do I get the genesis code to work well? Please, Someone Help me~!^
Post by: eiacgroup on December 05, 2021, 08:44:20 PM
When compiling the code returns:

fatal: packed object 7787377f79d120b9487bc178817913959ba05430 (stored in .git/objects/pack/pack-501f80c10a77f023a1f6e4f5da3e2992c6fc1b71.pack) is corrupt
g++ -c -O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -g -DBOOST_SPIRIT_THREADSAFE -D_FILE_OFFSET_BITS=64 -I/home/ubuntu/Desktop/eiacoin/src -I/home/ubuntu/Desktop/eiacoin/src/obj -DUSE_UPNP=0 -DUSE_IPV6=1 -I/home/ubuntu/Desktop/eiacoin/src/leveldb/include -I/home/ubuntu/Desktop/eiacoin/src/leveldb/helpers -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2  -MMD -MF obj/main.d -o obj/main.o main.cpp
main.cpp: In function ‘bool InitBlockIndex()’:
main.cpp:2836:11: error: ‘genesis’ was not declared in this scope
       if (genesis.GetHash() != hashGenesisBlock) {

Solved my issue:

if (block.GetHash() != hashGenesisBlock) {
            printf("Searching for genesis block...\n");
            uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256();

            uint256 thash;
            while (true) {
                thash = block.GetHash();
                if (thash <= hashTarget)
                    break;
                if ((block.nNonce & 0xFFF) == 0) {
                    printf("nonce %08X: hash = %s (target = %s)\n", block.nNonce, thash.ToString().c_str(), hashTarget.ToString().c_str());
                }
                ++block.nNonce;
                if (block.nNonce == 0) {
                    printf("NONCE WRAPPED, incrementing time\n");
                    ++block.nTime;
                }
            }
            printf("block.nTime = %u \n", block.nTime);
            printf("block.nNonce = %u \n", block.nNonce);
            printf("block.nVersion = %u \n", block.nVersion);
            printf("block.GetHash = %s\n", block.GetHash().ToString().c_str());

            exit(0);
        }