How a blockchain works – the Proof of Work

When we were talking about mining, we mentioned a difficult puzzle that a miner has to solve. What is this puzzle and what is it for?
Before reading this article, I suggest you read these two articles

So what is the puzzle that has to be solved by a miner?

The puzzle that a miner has to solve during the block creation is called proof-of-work. The proof-of-work is a piece of data which requires computational power to be created but it can be verified quickly. Thanks to the proof-of-work the blockchain’s data becomes immutable.

In the previous article we created a simple blockchain and we saw that tampering a block causes the invalidation of the following blocks.
In that example recalculating the hash of invalid blocks is simple, but if we add complexity in the calculation we will make the bad guys’ life difficult.

What is the proof-of-work for? Why do miners spend so much effort on mining?

The proof-of-work is a mechanism for reaching global consensus on the valid blockchain: since all nodes have a copy of the blockchain, each node must agree on the conditions that prove how much effort a node has spent on verifying transactions.
In other words: if the content of the blockchain is easy to change then everyone can tamper with it; instead, if each block is calculated with complex mathematical functions then it takes a lot of effort to tamper with the blockchain.

Let’s check the proof-of-work more in depth.

Let’s create a blockchain where the blocks are linked to each other through an identification code; a block contains the following data:

    • identification code of the previous block (PREV)
    • name of the sender (SENDER)
    • name of the receiver (RECEIVER)
    • bitcoin amount (AMOUNT)

To make the calculation difficult, every identification code must start with 0000 (four zeros). To do this we have to add a new field called NONCE.

For a better understanding let’s take an example.

The first block of our blockchain includes the following data (please note that the identification code of the previous block is 0 because this is the first block):

PREV:0
SENDER:john
RECEIVER:jenny
AMOUNT:100
NONCE:1

Now let’s copy this block content, then paste it in the hash calculator and press the button Calculate SHA-256 Hash (be careful with spaces and new lines). The hash is as follows:
07b01b0f4672f2bc58ef11132df4bc74a4e0dc9f2e07ee5d9a0428d3836bc6cb

As you can see the code starts with b273 and not with 0000; so you must increase the NONCE and repeat the calculation again (note that increasing the NONCE from 1 to 2 leads to the change of the content and consequently the hash changes too).
Now our block is:

PREV:0
SENDER:john
RECEIVER:jenny
AMOUNT:100
NONCE:2

and its hash is:
263172553403d3182866ed4d2e7b588a6932e58d0acaa1fa92958a1f70dfabc5

The code still does not start with 0000! You must repeat the calculation all over again until the code starts with 0000. OK, I will give you the solution: you have to repeat this process 22683 times!

PREV:0
SENDER:john
RECEIVER:jenny
AMOUNT:100
NONCE:22683

Hash code: 00000d7d33ebf71c24c15119c925acf9d9d45f8f9972034e2c8b1aabe29163a7

As it was said in the previous article, the hash is a one way function, so the only way to find the block’s identification code that starts with 0000 is making random attempts (the method is called brute force).

Let’s create a blockchain that we made in the previous article but this time we will apply the proof-of-work to it; this is what we get:

If you tamper the first block, you will break all the blockchain and for every block you will have to calculate the hashes that start with 0000 again! So, when a certain block has many blocks after it, this block becomes secure.

In the bitcoins world a block becomes secure when it has at least 6 following blocks; keep in mind that the difficulty of the hash calculation is much higher than our example.
If you want to tamper the bitcoin’s blockchain, remember that every fake block must comply with the calculation difficulty criteria and moreover you have to create fake blocks faster than the other miners in the network… to achieve this you need 51% of the computational power of the whole network!

Nowadays the blockchain technology is pushing to find other ways to reach the network consensus because the proof-of-work is not energy-efficient at all. Some of these new ways are proof of stake, proof of burn or casper.

___________

More Info

Bitcoin hash rate: https://blockchain.info/it/charts/hash-rate?timespan=all

More info about proof-of-work: https://en.bitcoin.it/wiki/Proof_of_work

HASH calculator: https://www.danielefavi.com/sha256-hash-calculator/

PHP code that I used to create the blockchain example: https://github.com/danielefavi/blockchain-hash-block-calculator

___________

Read the original at www.danielefavi.com

How a blockchain works… Let’s make one!

Have you ever wondered why the blocks on the blockchain are stored one after another?
In this article we are going to talk about the basic blockchain concepts; these concepts will be fundamental to grasp how the proof-of-work works, why the mining requires lots of computational power and how the blocks become immutable.

