Dbatu University Blockchain Technology Notes BCT 2nd Unit
Dbatu University Blockchain Technology Notes BCT 2nd Unit
Double-Spending
• Double spending is when someone spends the same cryptocurrency twice.
• Double spending means the expenditure of the same digital currency twice or more to avail
the multiple services. It is a technical flaw that allows users to duplicate money.
• Since digital currencies are nothing but files, a malicious user can create multiple copies of the
same currency file and can use it in multiple places.
• This issue can also occur if there is an alteration in the network or copies of the currency are
only used and not the original one.
• There are also double spends that allow hackers to reverse transactions so that transaction
happens two times.
• By doing this, the user loses money two times one for the fake block created by the hacker and
for the original block as well.
• The hacker gets incentives as well for the fake blocks that have been mined and confirmed.
•Finney Attack: Finney Attack is a type of Double spending Attack. In this, a merchant
accepts an unauthorized transaction. The original block is eclipsed by the hacker using
an eclipse attack. The transaction is performed on an unauthorized one. After that, the
real block shows up and again the transaction is done automatically for the real block.
Thus the merchant loses money two times.
•Race attack: is an attack in which there is a ‘race’ between two transactions. The
attacker sends the same money using different machines to two different merchants.
The merchants send their goods but transactions get invalid.
•51% Attack: This type of attack is prevalent in small blockchains. Hackers usually
take over 51% of the mining power of blockchain and therefore can do anything of
their own will.
Bitcoin Script
Bitcoin uses a scripting system for transactions. Forth-like, Script is simple,
stack-based, and processed from left to right. It is intentionally not Turing-
complete, with no loops.
Script is what’s known as a stack-based language. All this means is that, when
we read a set of instructions, we place them in what can be thought of as a vertical
column. The list A, B, C, for example, would result in a stack with A at the
bottom, and C at the top. When the instructions tell us to do something, we
operate on one or more elements beginning at the top of the stack.
Elements A, B, and C being added and “popped” from the stack.
We can distinguish between the data (things like signatures, hashes, and public
keys) and the instructions (or opcodes). The instructions remove data and do
something with it. Here’s a very simple example of what a script could look like:
<xyz> <md5 hasher> <d16fb36f0911f878998c136191af705e> <check if equal>
In red, we have data, and in blue, we have the opcodes. We read from left to
right, so we first put the string <xyz> onto the stack. Next up is the <md5
hasher> opcode. This one doesn’t exist in Bitcoin, but let’s say that it removes the
top element of the stack (<xyz>) and hashes it using the MD5 algorithm. Then, the
output gets added back onto the stack. The output here happens to be
d16fb36f0911f878998c136191af705e.
<check if equal> pops two elements off the top and checks if they’re equal. If
they are, it adds <1> to the stack. If not, it adds <0>.
Pay-to-Pubkey (P2PK)
The structure was heavily used in the early days of Bitcoin, but nowadays, Pay-to-
Pubkey-Hash (P2PKH) has largely replaced it.
The locking script for a P2PK transaction follows the format of <public
key> OP_CHECKSIG. Simple enough. You might have guessed
that OP_CHECKSIG checks for a signature against the provided public key. As
such, our scriptSig is going to be a simple <signature>. Remember, the scriptSig is
the key to the lock.
Pay-to-Pubkey-Hash (P2PKH)
The scriptPubKey in P2PKH is the following:
OP_DUP OP_HASH160 <public key hash> OP_EQUALVERIFY OP_CHECKSIG
OP_DUP
OP_DUP pops the first element, and duplicates it. Then, it adds both back to the stack. Typically, this is done so
that we can do an operation on the duplicate without affecting the original.
OP_HASH160
This pops the first element and hashes it twice. The first round will hash with the SHA-256 algorithm. The SHA-
256 output is then hashed with the RIPEMD-160 algorithm. The resulting output is added back onto the stack.
OP_EQUALVERIFY
OP_EQUALVERIFY combines two other operators – OP_EQUAL and OP_VERIFY. OP_EQUAL pops two
elements and checks if they’re identical. If they are, it adds a 1 to the stack. If not, it adds a 0. OP_VERIFY pops
the top element and checks if it’s True (i.e., non-zero). If it isn’t, the transaction fails. Combined,
OP_EQUALVERIFY causes the transaction to fail if the top two elements don’t match.
This time, the scriptSig looks like this:
<signature> <public key>
You need to provide a signature and the corresponding public key to unlock P2PKH outputs.
Bitcoin P2P
In peer-to-peer network all the nodes are equal and each node plays
role of client and server with other nodes.
A public key is a series of letters and numbers that a user must share in
order to receive funds. In contrast, a private key must be kept secret as it
authorizes the spending of any funds received by the associated public key.
To better illustrate how value is transferred in the Bitcoin network, we
will walk through an example transaction, where Alice sends .05 bitcoin
to Bob.
A transaction has three main parts:
Inputs. The bitcoin address that contains the bitcoin Alice wants to send. To
be more accurate, it is the address from which Alice had previously received
bitcoin to and is now wanting to spend.
· To maintain the time it takes to process one block at around 10 minutes, difficulty
has to be adjusted periodically.
Proof of Burn