Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Solution Thumbnail

Algorand on low-power devices based on STM32 MPU

Overview

This work and master degree thesis demonstrates how it is possible to use Algorand on two of the most spread low-power IoT devices such as the Raspberry Pi 4 Model B and the STM32MP157A-DK1, a discovery kit that is part of STMicroelectronics STM32 family.

Abstract

Through the use of sensors and other edge devices and infrastructure, IoT is transforming people lives also revolutionizing the way enterprises operate. Although, one of the major challenges revealed in the usage of IoT functionalities regards the need of protecting collected information at all levels of IoT ecosystems. Unfortunately, also due to the growing number of connected devices, data security has become extremely complex.

One of the revolutionary technologies that have the potential to address some of the IoT security, privacy, and scalability challenges is blockchain technology. Therefore, this work discusses the integration of IoT systems and blockchain technology with a specific focus on low-power devices enhanced through the functionalities of Algorand.

A scientific article was presented in September at an International Conference called SpliTech that deals with technology, theory, and application aspects of E-Health, Smart Environment/City, Energy and Engineering Modelling.

EditorImages/2021/06/24 17:07/netdata.jpg

Introduction

For years now, our way of interacting, working, studying, managing our time and our hobbies has changed thanks to advent of the Internet which has fostered an innovative future that has already become reality. Thanks to its spread, in fact, information became more accessible and usable, communications got faster and simpler, and technological innovations have been introduced to optimize the agendas and business processes. Different sectors have already benefited from the introduction of Internet in their daily lives and, specifically, thanks to the latest technological progress, also the industrial and electronic sectors have been improved leading to a model shift in manufacturing efficiency and operational cost reduction.

Generally, this cost reduction comes at the price of dismissing information security, especially when multiple stakeholders are involved. The promise of a strongly connected world, where previously inactive devices become “smart”, has driven a boom in the uptake in IoT technology over the past years. IoT involves the extension of internet connectivity beyond personal computers and mobile devices and can reach a wide range of non-internet enabled devices. Once the devices have been embedded with technology, they are brought to life and can communicate with each other, this means they can be monitored and controlled remotely.

The Internet of Things (IoT) paradigm is envisaged as one of the most disruptive concepts in the near future, with large technological, societal and economic impacts. The term Internet of Things describes the large and growing set of digital devices that operate across networks of potentially global scale. Massive IoT applications involve a large number of low-cost devices, portable/wearable, and they often transmit small data volumes and have little energy consumption requirements. Some of these applications are smart health, smart metering, transportation fleet management, smart buildings, monitoring of large infrastructures or industrial plants, agriculture or natural ecosystems. The ever-increasing number of IoT devices requires a secure and scalable infrastructure to store and process generated data.

In recent years, the Distributed Ledgers Technologies (DLT) and related tools such as blockchain, have gained momentum as solutions in such scenario. In fact, their decentralized and cryptographically secured nature offers new means of securing networks, storing data permanently, increasing transparency, and reducing fraud and abuses of privacy which become increasingly common.

Different companies and researchers are in fact investing time and effort in the exploitation of such technologies in their daily activities. Although, the spread and the consequent increasing advances in DLTs is also raising the knowledge base needed by new companies looking at this market to benefit from the integration of those technologies.

Low-power IoT end-devices do not possess enough resources to run a software client for intensive calculations, so the purpose of this work is to investigate on existing possibilities to enable low-power IoT devices in accessing a blockchain-based infrastructure that, instead, is usually a high energy consuming technology.

For the purposes of this work, the Algorand blockchain was selected for all the performed activities due to its inclination towards the IoT domain. In fact, although Algorand propounds a bright horizon for financial purposes and lacks several features to be successfully applied to IoT networks, its characteristics are appealing for IoT. Indeed, its self-sustaining and decentralized based network already supports a wide range of applications. In addition, it does not require communication among users to determine if they are selected to participate in the consensus protocol and it does not postulate computational resources to solve cryptographic puzzles. These characteristics alongside with decentralization, high scalability, and security are attractive features for IoT.

Within the described context, this work aims at investigating the applicability of the Algorand to the IoT domain and specifically demonstrate the benefits of its application to low-power devices. Different experiments have been conducted: some low-power devices were configured to operate as Algorand nodes and some transactions have been added to the distributed ledger by implementing all the requested cryptographic functions, communication functions, and specific operations. Finally, a performance analysis among all the tested low-power devices is carried out to analyze on which device Algorand performs better using Netdata, a system that helps collect all possible metrics from systems and applications, visualize these in real-time, and troubleshoot complex performance problems.

