https://2019.makerfairerome.eu/en/

Bitcoin & Blockchain

By on June 18, 2019
Pin It

 

We are going to take advantage of one of the most known real-life examples in order to introduce the concept of blockchain, its characteristics and its practical usefulness, also explaining how to mine Bitcoins using an essential hardware platform such as Raspberry Pi.

 

In today’s society, everything evolves really fast: lifestyle, communication… Even the concept of work. But there are some things that never change, such as the foundations of the economy, on which we base our everyday life: in order to purchase a good, we need something that allows to carry out the exchange, which is money, conventionally.

Today, however, technological evolution wants to try and radically change our concept of exchange and money.

In this article we are going to talk in-depth about the notoriety of Bitcoin in order to analyze the system at its foundation and which finds application also outside of Bitcoin: the blockchain. We will see how it works and what it is for. This phenomenon is quite spread nowadays as many people are approaching the world of blockchain, Bitcoin and cryptocurrencies in general, although they often lack the technological, mathematical and economical competences to do it in a scientific manner. Therefore, we will try to answer some of the most frequently asked questions, about what the blockchain is and what does it mean, how Bitcoin works and what is its meaning or its use, in comparison to traditional money. Then we will see how to turn our PC-on-a-board (a.k.a. Raspberry PI) into an active blockchain element, by making it into a relentless digital miner. Furthermore, we will attempt to calculate how much “mining” a Bitcoin costs.

 

Blockchain and Bitcoin

Let’s try to understand how the blockchain works through a comparison with already established economical measurements and concepts with which we have a certain degree of familiarity. Next, we will analyze the technique generating Bitcoins more in detail. (Fig. 1)

Bitcoin is a virtual currency which name derives from the terms coin and bit; it can be used on a global scale and, just like any other currency, it can be converted into another currency.







Created in 2008 by an individual known by the pseudonym of Satoshi Nakamoto, and officially launched in 2009, Bitcoin managed to overcome the value of gold and even passed the $17,000 threshold in December 2017.

 

Fig. 1

 

One of the most interesting aspects of this coin is that its appearance introduced a monetary system operating in a different way from the traditional ones, based on decentralization and anonymity. The first feature means that the underlying monetary system adopted by Bitcoin does not require an institution and therefore there is no central controlling body, while conventional currency is managed by a central bank, which is a control body that issues currency and guarantees the currency is not fake or counterfeited, but also guarantees a coherent exchange rate. Bitcoin doesn’t need a centralized controlling body and we will explain why shortly. On the other hand, anonymity means that the identity of Bitcoin users is never revealed, contrarily to what happens with traditional currency.

Furthermore, anonymity is guaranteed by the fact that Bitcoin is an encrypted currency. Bitcoin payments take place through blockchain-based solutions, which is a technology allowing the passage of information within a computer network among the nodes composing the network itself. The features making blockchain so interesting are security, transparency and anonymity.

The anonymity matter and is possibly the most controversial, especially because the global economy is trying to contain widespread crime activities such as money laundering, illicit traffic, sale of arms, drugs and dangerous substances, as well as other issues related to the use of cash, which exchange is not traceable.

Likewise, Bitcoin cannot be traced, this is why many fear it might be a privileged channel for money laundering; these fundamental issues, which are beyond the scope of this article, are being studied by academics, law experts, politicians, sociologists, technicians, journalists and economists.

Just like many other easily available and usable technologies, the cryptocurrency technology spread very rapidly and can be used by anyone by downloading and installing simple software applications or connecting to specific websites that allow to send, receive and save Bitcoins just like an actual online wallet. The worrisome aspect is that these services are not covered by the anti-laundering regulations.

From an economic perspective, a lot has happened since the first financial system where “1 g of gold equals its equivalent in gold”; the Golden share has been eliminated and the equivalent value sounds like an outdated concept, also thanks to the abundance and types of different financial products currently available on the market. The global economic system is, in fact, becoming less and less “material” in nature: this is due both to the fact that economies became service economies, and to the obsolescence of the concept of industrial and material production as the only instrument to establish the existence of something to which a price can be conferred.

