Crypto-notes
Bitcoin, Ethereum, Cardano, NEO, etc.
- A system for securely transmitting and storing value
(whitepaper)
- Reference implementation (first
version)
- People often think of Bitcoin as only virtual money or a transaction system.
But if you look closer, you’ll see that the monetary aspect is just the tip
of the iceberg. Money is merely one of the possible applications.
- PGP was the first
major iteration of applied cryptography and Bitcoin the second. The
interaction and integration of crypto into the very fabric of a decentralized
web will be the refined third implementation.
- Intend to support numerous advanced features, including
- Smart Contracts: decentralized logic, or distributed stored-procedures
- Executable programs that run on top of an immutable distributed database
whose inputs and outputs are maintained globally consistent by a
distributed consensus
protocol.
- A contract is like an autonomous agent that runs a certain piece of code
every time a transaction is sent to it, and this code can modify the
contract’s internal data storage or send transactions. Advanced contracts
can even modify their own code.
- Contracts run on a blockchain, which is a specific minimal implementation
of a distributed database with certain properties that are amenable to the
creation of so-called cryptocurrencies.
- Stephen Diehl
wrote:
- Basically a Contract is a Smalltalk object that allows message passing
through transactions on a blockchain. The code is deployed by it’s owner
and then anyone on the network can interact it with it by message passing
which may result in data or state changes on the global network. The
execution occurs on the ‘miners’ on the network who execute the contract
code with the inputs and outputs specified in the transaction and compute
a solution to a RAM-hard SHA inversion problem called Ethash which adds
the new block to the chain and updates the global state of contract
network. Whichever miner solves the problem first gets to append the
newly hashed block and the process continues ad-infinitum with the global
network converging on consensus.
From a programming language perspective this introduces the non-trivial
constraint that programs must necessarily terminate. The current
implementation accomplishes this by attaching a cost semantics to each
opcode in the virtual machine that expends a finite resource called ‘gas’
that is a function of the current block.
- Smart Contracts
Topology (Adjoint
Blog)
- In 1997, Nick Szabo came out
with the idea of Smart Contracts. He gave a definition of Smart Contracts
based on a simple idea:
- Smart Contract: A set of promises, including protocols within which the
parties perform on the other promises. The protocols are usually
implemented with programs on a computer network, or in other forms of
digital electronics, thus these contracts are “smarter” than their
paper-based ancestors.
- In simple terms, a Smart Contract is a program that captures all the
obligations of legal contracts and executes them automatically if
predetermined events occur. Smart Contracts have then no vocation to
replace existing legal contracts, but simply make their executions much
more efficient.
- Swarm: decentralized storage
- When imagining Ethereum as a metaphor for a
shared computer, it should be noted that computation alone is not enough.
For a computer to be fully useful, it also needs storage to “remember”
things and bandwidth to “communicate” them.
- More specifically, Swarm is being designed as an accounting protocol that
benefits from the automatic execution of so-called “Smart Contracts”
running on the Ethereum Virtual Machine
(EVM).
This accounting protocol is independent of the physical storage mechanism.
That is, it is not intrinsically tied to a specific storage system. It
could be IPFS,
BitTorrent, or some future technology not yet
invented.
- Whisper: decentralized messaging
- DApp is an abbreviated form for
decentralized application.
- A DApp has its backend code running on a decentralized peer-to-peer
network. Contrast this with an app where the backend code is running on
centralized servers.
- A DApp can have frontend code and user interfaces written in any language
(just like an app) that can make calls to its backend. Furthermore, its
frontend can be hosted on decentralized storage such as Swarm or IPFS.
- If an App = frontend + server, since Ethereum contracts are code that runs
on the global Ethereum decentralized peer-to-peer network, then:
- DApp = frontend + contracts
- This effort will also allow replacement of typical content delivery networks
(CDN) with a
distributed hash table
(DHT) pointing to
file blobs, much like how BitTorrent works.
Hash function
Merkle tree
- Definition
- Reference implementation
(Adjoint)
- Binary trees of hashed data
- Constructed from the leaves up
- Leaves are usually network
transactions
- If one leaf changes, the root will too
- A way of hashing a large number of “chunks” of data together which relies on
splitting the chunks into buckets, where each bucket contains only a few
chunks, then taking the hash of each bucket and repeating the same process,
continuing to do so until the total number of hashes remaining becomes only
one: the root hash.
- The benefit of this strange kind of hashing algorithm is that it allows for a
neat mechanism known as Merkle proofs
(definition)
- They tell us whether a piece of data belongs to a Merkle tree or not
- Why is it (Merkle proofs) an ideal Proof of Work
algorithm?
- Consists of a chunk, the root hash of the tree, and the “branch” consisting
of all of the hashes going up along the path from the chunk to the root.
Someone reading the proof can verify that the hashing, at least for that
branch, is consistent going all the way up the tree, and therefore that the
given chunk actually is at that position in the tree.
- The Bitcoin blockchain uses Merkle proofs in order to store the
transactions in every block.
Finite field
- Definition
- A finite set of positive integers on which multiplication, division, and
subtraction are defined and done with a modulus.
- Fπ = { 0, 1, 2, 3, 4, 5, 6 } (7 elements)
- gn = 3 (a generator)
- 1 + 5 = 6
- 2 + 6 = 1
- 4 * 1 = 4
- 3 * 4 = 12 % 7 = 5 (7, because we have 7 elements)
- Watch this talk by Thomas Dietert
Elliptic-curve cryptography
- Definition
- y2 = χ3 + αχ + β
- (χ, y) ∋ Fπ
- Secp256k1
- Elliptic Curve Digital Signature Algorithm (ECDSA)
- Definition
- a pair of algorithms used to sign and verify a piece of data using ECC
- Sign
- is to combine an ECC private key and the hashed data to produce a pair of
integers (from which the private key cannot be derived)
- Verify
- is to mathematically prove, using the public key of the signer, that the
signature was produced using the data and private key
- Cryptonite (Haskell
library)
Blockchain
- A distributed public ledger which securely records and facilitates
irreversible peer-to-peer transactions which cannot be easily amended.
- A replicated finite-state
machine maintaining a
cryptographically verifiable immutable history of transactions.
- A monotonically increasing chain of blocks in which subsequent blocks are
verified based on the data of the preceding blocks in the chain.
- Constructed by forcing every block to
contain a hash of the previous block’s
header in its header
- A transaction database shared by all nodes participating in a system based on
the Bitcoin protocol. A full copy of a currency’s block chain contains every
transaction ever executed in the currency. With this information, one can
find out how much value belonged to each
address at any point in history.
- Every block contains a hash of the previous block. This has the effect of
creating a chain of blocks from the genesis
block to the current block. Each
block is guaranteed to come after the previous block chronologically because
the previous block’s hash would otherwise not be known. Each block is also
computationally impractical to modify once it has been in the chain for a
while because every block after it would also have to be regenerated. These
properties are what make Bitcoin transactions irreversible. The blockchain is
the main innovation of Bitcoin.
- A blockchain is a very simplistic database that is an append-only immutable
store that can be written to by a collection of agents who sign their
transactions and engage in confirming other agents’ transactions through a
distributed consensus protocol based on cryptographic hashing.
- The blockchain is a specialized use case rather than a complete divergence
from traditional database technology.
- Do you need a
blockchain?
(Adjoint Blog)
- A blockchain is an immutable distributed ledger of verified transactions. In
basic terms, it is a distributed database of verified transactions that is
replicated along a network of participants, called nodes, making it secure,
efficient and transparent.
- Transactions, in order to be added to a blockchain, will be filled into a
block. The block will contain all the transactions’ details along with the
unique signatures of the parties involved and a link to the transactions
already in the blockchain (linking all the previous and current blocks
together - making the database immutable).
- Before being added to the chain, the block needs to be validated through a
cryptographic signing of transactions and a consensus protocol often built
on hashing of these blocks. Once validated, this block will be added to the
other blocks and replicated along the nodes of the distributed database.
- A blockchain is only one among different types of distributed ledgers.
- A blockchain is a magic computer that anyone can upload programs to and leave
the programs to self-execute, where the current and all previous states of
every program are always publicly visible, and which carries a very strong
cryptoeconomically secured guarantee that programs running on the chain will
continue to execute in exactly the way that the blockchain protocol
specifies.
- the fact that it’s “cryptoeconomic”, a technical term roughly meaning: it’s
decentralized, it uses public key cryptography for authentication, and it
uses economic incentives to ensure that it keeps going and doesn’t go back
in time or incur any other glitch
- Consensus process - the process for determining what blocks get added to
the chain and what the current state is. Or how to create trust between
parties with different incentives. Or how to reach an agreement in a
distributed system
- rules that dictate how the different agents in a distributed ledger
authenticate and validate the transactions added to it in order to prevent
different versions of the ledger from being created or previous
transactions from being edited
- Bitcoin uses Proof-of-Work. But
the landscape of consensus is evolving fast. Some of the currently used
consensus mechanisms are
Proof-of-Stake,
Proof-of-Authority,
Raft Consensus and Federated
Consensus.
- the consensus mechanism used by Stellar is a
decentralized version of the Practical Byzantine Fault Tolerance
(PBFT)
called Stellar Consensus
Protocol,
whereas Ripple uses probabilistic
voting.
- Proof-of-Work - a difficult solution to find but easy to verify.
- In order to validate a block of transactions, several nodes of the
distributed ledger (called Miners)
compete to solve a complicated mathematical problem. The principle is
that the solution of the problem is hard to find, but easy to verify by
the rest of the network. Once the first Miner has found the solution, it
provides the other nodes with the solution. The solution is then verified
and the consensus is reached.
- Time consuming
- Energy consuming
- The 51% attack:
since it is time and energy consuming to validate the transactions, some
Miners have decided to create Mining pools (pools where Miners share
their resources) to get more efficient and generate cost savings.
- Proof-of-Stake - the higher the stake of a validating node in the
network, the more chances and legitimacy it has to validate transactions.
- Validators of transactions are called Minters. Each Minter will commit
some of the stake it owns in the network (to simplify, they “deposit”
some cryptocurrency as a sort of collateral). Then, an algorithm will
select one of the Minters based on the stake they own. In basic terms, if
a node has a 5% stake, it will validate 5% of the transactions. It is
then easy for the other nodes to verify that transactions have been
validated by Minters that effectively have corresponding stakes in the
distributed ledger.
- Raft - validation through randomly won elections
- based on a randomly won election that will designate a Leader in charge
of the validation of the transactions.
- Federated - blocks are validated if signed by a specified quorum of
signers
- define an “M-of-N
multisignature” rule, with M
representing the number of signatures needed for a transaction to be
valid and N the number of validators (signers). Then, as long as less
than 2M - N - 1 block signers don’t violate the protocol, the consensus
is considered as secure
- Most of these consensus mechanisms are built on hashing the transactions
- See also https://anders.com/blockchain/
- Transactions
- A transaction is a transfer of Bitcoin value that is broadcast to the
network and collected into blocks. A transaction typically references
previous transaction outputs as new transaction inputs and dedicates all
input Bitcoin values to new outputs. Transactions may not be encrypted,
so it is possible to browse and view every transaction ever collected into
a block. Once transactions are buried under enough confirmations they can
be considered irreversible.
- Standard transaction outputs nominate addresses, and the redemption of any
future inputs requires a relevant signature.
- All transactions are visible in the blockchain, and can be viewed with a
hex editor
- Address
- A unique Base58 encoded value
representing a public key of a node in the network
- Maps a hash of binary encoded ECDSA
public key to a unique, irreversible identity that uniquely defines a
participant in the network
- A data structure representing a single atomic modification to the ledger
with some extra data to prove validity
- An atomic ledger state modification
- In order to be signed by the issuer they must first be converted to a
string of bytes
(serialization)
- Header
- Denotes the type of transaction
- Sender key (public key of the issuer)
- Recipient (the address to transfer)
- Amount (the amount to transfer)
- Signature (the issuer’s serialized ECC
signature of the header)
- Blocks
- A list of ordered transactions with some extra data to prove validity
- Simply ordered lists of transactions, plus a few other things to help us
validate their integrity
- Index (block height)
- Header
- Origin (public key of block miner)
- Previous hash (previous block hash)
- Merkle root (Merkle tree root representing all block transactions)
- Nonce (nonce for proof of work)
- Transactions (list of TXs)
- Signature (block signature)
- Hashing
- Validation
- current (ledger) state + previous block + current block
- Distributed Ledger
- Stateful in-memory representation of all Transactions that happened
- A mapping of Addresses to
Balances
- The datatype that reflects the culmination of Blocks
- Ordered list of Blocks
- Blocks encapsulate an ordered list of transactions
- Transactions are atomic stateful ledger updates
- The state resulting from the ordered, sequential application of all
Transactions in all Blocks
- Common operations
- Look up Balance of an Address
- Add Balance
- Add Address
- Transfer
- Distributed system
- Network of computers that run instances of the same program
- Each instance interacts with one another through a messaging protocol
- Networking
Credits, References