Everybody nowadays talks about the blockchain and how it could empower a new and incredible range of applications. But what it's stored inside a block and what is suitable for?
What is worth to store in and what is better to store outside?
In this webinar, we will take a look at Bitcoin and Ethereum blockchains, and read some blocks and transactions using a mix open-source libraries and web-based explorers.
Discover more at http://blog.zigolab.it
1. THROUGH THE LOOKING GLASS
(OF THE BLOCKCHAIN)
May 29th 2018
A l e s s a n d r o C o n f e t t i
2. 2
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
3. 3
• What it is stored inside a block
and what is suitable for?
• What is worth to store inside
and what is better to store outside?
Alessandro Confetti - May 29th 2018 – Codemotion Free Webinar - Through the looking glass (of the blockchain)
4. 4
Image from Julia Donaldson's books – in pictures
THERE IS NO
SUCH A THING AS
A BLOCKCHAIN
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
5. 5
Bitcoin's Academic Pedigree
By Arvind Narayanan, Jeremy Clark
Communications of the ACM, Vol. 60 No. 12,
Pages 36-45
10.1145/3132259Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
7. 7
Ok, I need a blockchain, but which one?
By Pavel Kravchenko Sep 26, 2016
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
10. BITCOIN TRANSACTION
10Ken Shirriff Bitcoins the hard way: Using the raw Bitcoin protocol
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
11. 11
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
12. 12
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
13. HOW TO INSTALL BITCOIN
13
git clone https://github.com/bitcoin/bitcoin.git
# See doc/build-*.md for instructions on building for your o.s.
./autogen.sh
./configure
make
make check
make deploy
# to explore the blockchain, use the following commands
./src/bitcoin-cli getblockhash <block height>
./src/bitcoin-cli getblock <block hash>
./src/bitcoin-cli getrawtransaction <transaction hash>
./src/bitcoin-cli decoderawtransaction <raw transaction>
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
14. BITCOIN-CLI EXAMPLES
14
# genesis block
$ bitcoin-cli getblockhash 1
$ bitcoin-cli getblock 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048
$ bitcoin-cli getrawtransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098
$ bitcoin-cli decoderawtransaction <the output from the above command>
# more complex block
$ bitcoin-cli getblock 0000000000000001b6b9a13b095e96db41c4a928b97ef2d944a9b31b2cc7bdc4
# Alice bought a cup of coffee from Bob’s Cafe (example from "Mastering Bitcoin 2nd edition")
$ bitcoin-cli getrawtransaction 0627052b6f28912f2703066a912ea577f2ce4da4caa5a5fbd8a57286c345c2f2
$bitcoin-cli decoderawtransaction <the output from the above command>
# Colored Coins (Open Assets)
$ bitcoin-cli getrawtransaction 10d7c4e022f35288779be6713471151ede967caaa39eecd35296aa36d9c109ec
$ bitcoin-cli decoderawtransaction <the output from the above command>
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
15. BITCOIN BLOCK HEADER
15
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
Courtesy of bicoinwiki
19. ETHEREUM STATE TRANSITION FUNCTION
19Ethereum Wiki
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
22. HOW TO INSTALL ETHEREUM
22
wget https://gethstore.blob.core.windows.net/builds/geth-darwin-amd64-1.6.0-
facc47cb.tar.gz
tar -xvfz geth-darwin-amd64-1.6.0-facc47cb.tar.gz
sudo mv geth-darwin-amd64-1.6.0-facc47cb/geth /usr/local/bin/geth
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
23. ETHEREUM RECURSIVE LENGTH PREFIX (RLP)
23
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
Ethereum Wiki
• For a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding.
• Otherwise, if a string is 0-55 bytes long, the RLP encoding consists of a single byte with value 0x80
plus the length of the string followed by the string. The range of the first byte is thus [0x80, 0xb7].
• If a string is more than 55 bytes long, the RLP encoding consists of a single byte with value 0xb7
plus the length in bytes of the length of the string in binary form, followed by the length of the
string, followed by the string. For example, a length-1024 string would be encoded as xb9x04x00
followed by the string. The range of the first byte is thus [0xb8, 0xbf].
• If the total payload of a list (i.e. the combined length of all its items being RLP encoded) is 0-55
bytes long, the RLP encoding consists of a single byte with value 0xc0 plus the length of the list
followed by the concatenation of the RLP encodings of the items. The range of the first byte is thus
[0xc0, 0xf7].
• If the total payload of a list is more than 55 bytes long, the RLP encoding consists of a single byte
with value 0xf7 plus the length in bytes of the length of the payload in binary form, followed by the
length of the payload, followed by the concatenation of the RLP encodings of the items. The range
of the first byte is thus [0xf8, 0xff].
24. ETHEREUM BLOCK HEADER
24
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
Ethereum Yellow Paper
parentHash: TheKeccak256-bithashoftheparent block’s header, in its entirety
ommersHash The Keccak 256-bit hash of the om- mers list portion of this block
beneficiary The 160-bit address to which all fees collected from the successful mining of this block be transferred
stateRoot The Keccak 256-bit hash of the root node of the state trie, after all transactions are executed and finalisations applied
transactionsRoot The Keccak 256-bit hash of the root node of the trie structure populated with each transaction in the transactions list
portion of the block
receiptsRoot The Keccak 256-bit hash of the root node of the trie structure populated with the re- ceipts of each transaction in the
transactions list portion of the block
logsBloom The Bloom filter composed from index- able information (logger address and log topics) contained in each log entry from
the receipt of each transaction in the transactions list
difficulty A scalar value corresponding to the dif- ficulty level of this block. This can be calculated from the previous block’s difficulty
level and the timestamp
number A scalar value equal to the number of an- cestor blocks. The genesis block has a number of zero
gasLimit A scalar value equal to the current limit of gas expenditure per block
gasUsed A scalar value equal to the total gas used in transactions in this block
timestamp A scalar value equal to the reasonable output of Unix’s time() at this block’s inception
extraData An arbitrary byte array containing data relevant to this block. This must be 32 bytes or fewer
mixHash A 256-bit hash which, combined with the nonce, proves that a sufficient amount of computation has been carried out on
this block
nonce A64-bitvaluewhich,combinedwiththemix- hash, proves that a sufficient amount of computa- tion has been carried out on
this block
26. ETHEREUM TRANSACTION
26
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
Ethereum Yellow Paper
nonce A scalar value equal to the number of trans- actions sent by the sender
gasPrice A scalar value equal to the number of Wei to be paid per unit of gas for all computation costs incurred as a result of the
execution of this transaction
gasLimit A scalar value equal to the maximum amount of gas that should be used in executing this transaction. This is paid up-
front, before any computation is done and may not be increased later
to The 160-bit address of the message call’s recipi- ent or, for a contract creation transaction, ∅, used here to denote the
only member of B0
value A scalar value equal to the number of Wei to be transferred to the message call’s recipient or, in the case of contract
creation, as an endowment to the newly created account
v, r, s Values corresponding to the signature of the transaction and used to determine the sender of the transaction
Contract creation only
Init An unlimited size byte array specifying the EVM-code for the account initialisation procedure
Message call only
data An unlimited size byte array specifying the input data of the message call
Transaction Receipt
gasUsed cumulative gas used in the block containing the transaction receipt as of immediately after the transaction has happened
logs set of logs created through execution of the transaction; each log is a list made of: logger’s address, a series of 32-byte
log topics and some number of bytes of data
logsBloom Bloom filter composed from information in those logs
statusCode the status code of the transaction
27. BTC & ETH BLOCKCHAIN STATS
27
StopAndDecrypt The Ethereum-blockchain size has exceeded 1TB, and yes, it’s an issue
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
bitinfocharts.com
28. SO YOU WANT TO USE A BLOCKCHAIN…
28
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)
Who can set or change the rules of the protocol?
Who runs the nodes and pay for them?
Who validates the block and at which cost?
Who can read and/or write the blocks?
29. 29Courtesy of Wired
Alessandro Confetti - May 29th 2018 – Codemotion Webinar - Through the looking glass (of the blockchain)