Low-power devices

As Industrial, Consumer, Smart Home, Health and Wellness systems are growing and are becoming more connected also due to the spread of IoT, certain embedded designs are now required to manage high processing loads and complex applications with rich Human Machine Interfaces (HMI). However, in many IoT applications, to keep costs down, human-machine interaction is reduced to a minimum. Under these conditions, the ability to harness open-source software stacks while maintaining low power and real-time performance are key requirements. One of the most important companies in the world that provides solutions for embedded systems and IoT is STMicroelectronics. Within this work, only low-power devices are used and specifically one of these is part of the STM32 (STMicroelectronics) family general-purpose 32-bit microprocessors (MPUs) based on the heterogeneous architecture combining Arm Cortex-A and Cortex-M.

In this work the STM32MP157A-DK1 has been used, a discovery kit designed as complete demonstration and development platforms for STMicroelectronics Arm-based dual Cortex-A7 32 bits and Cortex-M4 32 bits MPUs in the STM32MP1 Series and their STPMIC1 companion chip. The STM32MP157A-DK1 board neither include the “WLAN + Bluetooth”, nor the MB1407 daughterboard DSI display (available on STM32MP157C-DK2 board), so the connection to the device takes place through Ethernet.

This discovery kit using STM32 MPU OpenSTLinux Distribution that is a subpart of the STM32 MPU Embedded Software distribution, a set of software, system build and development tools created to ease the development to be done on top of STM32 MPU devices.

EditorImages/2021/05/23 18:55/DK1-front.jpg

Another device used within this work to make performance comparisons is the Raspberry Pi 4 Model B that offers increases in processor speed, multimedia performance, memory, and connectivity compared to the prior generation Raspberry Pi 3 Model B+. This Raspberry model includes a Quad Core Broadcom BCM2711 (Cortex A-72) (ARM v8) with 4 GB LPDDR4-2400 SDRAM memory and the operating system installed is Debian-based Raspberry Pi OS (Buster 32-bit Release).

EditorImages/2021/05/23 18:55/raspberry.jpg

Requirements

To test the applicability of Algorand to low-power devices, different operations have been performed:

  • Synchronize to Algorand Network
  • Perform write operations
  • Perform read operations
  • Performance analysis

At first, to perform operations on the Blockchain, the node must be perfectly synchronized. In addition, the Blockchain is designed to be an append only structure. A user can only add more data, in the form of additional blocks and all previous data is permanently stored and cannot be altered.

Therefore, the only operations associated are write operations to add data and read operations that query and retrieve this data from the Blockchain.

To make comparisons on the boards, the same type of Algorand node was installed, Non-Relay non-archival, using it to perform some features of this Blockchain, in particular synchronization of node, creation of the wallet and related accounts, participation key for helping to support the consensus protocol, private network, transaction, Atomic Transfers, and Algorand Standard Assets.

The image below shows where a Non-Relay non-archival node has been installed on STM32MP1 board to use the Algorand testnet.

EditorImages/2021/05/23 19:19/filesystem.jpg

root@stm32mp1:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        148M     0  148M   0% /dev
/dev/mmcblk0p6  690M  443M  202M  69% /
tmpfs           214M   64K  214M   1% /dev/shm
tmpfs           214M  8.7M  205M   5% /run
tmpfs           214M     0  214M   0% /sys/fs/cgroup
tmpfs           214M   84M  130M  40% /tmp
/dev/mmcblk0p4   58M   14M   40M  26% /boot
/dev/mmcblk0p5   15M  6.8M  6.7M  51% /vendor
tmpfs           214M  148K  214M   1% /var/volatile
/dev/mmcblk0p7   57G  315M   54G   1% /usr/local
tmpfs            43M     0   43M   0% /run/user/0

Implementation

The setup topology is shown in the below image where a notebook has been used for remote work on the boards using the SSH protocol and low-power devices are connected through Ethernet cable on the network ports of the modem/router with a home connection where the nominal bandwidth is 20 Mbit/s in Download and 1 Mbit/s in Upload.

EditorImages/2021/05/23 19:19/topology.jpg

The connection to Algorand takes place through algod client that requires a valid algod REST endpoint IP address and algod token from an Algorand node that is connected to the network. To create a transaction, Atomic Transfer, and an ASA, the AlgoSDK was used, a Java library for communicating and interacting with the Algorand network.

