BTC Slides
BTC Slides
Introduction
by
Marek
The network has not experienced a single outage since the inception.
At the time of writing this handout, there are a couple of thousands
Bitcoin nodes operating worldwide, which makes the network reliable
and robust. These nodes are run by volunteers since Bitcoin has no
authority. Besides having no outage, there has been no successful
attack on the Bitcoin blockchain that would deprive the owner of the
funds they possess.
A user generates a key pair on their own. This key pair is regarded as
a wallet, and the public key of the key pair is regarded as the address
of the wallet. The private key is kept secret and it can be used to
manipulate the funds belonging to the wallet. The user then shares the
address so other users that are in possession of some Bitcoin can
send funds to this address by broadcasting a transaction that will either
be accepted and written to the blockchain (only if it is a valid
transaction) or simply ignored. Besides mining, there is no other way
to obtain Bitcoin.
Note that there is no need to register anywhere. Also note that all the
user needs in order to access the funds is the key pair. This means
that the user is not bound to any device while using Bitcoin. The user
can generate a new wallet on their phone (even with no internet
connection), share the address of the wallet, retain the key pair and
then destroy the phone. The user can also subsequently travel to the
other side of the world just with the key pair and then use this key pair
to access their funds on any device with an access to the internet and
a Bitcoin client installed. This is possible due to the public nature of the
blockchain described later on. However, if the user loses the private
key, the funds are lost forever. Also, once the private key gets exposed
to an adversary, this adversary instantly gains full control over the
funds.
1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
or
bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq.
The receiver looks at the transaction referenced in the input, and gets
the sender’s public key from it. Subsequently, they verify that the
signature of the current transaction is valid. If this is true, we can be
sure that the funds are transferred (to the owner of the public key
specified in the output) only by the owner of the private key that
corresponds to the public key stored in the output of the referenced
previous transaction.
gn gn
Si Si
Owner 1's Owner 2's Owner 3's
Private Key Private Key Private Key
Transactions can have multiple inputs and multiple outputs. This allows
the value to be split and combined. All inputs are summed up, and this
sum has to be spent in the outputs. 1 If we don’t want to use all the
funds specified in the input, we can simply send it back to the same
wallet that we currently use for the transfer.
1
Unused funds are used as an incentive for miners.
Marek (CTU FIT) Blockchain — Introduction NIE-BLO, 2021, Lec. 1. 21 / 63
Chain of Transactions
E : y 2 ≡ x 3 + ax + b (mod p),
y 2 ≡ x 3 + 7 (mod p).
In fact, the finite field Fp is the prime field Zp with the characteristic p.
It can be easily shown that the points on the curve form an aditive
Abelian group under specifically defined addition. The standard also
specifies the base point G which is a generator of a subgroup of the
original group. Since the cofactor of the base point is 1, the base point
actually generates the whole group. The order n of the base point; and
in fact the whole group, is a 256 bit number. The private key in ECDSA
is a randomly selected integer in the interval [1, n − 1] and the public
key is a point on the curve.
We see that the curve offers 256 bits of entropy since we have
approximately 2256 points; however, we have to consider it together
with ECDSA which is based on the discrete logarithm problem. The
algorithms that solve the problem, such
√ as the baby-step giant-step
algorithm, have time complexity O( n) where n is√the order of the
group. Since n ≈ 2256 , the actual complexity is O( 2256 ) = O(2128 ).
This gives us 128 bits of security which is equivalent to the 3072 bit
RSA/DSA modulus (the size of a properly encoded public key is
approximately 256 bits). We see that elliptic curve cryptography offers
much shorter keys when compared to RSA/DSA.
The actual Bitcoin address is a 160-bit hash of the public key. This
means there are two ways a potential collision could occur. The first
possibility is that two users generate the same keys that will result in
the same hash. The second possibility is that two different keys will
result in the same hash as well. Even though the keys are different, the
signature will still be valid and the users will be able to manipulate
each others funds. The chance for any of these collisions to occur is
negligible provided we use a true random number generator.
It is important to realize that the process of looking for the right nonce
is not a long set problem. Each hash produces a random number
between 0 and 2256 , so looking for the right nonce is a lottery. No
matter how many nonces we have tried before, the probability of
getting the right one remains the same. Thinking otherwise results into
the gambler’s fallacy belief. The value of the target is adjusted by the
network every 2016 blocks so that on average it takes about 10
minutes for the whole network to generate a new block. This
adjustment is made in order to keep the network stable while the hash
power changes over time. Not every node in the network needs to
search for the right nonce. Nodes that do so are called miners.
Other nodes will accept the newly broadcasted block only if all
transactions in it are valid (by checking the preceding transactions),
and only if the hash of the block (including the right nonce) is less than
the specified target (to check this, only one hash is needed). Every
block contains a reference to the previous block; and therefore, it is
extremely difficult to change any data in the previously accepted
blocks. This would require re-hashing all the blocks that follow after the
altered one. As transactions in accepted blocks are buried under new
blocks, it becomes impossible for anybody to change them. This
mechanism brings complete trust to the whole history of all the blocks.
It is also not anymore necessary to check every preceding transaction
of a new block being currently verified. It is sufficient to check just a
couple of preceding transactions since the older ones are immutable
and they were checked already during their acceptance.
Notice that a 51% attack is not a typical Sybil attack in which the
attacker would create a large amount of fake identities which would be
used to gain the mining influence. Mining power of the attacker is
determined solely by their hash power which depends on
computational resources and energy.
A node that creates a new block can also claim all inputs in
transactions that do not have corresponding outputs. Such inputs are
called transaction fees, and users can motivate miners to prefer their
transactions to be processed with higher priority by providing a higher
transaction fee. Fees also prevent spam transactions.
During the first couple of years, there were usually no fees associated
with transactions. As the transaction volume was growing, fees
became a norm, and transactions with no fees are simply ignored.
This prevents an attacker from flooding the network by an enormous
amount of dummy transactions that could slow down the network for
regular users. It is also expected that fees will be the main motivation
for miners once the predetermined number of coins have entered
circulation.
Miners nowadays unite their hashing power under mining pools as the
probability of hitting the right hash for a single miner is very low.
A mining pool then rewards each miner according to their hashing
contribution to the pool. The pool sends candidate blocks with lowered
target to the miners. These candidate blocks are called shares. The
target is lowered so that the miner can solve it in a reasonable time. By
measuring how long it takes to each miner, the pool can determine the
miner’s hash power, and subsequently the reward for the miner. Each
share contains a coinbase transaction with the receiver’s address set
to the pool’s address. Note that at some point, one of the miners
generates a hash that is not only lower than the target required by the
share but also by the whole Bitcoin network. Also note that once a
miner finds such a hash, they cannot simply change the coinbase
transaction and point it to their address since doing so would invalidate
the hash.
For a Bitcoin light client, it is sufficient to keep only the root hash of the
Merkle tree. If such a client needs to verify a transaction, it can link it to
a place in the chain according to its timestamp and check that other full
nodes accepted it. This method is called Simplified Payment
Verification (SPV). However, light clients are vulnerable to second
preimage attacks (an attacker could forge the interior of the Merkle
tree). Also note that if a user does not wish to share which
transactions are of an interest to them, they have to run a full node
(and store the whole blockchain) since light clients request specific
transactions from other nodes.
The difficulty is given by the value of the target which is a 256 bit
number. This value is stored in each block in the “Bits” field, the size of
which is 4 bytes. The first byte is the exponent e and the remaining
three bytes constitute the mantissa m. The value of the target is then
calculated according to the formula
target = 256e−3 m.
δ
targetnew = targetprevious ,
2weeks
where δ is the actual time difference between the 2016 blocks.
Since the Bitcoin code base is an open platform, anyone can fork the
source code in the software engineering sense, and start either a
completely new chain of blocks from the very beginning or fork the
existing Bitcoin blockchain at a specific point, and continue in its own
way. In both cases, there is a new cryptocurrency created since the
new blocks are not compatible with the Bitcoin blockchain anymore. In
the latter case, users can keep and use all the funds they owned in the
standard Bitcoin blockchain. There are currently thousands of such
cryptocurrencies. This demonstrates the voluntary nature of Bitcoin
since anyone can use (including operating a full-node or mining) any
chain of blocks they prefer. Operators running Bitcoin nodes and
miners decide by themselves what ‘version’ of the blockchain they use
and nobody can force them not to do so. The same holds for ordinary
Bitcoin users and programmers who propose and develop new
features.