2018年5月26日土曜日

Demonstrating Block Chain with a set of micro:bits using radio

Currently, blaockchain, which is the basic technology of crypto currencies, attracts attention. Below is an example that lets us easily learn the basics of Bclockchain technology using micro:bit.


micro:bit radio-blockchain

https://makecode.microbit.org/projects/micro-coin

Although this is not practical, it is convenient for us to experience the following basic technologies:
  • Structure of the block which is an element of blockchain, especially storage of hash value on previous block information
  • Broadcasting of newly added block information which is required after new crypto currency is obtained
  • How to add a new block to the chain
  • Mechanism to maintain only one consistent block chain

The following experiments were conducted basically in accordance with the above url. However, we use six micro:bits under the wireless network.  In addition, I have created an original method to display the number of coins on the LED.  Next figure illustrates the experiment.


In the figure below, the micro:bit in the lower left corner got a new coin. In the real world of crypto currency,  in order to obtain new coins,  it is necessary to solve certain problems (that is,  proof of work).  However,  here,  for the sake of simplicity,  it is possible to obtain a coin stochastically by using random number generated when macro:bit is shaken.  The micro:bit that got the coin creates a new block,  adds it to the chain,  and broadcasts it to other micro:bits.  In the figure,  one flashing LED means broadcast,  and two flashing LEDs indicate that the micro:bit  has received it.

One micro:bit that obtained a coin broadcasts its information

The following figure shows the number of coins currently held by each node (micro:bit). You can display this information by pressing button A on each node. Each of the three nodes has one coin and the other one node holds three coins.

the number of coins that have been obtained by each micro:bit 

Next, we verify that the block chain known to each node is only one legitimate one. As a simple way to show it, the length of the block chain known to each node is displayed. Press button B on each node to display it. Here, all nodes indicate 6 (= 1 + 1 + 1 + 3). This is a proof of integrity that there is only one legitimate block chain.


the length of the block chain each micro:bit can see (6 blocks)


The micro:bit program (blocked JavaScript) that realizes the above is shown in the figure below. In this, readio-blockchain for exchanging block information is used. It is published in the following URL:

https://makecode.microbit.org/pkg/microsoft/pxt-radio-blockchain

In addition, I created my own custom blocks to display on the LEDs the number of coins and the length of the chain.


micro:bit program that demonstrates  block chain

radio-blockchain components

custom JavaScript blocks for showing numbers on the LED

The above was done using 6 actual micro:bits. However, before that, you can also check the operation by simulation. This simulator works very well. As shown in the figure below, for example, you can simulate an operation to obtain coins by shaking micro:bit. Here, when you shake the microbits on the right side, the image of micro:bit is distorted, so you can get a sense of reality.


showing the number of coins in the simulation

shaking to get a coin in the simulation

0 件のコメント:

コメントを投稿