// Create an algod client
import com.algorand.algosdk.v2.client.common.AlgodClient;

final String ALGOD_API_ADDR = "http://192.168.1.72";
final Integer ALGOD_PORT = 6001;
final String ALGOD_API_TOKEN = "62569290418bdd347a5df5fe9bb191a79aa89124fdda23541a4c1dc36bf3d335";

AlgodClient client = new AlgodClient(ALGOD_API_ADDR, ALGOD_PORT, ALGOD_API_TOKEN);

In the implementation and unit testing phase, the Algorand testnet has been used and a service called dispenser to obtain testnet ALGO tokens which have no monetary value, but only to allow development on the test network.

Results

STM32MP157A-DK1 Transaction

Transactions require a certain minimum set of parameters to be valid and mandatory fields include the round validity range, the fee and the genesis hash for the network for which the transaction is valid. The private key is required to sign the transaction and this creates a new transaction object signed using the SDK, sending it to the network with the algod client.

// Construct the transaction
final String RECEIVER = "7ZEEEYMRYL2HIXQBRIBG6TDSJPOAJXL5JONCY7RC5WXVZL7RUDRW4H3WJ4";
String note = "First STM32MP157A-DK1 Transaction";
TransactionParametersResponse params = client.TransactionParams().execute().body();
Transaction txn = Transaction.PaymentTransactionBuilder()
.sender(myAddress)
.note(note.getBytes())
.amount(10000000)
.receiver(new Address(RECEIVER))
.suggestedParams(params)
.build();

The transaction was confirmed and written to the Algorand blockchain in less than 5 seconds:

Signed transaction with txid: TS46PNQUS45DXBWHTXBYRM63GIGXY4FLIOKLZENGWJGFCOM6DU4Q
Successfully sent tx with ID: TS46PNQUS45DXBWHTXBYRM63GIGXY4FLIOKLZENGWJGFCOM6DU4Q
Transaction TS46PNQUS45DXBWHTXBYRM63GIGXY4FLIOKLZENGWJGFCOM6DU4Q confirmed in round 11800831

STM32MP157A-DK1 Atomic Transfer

Atomic Transfers are implemented as irreducible batch operations where a group of transactions are submitted as a unit and all transactions in the batch either pass or fail. Just like any other transaction, an atomic transfer can contain ALGOs or Algorand Standard Assets. Combining transactions just means concatenating them into a single file or ordering them in an array so that a group ID can then be assigned.

// Get node suggested parameters
String note1 = "First Atomic Transfer with STM32MP157A-DK1";
String note2 = "First Atomic Transfer with STM32MP157A-DK1";
TransactionParametersResponse params = client.TransactionParams().execute().body();        

// Create the first transaction
Transaction tx1 = Transaction.PaymentTransactionBuilder()
.sender(accountA.getAddress())
.note(note1.getBytes())
.amount(30000000)
.receiver(accountC.getAddress())
.suggestedParams(params)
.build();

// Create the second transaction
Transaction tx2 = Transaction.PaymentTransactionBuilder()
.sender(accountB.getAddress())
.note(note2.getBytes())
.amount(30000000)
.receiver(accountA.getAddress())
.suggestedParams(params)
.build();

// Group transactions an assign ids
Digest gid = TxGroup.computeGroupID(tx1, tx2);
tx1.assignGroupID(gid);
tx2.assignGroupID(gid);

The Atomic Transfer was confirmed and written to the blockchain in less than 5 seconds:

Successfully sent tx with ID: D55DP6HCNT5MFT652RWQYTEV7WRW4X6CNNTYKPRGRICFPNXZLF3Q
Transaction D55DP6HCNT5MFT652RWQYTEV7WRW4X6CNNTYKPRGRICFPNXZLF3Q confirmed in round 11839043
Group ID: p6KbKj7ZhrVDtbQYAygwlgsyd/DkISebffyze7TEVpM=

STMicroelectronics ASA

Algorand Standard Assets are highly customizable with parameters that allow to define total issuance of an asset, name of asset, units of an asset, as well as access controls privileges over an asset.

// Create the Asset
TransactionParametersResponse params = client.TransactionParams().execute().body();

