Bitcoin Forum
May 03, 2024, 12:31:36 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Twelve-step program for making yet another stupid altcoin.  (Read 2932 times)
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 10, 2015, 08:11:38 AM
Last edit: April 10, 2015, 06:05:03 PM by Cryddit
 #1

I never really realized how ridiculously easy it is to make a clonecoin.  It's literally a matter of about a dozen command lines and editing one file to make a clonecoin that's completely pointless.  Here's how it goes (although the command lines may be different depending on your OS and/or command shell program).

1.  Download and unpack the source of the project you want to clone.  My example will use Bitcoin.

2.  Set up a build environment if you haven't already, and get the build dependencies.

3.  Go to the top directory of the source and type
 find . -type f -print0 | xargs -0 sed -i 's/bitcoin/newname/g' 

to change every instance of 'bitcoin' in the files below that directory to 'newname'.  Repeat, changing 'Bitcoin' and 'BitCoin' to 'Newname', 'BITCOIN' to 'NEWNAME', 'BTC' and 'btc' to 'NEW'.

4.  Because that affected all the files including makefiles that have other filenames in them, and a lot of the files are named 'bitcoin-somethingorother', you need to rename the files to match what's now in the makefile.  So you do that by typing
find . -type f -exec rename 's/bitcoin/newname/
to change all the filenames.

5.  
ls -r | grep -i 'bitcoin'
reveals that no other capitalization matters in the filenames.

6.
ls -r | grep -i 'btc'
will find three files in the 'resources' directory under 'qt' that used 'btc' in their filenames,
    so you need to change those to match the makefiles using
find src/qt/res/ -type f -exec rename 's/btc/NEW/
.

