1
LET’S TEARDOWN
BITCOIN’S CODE
By BellajBadr
Mchain CTO
www.Mchain.uk
2
.... Not Satoshi Nakamato
……….
“
”
WHO AM I
▪ @bellajbadr
▪ /bellaj
Neither am
I
www.Mchain.uk
The so called Plan 3
1- Meet Bitcoin & Blockchain
2- Create Devoxx coin
4
>># Meet Bitcoin & Blockchain
www.Mchain.uk
5
• Scam 
• A way to get rich ☺
What’s Bitcoin
www.Mchain.uk
6
The #Bitcoin price history put through a sound
generator.
@Xentagz
www.Mchain.uk
• Bitcoin is a protocol
• Digital Cash system
What’s Bitcoin 7
https://en.bitcoin.it/wiki/Protocol_documentation
www.Mchain.uk
8
How to create an unstoppable
digital currency !?
Bitcoin is a technical solution for a complex
problem
www.Mchain.uk
9
https://bitcoin.org/bitcoin.pdf
www.Mchain.uk
10
Bitcoin digitized the trust
over internet without
relying on third parties.
DATA DIFFUSION
DATA STORAGE
CONSENSUS
SCRIPTING &
SMART CONTRACT
Bitcoin/
Blockchain
Stack
Blockchain is an immutable registry, once a transaction is logged it becomes tamper-proof
(virtually impossible to delete or modify the data.) As the blocks (transaction groups) are
interconnected cryptographically.
Chain of blocks
© 2017 MCHAIN
● The "trusted third party" becomes the system itself.
Confiance établie
Alice BoB
intermédiaires
Consensus
Badr
N5545 N5546
Block validated by the network
- and added in the blockchain
(updated)
TX+Signature
Cryptographically sign
the transaction and send
it to the network
ADDRESS:
1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
Transaction validated
N5547
Tx is checked and included
in a block (time window)
TXj+Signature
TXi+Signature
N5547
How transaction get proceeded?
16
Mining
17https://bitnodes.earn.com/
18
>># Run Bitcoin
www.Mchain.uk
Bitcoin Clients/Implementations 19
Electrum
www.Mchain.uk
Build Bitcoin Core 20
www.Mchain.uk
Localhost Env
Regtest Mode
21
A local testing environment in
which developers can almost
instantly generate blocks on
demand for testing events, and
can create private satoshis with
no real-world value. There are
two other options : Mainnet
and Testnet.
>> bitcoind –regtest // or define bitcon.conf
>> bitcoin-cli getnewaddress //new address
>> bitcoin-cli generate 101
>> bitcoin-cli listunspent
www.Mchain.uk
22
bitcoin-cli createrawtransaction
'''[{"txid":"6f8bc5dae48985d077017e715d5624b3fd8048004520b57917be4975341b76ff", "vout": 0}]'''
'{"data":"68656c6c6f20776f726c64","2N4yckESDaEMHTuAHattVo4FxQHe8MKiso9":49.92000000}'
}’
bitcoin-cli signrawtransactionwithwallet
bitcoin-cli sendrawtransaction
bitcoin-cli -regtest generate 1
Localhost Env
Regtest Mode/ OP_RETURN
www.Mchain.uk
Dissect Block
Hello world
23
FA BF B5 DA
https://en.bitcoin.it/wiki/Data_directory
www.Mchain.uk
24
Bitcoin’s Block Structure
25
>># Run DEVOXX Coin
www.Mchain.uk
26
Token/Colored Coin
D
Bitcoin/
Altcoin
Fork
From scratch
Devoxx Coin
27
Devoxx Coin Design
Coin’s Name DevoxxCoin
Coin’s Symbol DEC
Block Time 2.5 minutes
Initial block reward 10
Halving interval Every 100000 blocks (174 days)
Ports RPC port: 19333
P2P port: 9333
Total supply 2 000 000 units
Difficulty readjustment After 576 blocks
Block size Up to 8 Mb
D
In live demos
nothing goes
as expected
28
Show me the code
29
Version to choose => changelog -https://bitcoin.org/en/version-history-
find . -exec rename ‘s/*/*/' {} ";"
find ./ -type f -readable -writable -exec sed -i "s/*/*/g" {} ";“
>> grep –ri to check
Rebranding
30
Removing the seed nodes
You can include your properDNS seeds servers.In chainparamseeds.h
31
Changing
pchMessageStart
32
Checkpoints
33
ChainTxData
The chaintxdata represents the blockchain state at a specific timestamp using
data of a specific block.
34
Halving
For Bitcoin the mining reward is cut in half every 210,000 blocks, which will
occur approximately every 4 years.
174 days (1/2y)
35
Rewarding
In src/validation.cpp you'll find a parameter called nSubsidy in the
GetBlockSubsidy function which defines the initial value of the reward.
36
Genesis block
A genesis block is the first block in a blockchain. When a node boots, it initializes its copy
of the blockchain alongside the genesis block and then begins the synchronization
process.
New pszTimestamp
New nonce, epoch time, and nbits
genesis = CreateGenesisBlock(time, nonce, bits, 1,
10 * COIN);
assert (hashGenesisBlock == uint256 ("genesis
block hash"));
Editing the Merkle root
In testparams.cpp change:
assert( genesis.hashMerkleRoot ==
uint256s('merkle hash value');
37
Total supply
Bitcoin is designed in a such manner so it has a total circulation of
approximately 21 million bitcoins (20,999,999.9769 bitcoins). TS depends on
Halving, initial reward and Block time.
In the header file amount.h there is a total supply MAX_MONEY sanity check:
As per our design we will set MAX_MONEY to 20,000,000 (rounded number) //
1999999.987 in our case
38
POW parameters: target
Each hash basically gives a random number between 0 and the maximum
value of a 256-bit number (which is huge). If the miner's hash is below the
given target (a special hash value) then he wins. If not, he increments the
nonce (completely changing the hash) and tries again.
39
40
19 leading Zeros
41
Max Difficulty (Difficulty of 1):
Difficulty = original_target / target
If diff= 6653303141405 it's currently 6,653,303,141,405 times more difficult to
mine a block
42
New block time : Difficulty adjustment time
interval ( retargeting period)
In Bitcoin after each 2016 blocks (14 days worth of blocks), each node looks at the time stamps of the past 2015
blocks and adjusts the difficulty using the following function defined in src/consensus/params.h
Both parameters nPowTargetTimespan and nPowTargetSpacing are defined in chainparams.cpp where we will set the
new following values to keep block generation at 2.5 minutes (retargeting 24 H):
43
This specifies the minimum amount of chain work that a client must have
before it will consider itself synchronized. As we are running a new chain, the
minimum should be zero for both testnet and mainnet:
Minimum amount of chain work
45
Time maturity
The coinbase maturity indicator indicates a time window of 100 blocks
between the creating block and the spending block. For ReaderCoin we
decrease this limit from 100 to 50. In the src/consensus/consensus.h file we
edit the following line of code:
46
Block size
After Segwit activation, the weight parameters have been defined in consensus.h:
To double the weight we have to double the values of these four parameters.
47
BIPs : Bitcoin Improvement Proposals
BIPs as a way to introduce new features to the Bitcoin protocol. Each new
improvement (BIP) is activated at a future block height to give Bitcoin users time
to update their software
48
Compiling and testing
./autogen.sh
./configure--with-gui=qt5 --enable-
debug--disable-tests
make && sudo make install
devoxxcoin-qt -printtoconsole
readercoin-cli addnode 192.168.1.3:9333onetry
(in nodeA)
readercoin-cli addnode 192.168.1.8:9333onetry
(in nodeB)
devoxxcoin-cli getpeerinfo
Maybe run 2 node same pc
49
GUI
Define your own Logo/Icon and Splash screen.
The resource files corresponding to different dialogue forms are editable files
with .ui extensions and are located under src/qt/forms
50
Mining
In 0.16 version bitcoin client doesn’t have an internal miner. We use therefore
CPUminer :
./minerd -o http://127.0.0.1:9332 -u user -p password -a sha256d --nolongpoll --
no-getwork --no-stratum --coinbase-addr=your_address
www.Mchain.uk
To learn More 51
www.Mchain.uk
52
53
Q/A

create your own cryptocurrency