Long assetTotal = 1000000000000000L;
String unitName = "STM";
String assetName = "STMicroelectronics";
String url = "https://www.st.com/";
Address manager = account1.getAddress();
Address reserve = account1.getAddress();
Address freeze = account1.getAddress();
Address clawback = account1.getAddress();
int decimals = 6;
Transaction tx = Transaction.AssetCreateTransactionBuilder().sender(account1.getAddress()).assetTotal(assetTotal).assetDecimals(decimals).assetUnitName(unitName).assetName(assetName).url(url).manager(manager).reserve(reserve).freeze(freeze).defaultFrozen(false).clawback(clawback).suggestedParams(params).build();

In this case an Algorand Standard Asset called STMicroelectronics has been created, with unit name STM and 1 billion total number of base units:

Transaction ID: 2D23KLFZWUJ63WB5C6KWIDGCVRYPG4DMHU2BIUHNVNPL5WCWDPPQ
Transaction 2D23KLFZWUJ63WB5C6KWIDGCVRYPG4DMHU2BIUHNVNPL5WCWDPPQ confirmed in round 11814703
AssetID = 13604364

Key Registration Transaction

What distinguishes this as a key registration transaction is “type”: “keyreg” with the existence of participation key-related fields, namely “votekey” that is the root participation public key, the VRF public key “selkey”, the dilution for 2-level participation key “votekd” and “votefst”/“votelst”, respectively first and last round that the participation key is valid. The values for these fields are obtained by dumping the participation key info on the node where the participation key lives:

Transaction id for status change transaction: RKS5CCOWIC5XA6ZQI4OVOX63QUCIDTV7J76J2ALTLQI6QAYRB33A
Transaction RKS5CCOWIC5XA6ZQI4OVOX63QUCIDTV7J76J2ALTLQI6QAYRB33A still pending as of round 11208301
Transaction RKS5CCOWIC5XA6ZQI4OVOX63QUCIDTV7J76J2ALTLQI6QAYRB33A committed in round 11208303

Also in this case, a Key Registration Transaction was confirmed in less than 5 seconds to the Algorand blockchain.

Performance Analysis

To have greater clarity how the devices work using the Blockchain Algorand, Netdata was used to visualize total CPU utilization (all cores) and bandwidth from the Ethernet interface of the STM32MP157A-DK1 board in the various processes of synchronization of the node with Fast Catchup feature that rapidly updates it using snapshots, shortening the entire node sync (the same method was used with the Raspberry Pi 4 Model B board). An important thing is that sync times may vary depending on the number of accounts, number of blocks, technical specifications of devices, and the network.

In the first phase of the synchronization, we process the total number of accounts included in the current catchpoint. There are four components to consider for analysis: system, user, iowait and softirq.

  • system: This component is the proportion of time the CPUs spent inside the Linux kernel for operations like context switching, memory allocation, and queue handling.

  • user: This component is the time spent in the user space (high value of user time indicate a CPU bound workload).

  • iowait: This component is the time the CPU spent waiting for disk IO requests to complete.

  • softirq: This component is the portion of time the CPU spent servicing software interrupts generated by the device drivers.

It should be considered that if iowait is constantly high, disks are a bottleneck and they slow the system down. Furthermore, a constantly high percentage of softirq may indicate network driver issues (the network devices are generally the main source of high softirq values).

In the second phase, we verify the number of accounts from the current catchpoint as part of the catchup (by default Non-Relay nodes only store a limited number of blocks locally.)

In the third phase, we download the total number of blocks that are required to complete the current catchpoint catchup and the fourth phase consist to download the remaining blocks from that point to the current block.

In the fifth and last phase, when the node is caught up with the rest of the network, the “Sync Time” is 0.

Taking a general look in terms of performance analysis, as shown in the table, the greatest CPU bound workload happens when it downloads the number of blocks until the node is fully synchronized, which from then is less stressful. All synchronization phases are performed using the other low-power device, the Raspberry Pi 4 Model B, and also in this case reaches almost the same result.

EditorImages/2021/09/17 13:26/table.jpg

Conclusions

This work aimed at demonstrating the applicability of the Algorand blockchain to low-power IoT devices without any modification to hardware or software components of the chosen devices and blockchain. Specifically, the study was focused on two of the most spread IoT devices in the market: the STMicroelectronics STM32MP157A-DK1 discovery kit and the Raspberry Pi 4 Model B.

After a comprehensive analysis of the application of the Blockchain on IoT devices, some experiments were designed to test the applicability of Algorand on the selected low-power IoT devices. The results show that both devices are ready for the use of the Algorand Blockchain on low- power IoT devices. In addition, the experiments demonstrate that they are also capable of publishing transactions to the Algorand blockchain in a few seconds.

You can find the repository of this work, with master degree thesis, on GitHub