7. Bitcoin uses ports 8332 and 18332 on its main net and 8333 and 18333 on its testnet.  You want to change these to whatever ports you're using for the new coin, so first you type
grep -R 8332
and
grep -R 8333
to look at all the places where those numbers occur in source.  You'll find the port numbers in the source, but the strings also pop up in test vectors in the test directory, which you don't want to change.  So you need to do this in a way that leaves the test directories out of it.  But that's easy, because the places you do want to change it in source are all in the same directory.  So you type
sed -i 's/8332/newnumber1/g' src/*.cpp
and
sed -i 's/8333/newnumber2/g' src/*.cpp
, and that's done.

8. Next thing, you want to change the key prefix bytes so they don't cross up with bitcoin keys. The odds of an accidental collision are ludicrous, but 'odds' and 'accidental' are quaint oldfashioned ideas like thinking that radium suppositories are good for you when working on systems that people will actively attack.  The relevant lines in src/chainparams.cpp for mainparams look like this:
base58Prefixes[PUBKEY_ADDRESS] = list_of(number);
base58Prefixes[SCRIPT_ADDRESS] = list_of(number);
base58Prefixes[SECRET_KEY] = list_of(number);

and the ones in testparams look just like them except for different numbers. So plug in some different numbers so your keys won't be compatible with Bitcoin's system, just to eliminate the possibility of accidental key collisions.  (yes, you're already defaulting to different network ports, and keys are 'random' anyway, so confusion won't happen accidentally - but see the earlier comment about 'accidents' in systems that people will actively attack).  The four-byte sequences in the couple of lines after that are for 'stealth' addresses.   Again, it doesn't really matter what you change them to, unless you want to be cutesy and pick a particular alphanumeric prefix in the base58 representation of your keys.

9. Next up, the network magic bytes.  This is a sequence of four bytes that identify messages as belonging to some particular protocol, that get sent at the beginning of protocol messages.  You want yours to be different than everybody else's, as yet another way to make sure you don't wind up sending a message to (or getting a message from) something else.  Make up (or roll dice to find) some random bytes,  These are the
pchMessageStart[0]
through
pchMessageStart[3]
that get set at the top of CMainParams and CTestParams.  So you edit those to be your new numbers.

10. You probably don't want to show bitcoin's logos and graphics when you start up your alt, so go to the src/qt/res/ directory and change any graphics you find there that you don't want to show, to different graphics.  This is where you change logos and stuff.  I don't know good command lines for this, so you'll probably have to fire up GIMP and do them one at a time.  For now just change them for other graphics with the same size and saved in the same format.  It's a cheap trick, but if you want to do something different, you'll need to learn the qt framework and configure it to load and display something different.

11.  Use
date -+%s
at the command line to find the current time in seconds since the epoch,  add seven thousand or so to it, and plug it into all the parameters blocks replacing all the numbers that match the one that bitcoin's code sets genesis.ntime to.  You can change the
const char* pszTimestamp = 
string too, but keep it under 90 characters. Then insert this code into each of the mainparams and testparams blocks, right after the line that sets HashGenesisBlock:
if ((genesis.GetHash() != hashGenesisBlock) && true)
        {
            Logprintf("recalculating params for mainnet.\n");
            Logprintf("old mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
            Logprintf("old mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("old mainnet genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
            for(genesis.nNonce == 0; genesis.GetHash() > bnProofOfWorkLimit; genesis.nNonce++){ } // deliberately empty for loop; finds nonce value
            Logprintf("new mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
            Logprintf("new mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("new mainnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
        }

Then compile it (that's
automake; configure -with-incompabible-bdb; make
in the project's root directory) and start it up.  It'll chew for ~20 minutes to ~2 hours or so figuring out a new nonce and hash, drop them to the logfile, then hit the assert() statement right after that block and crap out immediately.  Then
tail ~/.newcoin/debug.log
will tell you the new parameters.  Plug them in where the code sets nNonce and HashGenesisBlock, recompile, rinse, and repeat for the testnet and regtest initializers.  You will probably want to
rm -rf ~/.newcoin
a few times along the way if you need to recover from any mistakes, and after you have the new parameters plugged in, change those 'true's into 'false's so that the client doesn't just start working on a new genesis block later if it follows a fake chain all the way back to a genesis block that doesn't match.  

12.  Now, still in chainparams.cpp find the line that says
static const Checkpoints::CheckpointData data = {
and delete all those bitcoin checkpoints that come after it.  replace all of them with a single checkpoint at height zero and the hash of your new genesis block.  While you're at it, be sure you have updated the CCheckpointData right after it to your new timestamp.  Also in CCheckpointData you need to set the height of the last checkpoint to zero.  If you're a completist, you'll want to do the same thing (with the new testnet values) at the line that says
static const Checkpoints::CcheckpointData dataTestnet = { 
right after it.   You'll also want to delete all those network seeds and URLs and stuff that are bitcoin-specific; you'd need to put machines up at URLs that are specific to your altcoin to replace them.  Compile one more time.

At this point you have a completely pointless altcoin. Woot.  Big effin' deal.  There are absolutely no new ideas in it.  Also, it has some user-facing strings that will direct people to wrong URLs that you'd want to fix if this were real.  If you launch this as an altcoin, it will fail.  

This is fun if you want to step through the process, mess with it, and change various parameters to see how it works. You can set up a couple machines with this program, point them at each other using the command line 'connect' and  'generate' arguments, and let them mine blocks.  But unless you are someone who has 8 hours a day to spend on supporting it for a long time, some original ideas you want to try out, some network hosting where you can put up long-lived servers to run those address services, and a full understanding of how and why these steps worked, don't mistake yourself for an altcoin dev.  

This is literally a half hour of work, a dozen or so command lines, and editing one file.  This is what coingen was charging 1 to 5 BTC for?  Man, a whole lot of people got ripped off there.
Make sure you back up your wallet regularly! Unlike a bank account, nobody can help you if you lose access to your BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714739496
Hero Member
*
Offline Offline

Posts: 1714739496

View Profile Personal Message (Offline)

Ignore
1714739496
Reply with quote  #2

1714739496
Report to moderator
1714739496
Hero Member
*
Offline Offline

Posts: 1714739496

View Profile Personal Message (Offline)

Ignore
1714739496
Reply with quote  #2

1714739496
Report to moderator
1714739496
Hero Member
*
Offline Offline

Posts: 1714739496

View Profile Personal Message (Offline)

Ignore
1714739496
Reply with quote  #2

1714739496
Report to moderator
YarkoL
Legendary
*
Offline Offline

Activity: 996
Merit: 1012


View Profile
April 10, 2015, 10:25:24 AM
 #2

This is literally a half hour of work, a dozen or so command lines, and editing one file.  This is what coingen was charging 1 to 5 BTC for?  Man, a whole lot of people got ripped off there.

Not sure, but I think those were based on
older Bitcoin source (0.8?).

What you have just done  is to give to the world a state-of-art
SHA-256 coin cloning tutorial based on most recent release.

And the world thanks you  Cheesy

“God does not play dice"
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 10, 2015, 05:54:32 PM
 #3

Anybody who knows the windows command line want to fill in with the equivalent commands?  I haven't been using MS systems for a long, long time and don't remember all that.
presstab
Legendary
*
Offline Offline

Activity: 1330
Merit: 1000


Blockchain Developer


View Profile
April 10, 2015, 06:45:48 PM
 #4

You are missing a lot of steps. Plenty of guides all over the place with the full steps though. Of course shakezulas guide is the gold standard  Cool

Projects I Contribute To: libzerocoin | Veil | PIVX | HyperStake | Crown | SaluS
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 10, 2015, 06:57:00 PM
 #5

Eh.  I was terse, and a lot of these could be expanded on I guess.  Or made a lot more specific anyway.  But, seriously, the renaming and name replacement gets you 95% of the way there.  Working out how to mine a genesis block held me up for about 20 minutes, but it's simple enough.

presstab
Legendary
*
Offline Offline

Activity: 1330
Merit: 1000


Blockchain Developer


View Profile
April 10, 2015, 07:00:47 PM
 #6

Eh.  I was terse, and a lot of these could be expanded on I guess.  Or made a lot more specific anyway.  But, seriously, the renaming and name replacement gets you 95% of the way there.  Working out how to mine a genesis block held me up for about 20 minutes, but it's simple enough.



you will also want to be replacing left over dev pubkeys, replacing seed nodes & pnseeds, versioning, genesis block generation, clear checkpoints, etc.

Sure you can create an absolute shitcoin with a few commands, but for it to function well you will need to prune the code for leftovers from the old source that won't apply to the new coin. Not too difficult if you know what to look for and where to look.

Projects I Contribute To: libzerocoin | Veil | PIVX | HyperStake | Crown | SaluS
Este Nuno
Legendary
*
Offline Offline

Activity: 826
Merit: 1000


amarha


View Profile
April 11, 2015, 08:45:54 AM
 #7

If you want one with scrypt you can fork this: https://github.com/MarkPfennig/pfennig
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 12, 2015, 07:07:57 PM
 #8

All the dev pubkeys, etc, are just if you intend to host on github.  I could just as easily explain how to set up an FTP server or a torrent feed with remote access and signature checking.  How you host things doesn't matter. 

And as for the direct clone via word replacement being an absolute shitcoin?  Well, yes.  As I said, don't mistake yourself for a Dev unless you're willing to support it 8 hours a day for a long time and have new ideas to code and know how.  Also as I said, if you launch this seek-and-replace thing as an altcoin, it will fail.  :-)

But as long as we're playing "tell me true" -- the old game where you try to make each other laugh by saying obviously true things?  I've got one.  A benevolent diety would never require us to poop anything bigger than our heads.
presstab
Legendary
*
Offline Offline

Activity: 1330
Merit: 1000


Blockchain Developer


View Profile
April 16, 2015, 10:30:04 PM
 #9

All the dev pubkeys, etc, are just if you intend to host on github.

What do alert and checkpoint keys have to do with github Huh

Projects I Contribute To: libzerocoin | Veil | PIVX | HyperStake | Crown | SaluS
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 17, 2015, 12:14:34 AM
Last edit: April 17, 2015, 12:25:11 AM by Cryddit
 #10

As far as the code is concerned, there is no such thing as a checkpoint key.  The so-called checkpoint key, as far as I know, is just the signing key that allows people to check diffs into the Github repository.  So that is just a hosting issue.  A new checkpoint is just a one-line addition to the source code, not something that the program auto-updates in response to a signed message that it has to know a key for.  Allowing a signed message to automagically add a checkpoint to running clients is interesting - and a fairly straightforward hack - but is probably a bad idea.

With that mechanism the dev could send out a new checkpoint at any time.  The good news is that it would be a way to resolve forks or "unstick" a stuck block chain by checkpointing one of the competing branches or the last orphan block prior to whatever it got stuck on.  The bad news is that it would give the dev power to undo any transaction on demand by rolling back the block chain.  All he'd have to do would be mine one block based on the block before the tx he wants to undo, with a tx spending at least one of its inputs. Then publish the "new" block and checkpoint it.  Suddenly the block chain containing the other tx, even if now many blocks longer, is invalid.  Poof, the dev has the power to double spend.  And if he undoes a bunch of blocks this way, everybody else who's spent something they want to "unspend" would get at least a chance to do the same.

You do have a point about the alert key though - and unless you want to gift your coinbase txOut to the "Spirit of Satoshi" you'll want to generate a coinbase txOut key as well.  

Code:
openssl ecparam -genpkey -name secp256k1 -out key.pem

will drop a public/private keypair in the file key.pem.  

The public key in that file is in hex format, with a semicolon between bytes.  Strip the semicolons and linefeeds out of it, and you can paste it directly in as the vAlertPubKey (still in chainparams.cpp).  That makes the private key of the pair the one you need to sign alerts to send out to the whole network.  So save that private key somewhere you won't lose it.  

Next the coinbase key.  

You can repeat the command line above to generate another key pair, then strip the semicolons and linefeeds out of THAT public key, go to the initializer for CMainParams and replace the key in the "txNew.vOut[0].scriptPubKey with the hexadecimal string for the new public key.  

Then the corresponding private key would be the one you need to spend the coinbase transaaction.  The coinbase transaction won't appear in any wallet by default, because no wallets exist yet at the time the transaction gets created.  So if you ever want to spend the coinbase, you have to keep that private key.  Convert it into base58check format, and you'll have a key you can later import into your wallet.

Converting into base58check is annoying, but do-able.  Rather than explain it, I'm going to point at https://en.bitcoin.it/wiki/Base58Check_encoding.  Keep in mind that your keys use a different version byte than the Bitcoin keys though.

That means you changed the coinbase transaction though, so you'll have changed the Merkle root of the genesis block, so your hashes (for mainnet and testnet) won't be valid any more.  

To fix this, you'll need to do

Code:
 rm -rf ~/.newcoin/ 

Then mine the genesis blocks again.  


Man, this is getting to be more than twelve steps, isn't it?  Maybe I'll need to do a full-on guide.

presstab
Legendary
*
Offline Offline

Activity: 1330
Merit: 1000


Blockchain Developer


View Profile
April 17, 2015, 01:40:12 AM
Last edit: April 17, 2015, 03:13:21 AM by presstab
 #11

As far as the code is concerned, there is no such thing as a checkpoint key.  The so-called checkpoint key, as far as I know, is just the signing key that allows people to check diffs into the Github repository.


There is not a checkpoint key for bitcoin, but for almost all altcoins there are (remember that pretty much no altcoins are cloned from btc at this point in time). This is something that descends from PPC (as far as i know) and is in fact commonly used...
https://github.com/ppcoin/ppcoin/blob/master/src/checkpoints.cpp#L370

Bitcoin does have an alert key https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L121 but not the checkpoint key




Projects I Contribute To: libzerocoin | Veil | PIVX | HyperStake | Crown | SaluS
YarkoL
Legendary
*
Offline Offline

Activity: 996
Merit: 1012


View Profile
April 17, 2015, 04:50:09 AM
Last edit: April 17, 2015, 06:35:25 AM by YarkoL
 #12


You do have a point about the alert key though - and unless you want to gift your coinbase txOut to the "Spirit of Satoshi" you'll want to generate a coinbase txOut key as well.  

Heh. Poor Spirit of Satoshi usually gets amount  0 in the genesis. Plus txfee.

 

Man, this is getting to be more than twelve steps, isn't it?  Maybe I'll need to do a full-on guide.

You could make it into something that teaches the
theory and purpose behind these operations as well.

“God does not play dice"
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 17, 2015, 08:34:30 PM
 #13

There is not a checkpoint key for bitcoin, but for almost all altcoins there are (remember that pretty much no altcoins are cloned from btc at this point in time). This is something that descends from PPC (as far as i know) and is in fact commonly used...
https://github.com/ppcoin/ppcoin/blob/master/src/checkpoints.cpp#L370

Huh.  So people are doing exactly that.  I think I'm going to stick with my initial assessment and call it a bad idea.  Handy, but now the dev can screw everybody over. 

You know what a "trusted" entity is, don't you?  It means one that can wreck your security. 


Heh. Poor Spirit of Satoshi usually gets amount  0 in the genesis. Plus txfee.

People know the genesis block output of bitcoin is unspendable, but they still send bits to that address - sort of like a religious observance or a symbolic act.  So yes, people make offerings to the Spirit of Satoshi.  Here, go look:

https://blockchain.info/address/1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

And I seem to recall several altcoin developers who mentioned that they were leaving their genesis blocks unspendable, for the same reason - to give an acknowledgement of sorts. 

You could make it into something that teaches the
theory and purpose behind these operations as well.

Hum.  You know what, I probably should.  It would be a good series of blog articles for the cryptocurrency-101 thing.

YarkoL
Legendary
*
Offline Offline

Activity: 996
Merit: 1012


View Profile
April 17, 2015, 09:02:56 PM
 #14


People know the genesis block output of bitcoin is unspendable, but they still send bits to that address - sort of like a religious observance or a symbolic act.  So yes, people make offerings to the Spirit of Satoshi.

I know, I've observed this ritual many times myself.
To quote the patron saint of us lowly altcoin devs, St. Shakezula:

Quote
I leave them to cyber space as a token of good karma to the bit gods at the church of development

http://devtome.com/doku.php?id=scrypt_altcoin_cloning_guide


“God does not play dice"
muddafudda
Legendary
*
Offline Offline

Activity: 1008
Merit: 1022



View Profile
April 19, 2015, 11:52:33 AM
 #15

www.howtocloneanaltcoin.com I find more easier to follow and its windows also
Bizmark13
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


WikiScams.org - Information about Bitcoin Scams


View Profile
April 22, 2015, 02:43:55 AM
 #16

Aren't most altcoins forked from Litecoin nowadays rather than Bitcoin? OP's tutorial could probably be useful for someone who just wants to learn the basic ideas behind forking a coin but an equivalent tutorial for Litecoin might be more useful for most people.


Heh. Poor Spirit of Satoshi usually gets amount  0 in the genesis. Plus txfee.

People know the genesis block output of bitcoin is unspendable, but they still send bits to that address - sort of like a religious observance or a symbolic act.  So yes, people make offerings to the Spirit of Satoshi.  Here, go look:

https://blockchain.info/address/1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

My understanding is that the initial 50 BTC block reward cannot be spent but those donations which other people have sent to the genesis block which now total ~15 BTC are, in fact, spendable.
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 22, 2015, 02:56:32 AM
 #17

I think you're right about that.  Assuming the key for that coinbase transaction was saved, the key corresponding to the original coinbase could be used to spend any of the tx that have sent money to it.

That key can't automatically wind up in a wallet the way other mining keys do, because no wallet exists yet at the time the coinbase tx is created.  So you'd have to have planned ahead and taken a few fancy steps to even have that key.

For people who are interested in making altcoin, I've taken the original topic here and made a more serious treatment of it on another thread:  https://bitcointalk.org/index.php?topic=1030365.0
Este Nuno
Legendary
*
Offline Offline

Activity: 826
Merit: 1000


amarha


View Profile
April 22, 2015, 07:23:14 AM
 #18

Aren't most altcoins forked from Litecoin nowadays rather than Bitcoin? OP's tutorial could probably be useful for someone who just wants to learn the basic ideas behind forking a coin but an equivalent tutorial for Litecoin might be more useful for most people.


No one should be forking from Litecoin in 2015. Or 2014 for that matter, but I'd give them a pass since it was so common in 2013 and before.
Cryddit (OP)
Legendary
*
Offline Offline

Activity: 924
Merit: 1129


View Profile
April 22, 2015, 05:38:08 PM
 #19

Anyway, what I've got above is mostly applicable to whatever codebase you're forking from, assuming it is ultimately something that originated with a bitcoin fork.  You may have to find the respective functions living in different files with earlier versions, or they may be slightly differently structured, but adapting things is pretty straightforward.

And I haven't kept up with Litecoin; aren't they lagging behind Bitcoin in features these days?  Did stealth addresses, deterministic wallets, etc, ever make it into Litecoin? 
Este Nuno
Legendary
*
Offline Offline

Activity: 826
Merit: 1000


amarha


View Profile
April 22, 2015, 09:25:08 PM
 #20

Anyway, what I've got above is mostly applicable to whatever codebase you're forking from, assuming it is ultimately something that originated with a bitcoin fork.  You may have to find the respective functions living in different files with earlier versions, or they may be slightly differently structured, but adapting things is pretty straightforward.

And I haven't kept up with Litecoin; aren't they lagging behind Bitcoin in features these days?  Did stealth addresses, deterministic wallets, etc, ever make it into Litecoin? 

I believe there is an adaptation of Electrum for Litecoin, so yes for deterministic wallet.
Pages: [1] 2 »  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!