Bitcoin Forum
November 07, 2024, 07:31:39 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 2 3 4 5 [6] 7 8 9 10 11 12 13 14 15 »  All
  Print  
Author Topic: How do you create an altcoin?  (Read 21864 times)
chris200x9
Legendary
*
Offline Offline

Activity: 1316
Merit: 1011


View Profile
April 14, 2013, 12:00:02 AM
 #101

Didn't read all through it yet but maybe this helps? https://bitcointalk.org/index.php?topic=171355.0
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
April 14, 2013, 12:02:26 AM
 #102

Ok, so we basically have this

Code:
        const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
        CTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
        txNew.vout[0].nValue = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
        CBlock block;
        block.vtx.push_back(txNew);
        block.hashPrevBlock = 0;
        block.hashMerkleRoot = block.BuildMerkleTree();

What we are interested in is, BuildMerkleTree which is found in main.h

Code:
    uint256 BuildMerkleTree() const
    {
        vMerkleTree.clear();
        BOOST_FOREACH(const CTransaction& tx, vtx)
            vMerkleTree.push_back(tx.GetHash());
        int j = 0;
        for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
        {
            for (int i = 0; i < nSize; i += 2)
            {
                int i2 = std::min(i+1, nSize-1);
                vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]),  END(vMerkleTree[j+i]),
                                           BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
            }
            j += nSize;
        }
        return (vMerkleTree.empty() ? 0 : vMerkleTree.back());
    }

Next we are interested in this, I believe.

Code:
vMerkleTree.push_back(tx.GetHash());
since we have only one transaction, this will return as soon as it computes the has. So we see tx.GetHash, and that tx is of type CTransaction, so we head in that class, which is in main.h again

and see this coide

Code:
    uint256 GetHash() const
    {
        return SerializeHash(*this);
    }

which passes the instance of the object to SerializeHash. SerializeHash is located in hash.h

Code:
template<typename T>
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
{
    CHashWriter ss(nType, nVersion);
    ss << obj;
    return ss.GetHash();
}

Here we see that the object is written(I think, not sure) to ss which is an instance of CHashWriter which is also in main.h and that is where the funky business happens that is uber hard to understand.

But here we go,

Code:
class CHashWriter
{
private:
    SHA256_CTX ctx;

public:
    int nType;
    int nVersion;

    void Init() {
        SHA256_Init(&ctx);
    }

    CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {
        Init();
    }

    CHashWriter& write(const char *pch, size_t size) {
        SHA256_Update(&ctx, pch, size);
        return (*this);
    }

    // invalidates the object
    uint256 GetHash() {
        uint256 hash1;
        SHA256_Final((unsigned char*)&hash1, &ctx);
        uint256 hash2;
        SHA256((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
        return hash2;
    }

    template<typename T>
    CHashWriter& operator<<(const T& obj) {
        // Serialize to this stream
        ::Serialize(*this, obj, nType, nVersion);
        return (*this);
    }
};

CHashWriter, small, but deadly. I guess what we are further interested in, is

Code:
    template<typename T>
    CHashWriter& operator<<(const T& obj) {
        // Serialize to this stream
        ::Serialize(*this, obj, nType, nVersion);
        return (*this);
    }
which as you calls some global function Serialize that may or may not be located in serialize.h

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:07:09 AM
 #103

Ok, so we basically have this

Code:
        const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
        CTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
        txNew.vout[0].nValue = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
        CBlock block;
        block.vtx.push_back(txNew);
        block.hashPrevBlock = 0;
        block.hashMerkleRoot = block.BuildMerkleTree();

What we are interested in is, BuildMerkleTree which is found in main.h

Code:
    uint256 BuildMerkleTree() const
    {
        vMerkleTree.clear();
        BOOST_FOREACH(const CTransaction& tx, vtx)
            vMerkleTree.push_back(tx.GetHash());
        int j = 0;
        for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
        {
            for (int i = 0; i < nSize; i += 2)
            {
                int i2 = std::min(i+1, nSize-1);
                vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]),  END(vMerkleTree[j+i]),
                                           BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
            }
            j += nSize;
        }
        return (vMerkleTree.empty() ? 0 : vMerkleTree.back());
    }