When we go out shopping, we accept the idea to purchase a material good in exchange of paper with conventional figures drawn on them, i.e. paper money; this happens because we all agree that those pieces of paper have a specific value. We also accept the concept that a retailer must accept these pieces of paper as a form of exchange currency.

We also accept that not all currencies are equal, that exchange rates exist, that they all have an intrinsic value, that they can replace gold because they are more convenient to use and that all currency in the market is authentic because there is a dedicated controlling body checking it.

All these assumptions come from a series of suppositions at the foundation of the economic system as we know it today.

Conventional currency is a de facto bond, issued by the central bank of the country and providing the equivalent value when returned to the bank itself.

Bitcoin is outside this logic, so many ask questions such as “how much is one Bitcoin worth?”, “If I buy a Bitcoin, what do I get?”, “Where can I spend a Bitcoin?”, As well as its simplified version “can I buy bread using Bitcoin?”.

These questions are funny in their ingenuity and it’s no surprise since the current economic system has been designed to be used even by the most uneducated people. However, since currency may be virtual and digital in the future, it seems like a good idea to explain the mechanism behind it, not as simple as it is with traditional money, which passes through the blockchain.

Anyone having a bank account, regardless of the number of transactions, know that at any given time they can check their balance, inbound and outbound transactions and details about recipients for all the money that is no longer available. The bank is legally responsible to save all this information inside a private and protected system. It also must allow ubiquitous access to that information to its customers, anytime.

Access to that information is only allowed to account holders and operators enabled by the bank itself.

This criteria guarantees, with absolute certainty, and for all the subjects involved, that their movements are reserved, private, protected at any given time.







So far so good; but now, let’s try to envision a database which may contain an infinite number of elements.

Let’s also suppose that, anytime the bank inserts a new entry in the database, it defines the first transaction, then the second one and so on, using the sequence “1”, “2”, “3”, etc.

After a certain number of transactions, the bank, on its databases, will start to record entry as “i” and then “i+1”, “i+2” and so on.

This allows us to make two observations:

  • it is not possible to write a transaction with the previous index because writing an entry in the database is a unique, one-way action;
  • if within a certain period of time, the bank is writing the number “K”, the corresponding transaction cannot be considered as valid yet; it is somehow similar to the difference between accounting balance and available balance, so something we are familiar with; operations are accounted in the time it takes to do so and this means that all transactions for “k” can be accessed, while this one cannot.

Another observation is about the cost per transaction, i.e. the commission, justified by the running costs for the bank’s activities; the amount of said commission is not flat and subject to the rules of the free market, therefore each bank can set its own.

While still on the technical level, Bitcoin can easily be conceived as a series of uniquely defined code strings which have value only because they are accepted as exchange currency between the users; these codes work as a bona fide checking accounts.

Instead of an exchange mechanism based on a current see, you can think of it as a hybrid system: a real redefinition of barter, from a digital perspective.

 

 

Centralized vs decentralized

In order to better understand the concept of decentralization, the easier, quicker and most effective way is to analyze the concept of “centralized” monetary system: when an economic system is controlled by a central authority, the system is said to be “centralized”. The most important aspects are paper money printing, coin minting, tax collection, banks regularization and credit regularization in general.

Laws and regulations addressing these activities are issued by the government. Everything about every single transaction must be approved and memorized in order to avoid any possible future controversy. In this sense, banks operate to guarantee uniqueness of transactions, both in terms of exchange and participants to the exchange itself.

On the other hand, in a decentralized system, there is no such structure, however, the needs of the financial system are the same; therefore, the question is, who should grant formal and substantial correctness of the system operations without a regulatory body?

First of all, it is important to highlight that economic regulations are not universal; they differ from one country to another. The Bitcoin system answers the shared need to find a method for generating money.

It is clear that a centralized system involves some mechanisms that cannot be altered in any way.

But what does actually change in a decentralized system? Well, decentralization doesn’t change the need to save each transaction, but we might wonder how we can do that without a central body dedicated to it, who does guarantee that the memorization is reliable and data is true? In short, even if there is saved data, how can we make sure it is authentic? To explain this, let’s suppose we have two users, Alice and Bartholomew and Alice wants to send money to Bartholomew: within the bank system there is a group of people checking the credit availability of Alice and their task is to gather information related to the transaction towards Bartholomew, such as Bartholomew’s checking account number and the amount transferred.