The blockchain technology uses a mathematical function called Hash which turns data into a 64 character long code. The hash code identifies the block in the blockchain and protects its content.

What is the hash?

The hash is a mathematical function that turns every type of data (like text or file) into a string of 64 characters. The output code never changes for the same input. The hash is a one way function: it is easy to generate a code but starting from a hash code it is impossible to get the original data.

Let’s take an example: this is the link to my website where you can find the hash calculator https://www.danielefavi.com/sha256-hash-calculator/.
Let’s type “test” in the text field and then press the button Calculate SHA256 hash. The generated code is:
9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

Now let’s type “test.” (add only a full stop) in the text field Data and press again the button Calculate SHA256 hash. The generated hash is:
4ee3df88f682d376531d8803f2ccbee56d075cd248fc300f55dfe8596a7354b7

Adding a full stop makes a difference, the code of “test” is totally different from the code of “test.” Even the addition of a space or a blank line or change a letter to the capital letter can change completely the hash of the output code.

It is easy to calculate the hash, but it is very difficult to get back the starting data from the hash. For example try to find the word that matches with the following hash:
3866daf66ad5f7e6dbf8c983b06287d7ad254336a172d8f34eb1cb4f25f12b70
You can search for a starting word doing lots of random attempts until you will find the corresponding word (this method is called brute-force).

Let’s create a simple blockchain to understand what the hash is for.

Our blockchain contains simple information: a list of people with their names and ages; the name and the age are separated by a dash:

  • Block 1: Natalia-28
  • Block 2: John-45
  • Block 3: Paul-21
  • Block 4: Claire-67

Every block must have an identification code: this code will be calculated with the hash.
In order to build a chain of blocks you must link each block to its previous one: so a block must contains the identification code of the previous block.

For a better understanding let’s build our blockchain.

Let’s start with the first block: since the block 1 has no previous blocks we can choose zero: 0-natalia-28.
Now go to the hash calculator and calculate the hash of 0-natalia-28; the hash is:
51831cdd6acfaee6c7402cea12c58f514bc014d495e185610ee6cc664452d23d

Let’s take only the first 5 digits of this code (to make our life easy) and put them at the beginning of the second block: 51831-john-45.
Go back to the hash calculator and calculate the hash of 51831-john-45; the generated hash is:
4e942233bba491ab530669fa78c03b3e72c4e3940834e3e960d9ca32ed959429

Again, take only the first 5 digits and put them at the beginning of the third block, obtaining 4e942-paul-21.
Repeat the same process for the blocks #3 and #4; the chain that you have built is:

Let’s tamper with the blockchain!

For our friend Natalia, from the first block, let’s change the age from 28 to 25. So, changing the content of the block will result in the change of the hash of the block too.
The new content of the first block is 0-natalia-25 and the first 5 digits of the new hash are 07698.

Since the identification code of the first block changed (before it was 51831 and now it is 07698) we must update the hash code inside the second block that refers to the first block. With this update the content of the second block changes (now it is 07698-john-45) so we have to calculate again the hash of the second block: the first 5 digits of the hash code of 07698-john-45 are 43339.

The hash code of the block #2 is changed, as well as the content of the block #3. The content of the block #3 is 77e83-paul-21.
As you have already guessed, since the content of the block #3 is changed, we must calculate again its hash, which will cause the change of the content and the hash of the block #4.

The change of the content of the block not only invalidates the block itself but causes the invalidation of all the following blocks.

This article showed us how a blockchain is structured. In the next article we will see how to prevent a blockchain from being tampered.

___________

Read the original article at www.danielefavi.com

What is the mining? Who is the miner?

The mining is the process where the data is collected in a block and then the block is appended to the blockchain. This process is done by the miner.

Before digging into the process of mining, I suggest you read the following articles:

Who is the miner? Why does a person decide to start mining?

The miner is a special node in the network that gives its computational power to the network. You could be a miner too, all you need to do is to download a free software and run it.
The miner earns 12.5 bitcoins for each block created (called coinbase) as well as the transaction fee.

If it’s so easy I’ll quit my job and I’m going to be a miner!