Next we are interested in this, I believe.

Code:
vMerkleTree.push_back(tx.GetHash());
since we have only one transaction, this will return as soon as it computes the has. So we see tx.GetHash, and that tx is of type CTransaction, so we head in that class, which is in main.h again

and see this coide

Code:
    uint256 GetHash() const
    {
        return SerializeHash(*this);
    }

which passes the instance of the object to SerializeHash. SerializeHash is located in hash.h

Code:
template<typename T>
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
{
    CHashWriter ss(nType, nVersion);
    ss << obj;
    return ss.GetHash();
}

Here we see that the object is written(I think, not sure) to ss which is an instance of CHashWriter which is also in main.h and that is where the funky business happens that is uber hard to understand.

But here we go,

Code:
class CHashWriter
{
private:
    SHA256_CTX ctx;

public:
    int nType;
    int nVersion;

    void Init() {
        SHA256_Init(&ctx);
    }

    CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {
        Init();
    }

    CHashWriter& write(const char *pch, size_t size) {
        SHA256_Update(&ctx, pch, size);
        return (*this);
    }

    // invalidates the object
    uint256 GetHash() {
        uint256 hash1;
        SHA256_Final((unsigned char*)&hash1, &ctx);
        uint256 hash2;
        SHA256((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
        return hash2;
    }

    template<typename T>
    CHashWriter& operator<<(const T& obj) {
        // Serialize to this stream
        ::Serialize(*this, obj, nType, nVersion);
        return (*this);
    }
};

CHashWriter, small, but deadly. I guess what we are further interested in, is

Code:
    template<typename T>
    CHashWriter& operator<<(const T& obj) {
        // Serialize to this stream
        ::Serialize(*this, obj, nType, nVersion);
        return (*this);
    }
which as you calls some global function Serialize that may or may not be located in serialize.h

We really need an altcoin dev in here

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
April 14, 2013, 12:10:06 AM
 #104

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:11:21 AM
 #105

Ive made a discovery... i think??

Starting on line 1,985 of main.cpp

Code:
    //
    // Init with genesis block
    //
    if (mapBlockIndex.empty())
    {
        if (!fAllowNew)
            return false;

        // Genesis Block:
        // CBlock(hash=12a765e31ffd4059bada, PoW=0000050c34a64b415b6b, ver=1, hashPrevBlock=00000000000000000000, hashMerkleRoot=97ddfbbae6, nTime=1317972665, nBits=1e0ffff0, nNonce=2084524493, vtx=1)
        //   CTransaction(hash=97ddfbbae6, ver=1, vin.size=1, vout.size=1, nLockTime=0)
        //     CTxIn(COutPoint(0000000000, -1), coinbase 04ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536)
        //     CTxOut(nValue=50.00000000, scriptPubKey=040184710fa689ad5023690c80f3a4)
        //   vMerkleTree: 97ddfbbae6

        // Genesis block
        const char* pszTimestamp = "NY Times 05/Oct/2011 Steve Jobs, Apple’s Visionary, Dies at 56";
        CTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
        txNew.vout[0].nValue = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << ParseHex("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9") << OP_CHECKSIG;
        CBlock block;
        block.vtx.push_back(txNew);
        block.hashPrevBlock = 0;
        block.hashMerkleRoot = block.BuildMerkleTree();
        block.nVersion = 1;
        block.nTime    = 1317972665;
        block.nBits    = 0x1e0ffff0;
        block.nNonce   = 2084524493;

        if (fTestNet)
        {
            block.nTime    = 1317798646;
            block.nNonce   = 385270584;
        }

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:12:05 AM
 #106

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.
But then how did altcoin authors create theirs?  Undecided

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
achillez
Hero Member
*****
Offline Offline

Activity: 878
Merit: 1000


View Profile
April 14, 2013, 12:12:19 AM
 #107

Perhaps, but a q on this. Do you really want to create a sha256 alt, or LiteCoin (or better yet PPCoin) type chain instead?  
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
April 14, 2013, 12:13:00 AM
 #108

Ive made a discovery... i think??
That's where I derived my information from, by following the functions.

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:15:03 AM
 #109

Perhaps, but a q on this. Do you really want to create a sha256 alt, or LiteCoin (or better yet PPCoin) type chain instead?  

Really either is fine at this point im just trying to get somthing running

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
April 14, 2013, 12:15:49 AM
 #110

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.
But then how did altcoin authors create theirs?  Undecided
They've learned C++ and have no issue with the C++ semantics? Understand Cryptography more than we do?

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:16:49 AM
 #111

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.
But then how did altcoin authors create theirs?  Undecided
They've learned C++ and have no issue with the C++ semantics? Understand Cryptography more than we do?
True, true  Cheesy Tongue

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
wmikrut
Hero Member
*****
Offline Offline

Activity: 631
Merit: 501



View Profile WWW
April 14, 2013, 12:17:33 AM
 #112

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.

It's open source... it may be obscure... but that doesn't mean people don't have a right to know how to do it.
By the end of this thread hopefully we'll all know how it works!   Wink

I will NEVER ask for any kind of funds up front in a buy/sale of anything on bitcointalk.

BM-2cTFihJKmSwusMAoYuUHPvpx56Jozv64KK
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
April 14, 2013, 12:19:19 AM
 #113

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.

It's open source... it may be obscure... but that doesn't mean people don't have a right to know how to do it.
By the end of this thread hopefully we'll all know how it works!   Wink
Yeah, but we likely won't understand the process itself.

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:20:48 AM
 #114

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.

It's open source... it may be obscure... but that doesn't mean people don't have a right to know how to do it.
By the end of this thread hopefully we'll all know how it works!   Wink
This, I was not expecting this much interest when I started this thread but now myself and im sure a bunch of others really want to know what goes into this

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
wmikrut
Hero Member
*****
Offline Offline

Activity: 631
Merit: 501



View Profile WWW
April 14, 2013, 12:21:50 AM
 #115

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.

It's open source... it may be obscure... but that doesn't mean people don't have a right to know how to do it.
By the end of this thread hopefully we'll all know how it works!   Wink
Yeah, but we likely won't understand the process itself.

We'll figure it out   Grin

I will NEVER ask for any kind of funds up front in a buy/sale of anything on bitcointalk.

BM-2cTFihJKmSwusMAoYuUHPvpx56Jozv64KK
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:23:24 AM
 #116

If Sunny King can help us, it'd be nice. But I guess the reason the genesis block creation information is not found easily is because every noob(me included) on the block will have an alt-currency out by the end of the day.

It's open source... it may be obscure... but that doesn't mean people don't have a right to know how to do it.
By the end of this thread hopefully we'll all know how it works!   Wink
Yeah, but we likely won't understand the process itself.

We'll figure it out   Grin
I like your positive attitude Cheesy

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:27:13 AM
 #117

Is this whole thing on hold till we can get someone to help with the genesis block?

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
April 14, 2013, 12:28:54 AM
 #118

More like till an alt-coin dev sees the thread.

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
pixel (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


x1 7970 | Aprox. 587 kh/s


View Profile
April 14, 2013, 12:30:19 AM
 #119

More like till an alt-coin dev sees the thread.
I got my fingers crossed a dev runs across it, ill keep checking in

Currently Mining: Litecoin, Xencoin, and Worldcoin (Just because its fun!, don't yell at me ;_;)
wmikrut
Hero Member
*****
Offline Offline

Activity: 631
Merit: 501



View Profile WWW
April 14, 2013, 12:33:26 AM
 #120

Not that it's completely relevant... but I have been in programming for over 20 years.
I'll keep researching and reading code... if nothing else, I will try to decode the process as much as I can and relay all the information back here.... unless a dev comes in and goes "Oh.. 1, 2, 3... Done!".

I will NEVER ask for any kind of funds up front in a buy/sale of anything on bitcointalk.

BM-2cTFihJKmSwusMAoYuUHPvpx56Jozv64KK
Pages: « 1 2 3 4 5 [6] 7 8 9 10 11 12 13 14 15 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!