Out of all the users eligible to control transactions, at least one will receive the notification that Alice wants to transfer money: let’s suppose this is Kate who, in order to earn a commission on the operation, will open the transaction, i.e. will create a new entry in the database. Remember that the database is shared between all the employees, therefore once the transaction takes place, the other users (let’s call them Danielle, Ernest, Francesca etc.) will know it is.

Kate must add the transaction to the database to make sure the operation can be numbered; in doing so, she will guarantee the database always contains updated, unique and consistent information. When all the employees verify the transaction has been added to the database, this will be declared as valid and therefore Kate is awarded with a commission.

Should Danielle or Francesca try to enter the same transaction in the database, would be impossible for them to complete the operation.

Should Kate and Danielle try to process the same transaction between Alice and Bartholomew at the same time, only one of them could complete the operation first; the faster one.

This case could represent any person using an electronic wallet application on a device, be it a PC or smartphone or any kind of portable device. The application is just a software capable of saving Bitcoins, keeping a record of the “miners” and’ IP addresses (those operating within the Bitcoin network); through their IP addresses, they are notified with each request for money transfer. Basically, each time we create a new transaction, it is properly notified.

Besides, the application periodically queries the “miners” to verify if the money transfer to our benefit has been issued, that is if we have received any payment, which introduces another concept: all these operations are calculations and are done using a computer. We are used to thinking that, the faster a computer is, the more “simultaneous” operations it can carry out. This is a new, very important element: the transactions management system on which Bitcoin is based is competitive and it is based on the fact that computational capacity makes a difference.

However, the system is very attentive to starting differences: let’s suppose that Kate and Danielle start at the same time trying to resolve the transaction and enter it in the database; the way we can all agree on who processed the transaction and therefore will be awarded a commission is by solving a mathematical puzzle.

For each transaction that can be processed by each of the employees of this “bank”, a mathematical question is generated, very hard to solve, and therefore much more complex than a simple operation such as addition or multiplication. The algorithm generating the mathematical problem works randomly in order to create always different problems and of ever-increasing difficulty compared to those previously generated; therefore the system gets more and more complex and the mathematical problem becomes more and more difficult, so entering transactions in the database requires employees who are faster and faster and machines that are more and more powerful. Anyway, one thing we know for sure: the problem will be solved; it’s just a matter of time!

Going back to Bartholomew, who now has this money amount, what did he really get? This is not coloured paper with figures and numbers, so what is this about? The peculiarity of the Bitcoin era is that we have no difficulties imagining that a checking account is the virtual counterpart of a pile of paper notes on the table, but the money being entirely virtual is the scary bit.

However, there is a comparison term with what used to take place: the so-called mining. Just like people use to go mining to extract pressures metals, we now have the activity of Bitcoin creation called mining.

Modern miners work at the best of their computational capacity just to solve those complex mathematical problems we mentioned previously.

Bitcoin is therefore the result of the mathematical problems mentioned above.

The effort of digital miners is to invest time, power and money first of all in a lot of machines, which can be updated in terms of computational capacity and which are constantly running.

Therefore, miners work both through commissions related to transactions that are processed and inserted into the database and with each entry added.

In fact, each of them competes to solve the aforementioned mathematical problem and therefore it is crucial that anything inside the database is available to everyone and updated in real time.

Once the miners have been notified about a transaction, they will process it by looking for a solution to the associated puzzle. The miner who finds the solution to the puzzle first will earn their commission, along with a fixed amount of money (in Bitcoins or fractions thereof).

 

Is everything clear?

So far, you would certainly have some questions. You are probably wondering if you could spend your life mining Bitcoin without managing to solve even one of the mathematical problems proposed. Well, the answer is that it could happen; just like how, in your everyday life, you can be the last in the queue at the ticket booth, you can finish second in a marathon, or you could never win a lottery.

You frankly have a series of technical doubts and still, don’t quite understand how you can get to have a Bitcoin. Furthermore, up until now, mining is just words, nothing factual.

Please don’t give up though, because this long introduction description was crucial because before actually doing things, writing code, downloading packages, configuring machines or any other practical things, we have to understand the operational scenario. (Fig. 2)

 