Wait! It’s not so easy! In order to secure the data on the blockchain, it has been made intentionally difficult to create a block.
During the mining process, the miner calculates a code which will identify the block within the blockchain. This calculation must comply with the criteria of complexity that increases with the hashing power of the network. This difficult puzzle is called proof-of-work (I will talk about it in the next article).
The miners are racing with each other to solve the puzzle and the winner will earn the coinbase and the transaction fees.
Nowadays, there are miners with warehouses full of special computers that are working 24/7 only for mining; so if you want to start the career as a miner, your nerd computer is not enough!

What is the proof-of-work for? Why do miners spend so much effort on mining?

The proof-of-work is a mechanism for reaching global consensus on the valid blockchain: since all nodes have a copy of the blockchain, each node must agree on the conditions that prove how much effort a node has spent on verifying transactions.
In other words: if the content of the blockchain is easy to change then everyone can tamper with it; instead, if each block is calculated with complex mathematical functions then it takes a lot of effort to tamper with the blockchain.

If everyone can be a miner, is there any risk that someone can create a fake block?

Of course. A bad miner can create an invalid block; but remember that before appending a block to the blockchain, a miner must check if the block is valid. Hence if the block received by the miner is not valid, it will be rejected.
Moreover, the identifier hash code links each block together in a chain (that’s why the name is the blockchain); if I tamper with a block, I will invalidate not only that block, but also all the following blocks!

References

Coinbase value: https://blockchain.info/stats (you can calculate it dividing Bitcoins Mined by Blocks Mined)

Hash: wikipedia or you can wait for the next article!

Difficulty of proof-of-work: https://blockchain.info/it/charts/hash-rate?timespan=all

___________

Read the original article at www.danielefavi.com

Bitcoin transaction: how does it work?

In the previous article we had a quick introduction to the blockchain technology. In this article we are going to see what’s happening behind a bitcoin transaction.

Let’s take a simple example: Robert and his friends went to the Bit&Beer pub where bitcoin payments are accepted. After the whole night of drinking and having fun it’s time to pay the bill!
The waiter takes out a smartphone and shows the QR code to Robert for the payment of the bill. Robert takes out his smartphone as well, opens his bitcon app, scans the QR code, checks if the payment details are correct and presses the PAY button.

The QR code is a kind of a bar code but more complex, it contains several types of information, like:

  • the ewallet of the receiver (in our case Bit&Beer)
  • bitcoin amount to transfer
  • general information (like the name of the receiver)

When Robert presses the PAY button he creates a new transaction which contains the sender’s ewallet (Robert) and the receiver’s ewallet (Bit&Beer) details, the amount of bitcoins and a small fee. The fee however is not mandatory: the sender can decide whether or not to include the fee (transactions with a higher fee have a higher priority).

What is happening behind the scene?