Fig. 2

 

Now that everything is clear, we can begin: let’s see how to correctly name all the “objects” mentioned above according to the Bitcoin community: the body of the transactions (which can be processed by each minor) is called “block”, and a group of transactions is therefore called block of transactions. The common and shared database is called “blockchain” since it is a chain of sorted blocks. Each of them contains a group of processed and validate transactions. The highly difficult puzzle the miners must try to solve is substantially represented by the output produced by a cryptographic hash function.

Besides, since miners are asked to carry out a high number of attempts in order to find a solution to the puzzle, they say they are proving they have been working hard; this is called Proof of Work, PoW in short.

 

Bitcoin in practice

Now that the Bitcoin background is sorted, we’re going to explain to you how you can be a part of the blockchain, from the comfort of your home. Especially, that’s let’s suppose supposed to use a board from the Raspberry Pi family as the computer and to use the classic Raspbian operating system.

In order to start mining, we first need to update the operating system: it being a Debian-based Linux distribution, Raspbian is based on Aptitude to manage packages (if you haven’t changed it). The update can be done using the following commands:

 

sudo apt-get update

sudo apt-get upgrade

 

When Aptitude asks you to confirm what to update, give your information and wait for the process to end. Then you will have to install the additional packages and related dependencies, using the command:







sudo apt-get install libusb-1.0-0-dev libusb-1.0-0 libcurl4-openssl-dev libncurses5-dev libudev-dev screen libtool automake pkg-config libjansson-dev screen

 

Now you must download cgminer:

 

git clone https://github.com/bitmaintech/cgminer

 

All you have to do now is go to the cgminer folder and carry out some simple operations to properly configure it:

 

cd cgminer

sudo ./autogen.sh

export LIBCURL_CFLAGS=’-I/usr/include/curl’

sudo ./configure –enable-bmsc

sudo make

 

If everything has been done correctly, we are ready to start and all we have to do now is insert the following string:

 

sudo ./cgminer –bmsc-options 115200:0.57 -o XXXXX -u YYYYY -p ZZZZZ –bmsc-voltage 0800 –bmsc-freq 1286

 

Where:

  • XXXXX is the POOL address;
  • YYYYY is your USERNAME;
  • ZZZZZ is your password.

Now you are operational, but keep in mind that if the Raspberry Pi shuts down due to a blackout or a voltage drop under the minimum value, you will have to manually reboot the routine, because only Raspbian reboots at start.

For the automatic reboot of the routine, we have to modify the board’s functioning, by programming it to automatically launch cgminer. To this purpose, you can appropriately edit the file rc.local , keeping in mind that it is found in the “/etc” folder and modifications must be carried out as a superuser (sudo).

 

How much does it cost to mine a bitcoin?

The operations you read about in the previous section have been carried out on five different boards from the raspberry family, which are:

  • Raspberry Pi 1 model A;
  • Raspberry Pi 1 B+;
  • Raspberry Pi 2 B;
  • Raspberry Pi 3 B;
  • Raspberry Pi 3 B+.

 

They are different in terms of available RAM, but also in terms of computational power, which is very limited on version 1 but definitely higher starting from the 2 B+.

Performances and consumptions are crucial determining factors in evaluating how much does it cost to earn a Bitcoin, because mining requires a computer to be constantly active online. Table 1 shows a recap of the relevant technical specs of the tested boards; in the tests, the boards were powered by a 5 V, 2.4 A AC/DC adapter

Table 1

 

From a power consumption perspective, the detected values are reported in Fig. 3; standby values refer only to the starting of the operating system.

Now, let’s try to better understand how much does it cost to mine Bitcoin; starting from the power consumption data, let’s convert mAh to Ah, simply dividing the values by 1.000.

For instance, 310 mAh equals 0,31 Ah; in order to get the corresponding consumption in Watt/hour [Wh], we need to multiply by the voltage value used. In our case, it’s 5 V, which is the operating voltage of our Raspberry Pi. Therefore, in Wh, we are consuming 0,31 x 5 = 1,55 Wh.

 

Fig. 3

 

In order to understand how much does it cost to “produce” Bitcoins we still need two bits of data, because we need to know:

  1. The cost of the energy we consume;
  2. The time needed to mine a Bitcoin.

 

The first piece of information is quite easy to get: you just have to check with your service provider, and you will easily see rates similar to those found in Table 2.

Table 2

 

For simplicity, let’s suppose we round the cost to 0,05 €/kWh, which is 0,00005€/Wh. Let’s also suppose that we don’t have hour ranges, so the rate is flat throughout the day. Under these hypothesis, we would have 1,55 * 0,00005 = 0,000075 €. Well, that is how much it cost to have our Raspberry Pi system running and mining Bitcoins for an hour.

Now we have to answer the second question, but things get really complicated here, because unfortunately, given the mechanisms previously explained, the ever-growing importance of computational power for mining, the increase in complexity of the mathematical problems and heterogeneity of the machines involved, it is not possible to foresee how many hours you will need to keep your system online to add a block to the blockchain. It is worth noting that from this preliminary estimate, some cost factors have been left out, which are deemed minor but are actually all but negligible.

First of all, although it might seem trivial, we have the cost of the board, which is anyways still below €50 in its latest version available.

Then we have the cost of the Internet connection and power consumed by the router. We also have the efficiency of the Raspberry Pi adapter, as well as the decrease in the board’s performance due to the increase of the operating temperature of the SoC during the mining operations; we can solve the issue using passive heatsinks on the processor, however, if you opt for active cooling systems, consumptions will increase even more.

From a computational perspective, we see what is the CPU usage percentage for each of the boards; contextually, we report, thanks to a dedicated graph, how much RAM is used. Values reported in

Fig. 4 and Fig. 5 shows how really difficult it is to use the boards to do other things while they are at work mining Bitcoins. It is worth mentioning that the value reported identify cost factors and performance factors of a single board. When browsing on forms, websites, informational blogs etc., you can often find images of a series of boards, especially Raspberry Pis, from different generations, connected to a network switch and working to mine Bitcoin. It is easy to understand that our observations up until now are valid for each of those boards. The fact that they work at the same time doesn’t decrease the consumption of each one.

 

Fig. 4

 

Therefore, your question will probably be: why should I put them to work all together, within the same network? Well, because putting more boards to work together to mine is just like buying more lottery tickets: your “winning” chances increase. If the whole world mined Bitcoins at the same time, the increase of complexity for the aforementioned problem would be much faster.

So, what are the profit and performance increase margins for the system we have just seen? The first point is definitely the hardware. The ideal situation would be to have a quant architecture available, however, this type of solution is absolutely unavailable to the general public as of now, however, although on a purely theoretical level, it would surely solve the issue of more powerful calculators. The second point is the implementation, which could be optimized and made scalable according to the machine on which the calculation is carried out. Something similar to what happens with graphics engines for video games, where we can choose the level of detail and the resolution of the image in order to execute the same game even on older machines.

 

Fig. 5

 

Conclusions

This article was born with the clear intention to transform economical concepts, which can be objectively very complicated at times, in something much simpler, once the theoretical assumptions are clear, it was incredibly immediate to understand what was created by the technique. We are on the verge of the beginning of a new economic era which has, as a foundation, digitalization pushed by the concept of exchange itself. After analyzing this futurist scenario, we have seen and touched with hand what could it mean to use a virtual currency, trying to become part of the blockchain, but also mining a Bitcoin. Everything starting from a low-cost hardware platform, i.e. Raspberry Pi. We have seen the main steps to make the board operational, analyzed its performances and projected the long-term cost of a Bitcoin, in order to have an idea of how economically sustainable could be, for a private citizen, to mine a Bitcoin and, subsequently, why there are entire establishments where people work with an impressive array of very high-performance calculators with the sole purpose of creating additional blocks for the blockchain.

After all, the blockchain is no longer something far away from the financial field, because last May, the first transaction based on this technology took place between two banks (HSBC and ING) and this could pave the way for large-scale deployment.

 

From openstore

Raspberry Pi 3 Model B with Wi-Fi and Bluetooth

Raspberry Pi 3 Model B+



jlcpcb.com



https://2019.makerfairerome.eu/en/

About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.