The transaction is propagated in the bitcoin network (phase #1 of the scheme); the waiter of Bit&Beer can see Robert’s payment on his phone almost instantly, the status however is NOT CONFIRMED.

Who decides whether a transaction is valid or not?

The transaction is considered valid when special nodes in the network (called Miner) will append this transaction into a block in the blockchain.
This process is called Mining (phase #2 of the chart) and it has the following purposes:

  • to validate the transaction (referring to consensus protocol) or to reject an invalid transaction.
  • to create new bitcoins.

The process of Mining is the essential phase where the transactions are stored in the blockchain. In this step the transaction is being included inside a new block and this block is appended to the blockchain.
It is not simple at all to create a new block. Mining a block requires complex operations using a lot of computational power; this operation is called proof-of-work and it verifies the data on the blockchain and makes it immutable.

Miners are racing with each other to create a block: the first one that creates a block which satisfies the requirements earns some bitcoins and the fee within the transactions (phase #3 of the chart).

A new block is propagated on the network (phase #4 of the chart); other miners which received a new block, are going to check if the block is valid first and then include the new block in the blockchain.
Finally, the waiter of Bit&Beer can see in his ewallet that the payment has been confirmed. All this process is about 10 minutes long.

___________

Read the original at www.danielefavi.com

Blockchain for Dummies! A gentle introduction.

This article is one of several articles in which I explain in a very simple way what a blockchain is.

What is the difference between Bitcoin and Blockchain?

Blockchain is the technology behind bitcoin: bitcoin cannot exist without a blockchain. It is like Internet and Facebook: Facebook cannot exist without Internet.

What is a blockchain?

A Blockchain is a kind of database: while a normal database is located on a server, a blockchain is distributed among the software users.
For example, the Facebook’s database is located on a protected server and no one can access the information. The Bitcoin’s blockchain instead is located on servers and computers (called nodes) of all the Bitcoin users.

All the transactions that occur between ewallets are stored on the bitcoin’s blockchain. All the servers and the computers that are using bitcoin have the same copy of the blockchain stored on their hard disk.

There are many kinds of blockchain with different features, like Ethereum, Hyperledger, Ripple. Some of them are more suitable to handle currency, others are used to transfer the ownership of assets (eg supply chain).

You don’t need to download all the blockchain to your computer in order to use Bitcoin (or any other blockchain technology) as the current size of Bitcoin’s blockchain is over 160 GB and it can easily drain the resources of your computer. To avoid this issue there are different types of e-wallets (we will talk about them later).

If the bitcoin’s blockchain is on my computer, can I add 1 million of bitcoins in my ewallet?

The blockchain is famous for its security: once the data is there it is impossible to modify it.

The blockchain consists of a chain of blocks, where every block contains data (for instance a money transactions, documents or personal data).
When a new block is to be added to the chain, it has to be verified by the network of nodes first, and once this is done, the transaction can be inserted in the blockchain. There are mining and a consensus protocol standing behind this phase (click here to read more).
The blocks are connected with each other in a way that if I edit the content of one block I must edit all the following blocks, moreover to edit a block you need the consensus of other nodes.
Hence the more people are using a blockchain, the longer it is and the more secure the system is.

At present there are over 9000 nodes in the Bitcoin system.

Are you telling me that the blockchain has no flaws?

Technically it is possible to break into the blockchain but you will need more than half of the computational power of the whole world (so basically it is impossible).

Experts are worried that blockchain cannot resists a quantum attack. A quantum computer is a next generation computer with a huge computational power, it is being developed in Google’s laboratory. It can come out in 10 or 20 years but by that time also the blockchain technology will evolve. For instance Iota is a new kind of blockchain with a different structure and it can resists a quantum attack.

Why don’t we continue using a normal database as we did so far?

The blockchain is shaking many industries but it cannot be used everywhere. For example there is no sense in using blockchain to store the data of this website. But it makes a big difference when the third party is involved.
If you have to transfer money, the bank is the third party that takes the money from you and transfers it to the recipient.

In the Bitcoin system there is no one between you and the recipient, the transfer is direct, and it takes around 10 minutes.

The blockchain technology is applied in many industries such as music, real estate and energy. The company where I work uses the blockchain technology in the notary industry.

Thanks! You convinced me! Now I’ll buy 1000000€ in Bitcoin!!!

Wait a moment! The blockchain world is wonderful but risky. There are legal and technical details that you have to understand.

In several countries Bitcoin is not regulated.
For instance if I steal from you 10000€ you can sue me. If I steal from you 100 bitcoins and you go to the police, the policemen will tell you that the Bitcoin has no value. From the legal point of view, to steal the bitcoins is like to steal the air! You cannot sue me for stealing something without value.
Keep yourself updated with regards to the cryptocurrency laws of the country you live in.

The blockchain is a technology that is still evolving, some technical problems can arise with its development as well. For example in 2016 a bug in the Ethereum cryptocurrency system resulted into a loss of 50 million dollars suffered by many users.

On the other hand, many investors took the risks and became rich. It’s important to be updated, rely on tested technology, use safe systems for money deposits and not to search for easy ways to make money.

___________

Read the original at www.danielefavi.com

Ledger Projects AT The Malta Stock Exchange

On the 12th October 2017 David Schranz, CEO, Anthony Mamo, Director, and Jesmond Saliba, Communications consultant of Ledger Projects called at the Exchange to discuss their blockchain project with the MSE executive team.

It was an honour for us to be invited to the Malta Stock Exchange, as representatives of the first local Company to deploy a fully functional DLT platform. We wish to thank Mr. Joseph Portelli Chairman of MSE, Mr Simon Zammit, CEO and the rest of the team at the MSE for their welcome and support.

Malta’s First Blockchain Application Launched

“Blockchains are not merely a business opportunity, but a way to change how governments serve their citizens and how private companies serve their clients. The main priorities should be regulation and incentives to attract the right capital and talent to stimulate growth in this sector.”

This was stated by Maltese technologist David Schranz and Maltese businessman Anthony Mamo who launched the first ever Maltese built Distributed Ledger Application targeted at property transfer management, LP 01, through their newly set up company Ledger Projects.

“Rolling out such technology as Block chain is easier in Malta since the country enjoys a strong financial system, talent, entrepreneurial spirit and a can-do approach that can turn our island into a base and a test-bed for new sectors and technologies. Malta has become a centre of excellence with an enviable reputation in many sectors, and not only ones that are ICT related. The formula, so to speak, is already tried and tested and can therefore be replicated in other areas such as block chain,” said the two entrepreneurs.

This launch took place within a particular context, where Malta is pushing forward a strategy aimed at becoming a regional centre of excellence in this field. In fact earlier this year, Malta’s Government has set up a taskforce to review proposals and make its recommendations for a clear roadmap to be taken by the Government to implement its National Blockchain Strategy, aimed at materialising the opportunities of distributed ledger technology. Apart from exploiting the opportunities that block-chain technology offers for added efficiency in public sector processes and services, the Government looked into the setting up of a new regulatory function, with the primary objective of harnessing the technology with a legal operational framework, serving as a bold initiative leading to the formation of an ideal ecosystem for those willing to invest in block-chain technology.

Speaking about the main advantages of blockchain, David Schranz explained how the technology enables any two parties to make an exchange without the oversight or intermediation of a third party, strongly reducing or even eliminating counterparty risk. “This means that the users are in control of all their information and transactions. Furthermore when using blockchain one can claim that data is complete, consistent, timely, accurate, and widely available.”

Parliamentary Secretary for Financial Services, Digital Economy and Innovation Silvio Schembri announced that the government is working to create a sandbox that allows for the use of crypto currency in the iGaming industry. He explained that the plan is to allow the use of cryptocurrencies in iGaming, where a player will be able to transact in digital currency in and out of gaming platforms.

“These initiatives show that Malta is indeed gaining momentum and moving fast in the adoption of blockchain technology,” said Schembri while adding that this work will enable to harness the market with the right regulation.

Parliamentary Secretary Silvio Schembri reiterated government’s intention in making use of blockchain technology so that services provided by the public sector will be more efficient. He expressed his satisfaction at the interest from local and international private investors, was significant” and that the government would remain available to discuss innovative ideas “rendering this disruptive technology into a catalyst for the further growth of Malta’s digital economy”.

The team at Ledger Projects is being mentored by Dr Abdalla Kablan, who is a widely respected fintech expert and data scientist. Dr Kablan has always been at the forefront of disruptive technology and is considered a renowned entrepreneur and published academic. His interdisciplinary background in fintech and machine learning has been paramount to his international success, and Ledger Projects is delighted that he has mentored our team academically.

Speaking about Ledger Projects’ first product LP 01, David Schranz said “We have been focused on researching, developing and testing LP 01 for the past 20 months. The design process was somewhat difficult because we wanted to ensure that we would be able to scale horizontally within reasonable time frames. During this time we also focused on identifying immediate opportunities where DLT could bring tangible benefits to multiple users and the plan is to deploy another 2 applications at 6 month intervals.”

Referring to the people at Ledger Projects, David Schranz added, “the team is small but very diverse, and consists of people with very different skillsets and backgrounds. We have managed to attract persons who are academics, technologists with a passion for innovation and people with a strong legal background. We are also fortunate enough to be able to involve from time to time people with experience in a particular field to explain inefficiencies in their business process and provide feedback to our proposed solutions.”

Those interested to learn more about Ledger Projects and its product offer may send an email to info@localhost.

Ledger Projects sponsor Mr James Farrugia, the top Artificial Intelligence student in Malta

Ledger Projects, a local company specialising in Fintech,  was the first organisation to take part in a scheme launched by the Artificial Intelligence (AI) Department, within the Faculty of ICT at the University of Malta, aimed at sponsoring the top performing students of the B.Sc. AI degree.

The student, Mr James Farrugia, will now embark on a fully paid M.Sc. AI in Fintech (2017-2018) held at the University of Malta. Mr James Farrugia was not only one of the top performing students of his year but also received the Dean’s Award. An Agreement to regulate this scholarship was signed by Mr David Schranz, CEO Ledger Projects, the University of Malta Rector, Professor Alfred J. Vella and  scholarship awardee, Mr James Farrugia in the presence of Prof Alexiei Dingli, Head of the AI Department and Mr Anthony Mamo, Director Ledger Projects.

 
More Info: http://www.um.edu.mt/newspoint/news/features/2017/07/ledgerprojectssponsormrjamesfarrugia,thetopartificialintelligencestudentinmalta