Smart-Contract Storage for Ethereum

The year 2018 is the year of cryptocurrency's meteoric rise in popularity. The fact that the number of Ethereum addresses in use is growing every day is a good example of this. More users means more money entrusted to the Ethereum blockchain, which is where they keep their money.


As of May 23rd, 2018, the Ethereum platform had a market valuation of $64 billion USD. In addition, Ethereum tokens, which are among the top 100, have surpassed $39 billion in value.


This necessitates learning how Ethereum storage works and what can be stored there in order to comprehend what happens to money after it is entrusted to the Ethereum blockchain.


First and foremost, let us understand more about the Ethereum platform.


What Is Ethereum and How Does It Work?

Ethereum is a decentralised computing platform based on the Ethereum blockchain that permits the execution of programmes written in the Solidity contract-oriented programming language.


In a nutshell, Ethereum is a network that allows a large number of computers to work together to create a true "supercomputer" that democratises the present client-server architecture. Instead of servers and clouds, it uses thousands of “nodes” managed by volunteers all over the world.


Ethereum facilitates the execution of insurance contracts, the trade of financial instruments, and the storage of data. It gives all users an equal chance to offer services on top of this infrastructure. Users can download and instal a variety of applications on their computers, but they rely on a corporation (or another third-party service) to keep their credit card information, purchase history, and other personal data, which means those parties have access to all of it.


Allowing all users access to an open network allows data theft, leaks, and potential alterations to users' private information without their knowledge. Users' personal information is stored on clouds and servers owned by firms like Amazon, Google, and Facebook. These organisations provide a range of benefits, such as protected data and no hosting or uptime expenses, but they also expose the entire computer system to threats.


Furthermore, third companies like as Google and Apple allow programmes that are solely managed by them (Evernote, Google Docs, iTunes).

Ethereum is a game-changing technology that enables us to withstand the risks that online third parties pose to users. Ethereum gives individuals back ownership of their personal data while also granting them creative liberties. The basic concept is that third-party companies will not be able to modify user data. Each node on the network will notice the changes if the data owner saves modifies, adds, or deletes notes.


From a software standpoint, Ethereum consists of a set of accounts, each of which has a balance (in Ether).


After creating an Ethereum wallet, a user can carry out transactions, send Ether to other users, and execute smart contracts.


Ethereum's transaction processing system consists of the following components:


  • a state: a collection of all accounts and their respective balances

  • a business deal

  • a new state: a new set of accounts with updated balances

Each account has a physical address as well as a balance. In Ethereum, there are two sorts of accounts: user and smart-contract. A smart contract is a digital asset that can store data, hold Ether, and execute functions on the Ethereum Virtual Machine (EVM).


What Is an Ethereum Array, and How Does It Work?

The Ethereum Virtual Machine (EVM) runs all smart contracts and stores their state in its own permanent storage. Ethereum storage is a massive array that holds no data at first. The array's values are 32 bytes wide. There are a total of 2,256 values. At every point in time, smart contracts can read from or write to a value.


Because zero takes up no space, all values can be restored simply setting them to zero. The amount of gas used to set a value to zero is refundable.


Finding Values of a Fixed Size

A known variable with a fixed size is assigned to a specific storage location. Slots (specified positions of values within the storage) are created using the Solidity programming language:



values are stored in precise locations within the storage“a” value is saved in slot 0

Slots 1 and 2 are used to hold “b” values.

The “c” value is stored in slot 3, while the entry structure stores two 32-byte values in the following slots.


The slots are created during the compilation process, and their order is determined by the order in which the variables occur in the contract code.


Values that are dynamically sized

To preserve their sizes and elements, dynamically-sized arrays require locations.


Only the data that the dynamically-sized array "d" has inserted into slot 5 is saved. Starting with the hash of the slot, the array keeps the values in order.



Note that reserved slots cannot be used in dynamically-sized arrays or mapping because the number of slots to reserve is unknown. To repeatedly compute locations for dynamically-sized variables, Solidity uses a hash function.


Mapping

The requirement in mapping is to find the location associated with a particular key. We can hash the key, but keep in mind that different mappings should produce different results.



There are no lengths or personal values saved in slots 6 and 7. Mapping“e” value is placed in slot 6, and “f” value is placed in slot 7, but there are no lengths or personal values recorded in those locations.


By hashing the key and the mapping's slot, it is possible to find the location of a specific value within mapping.


By recursively applying the calculations, we may combine dynamically-sized arrays and mappings to identify a value's position.


Items can be found in the following complex types.


What Kinds of Information Can Be Stored in Ethereum's Storage?

Let's start by determining what kind of data we can store in order to run a blockchain network. Here's a simple transaction example:



Trace the balances and other data from different customers, as well as each piece of data that is running on the blockchain; for example, transactions. Every platform works in a unique way. Let's take a look at what's going on with the Ethereum platform.


Ethereum is a transaction-based “state” machine, which means that it may be used to build any transaction based on state-machine notions. It all begins with its own genesis block. The status of the Ethereum blockchain is continually changing due to transactions, contracts, and mining. An account balance maintained in a state tray, for example, recalls all changes made throughout transaction execution.


Every account in the Ethereum system has a key and value pair provided by the state trie, or Merkle Tree. A single 160-bit identity serves as the "key" (the address of the Ethereum account). The “value” in the state trie is created by using the recursive-length prefix (RLP) encoding method to encode the following Ethereum account details:

  • nonce

  • balance

  • storageRoot

  • codeHash

The root node of the state trie (a hash of the current state trie) can be used to identify the state trie; the root node of the state trie is cryptographically dependent on all internal state-trie data.



The storage trie is where contract data is stored, and it contains a hash of the current state trie. Every user has their own storage trie. A storageRoot value in the global state trie is a 256-bit hash of the storage trie's root node.



The transaction trie is included in every Ethereum block and stores the value of storageRoot in the global state trie. The order of transactions in the block is determined by the miner who governs the block.



The transaction trie's index can be used to find a specific transaction in the transaction trie. Because mined blocks are immutable, a transaction will always have the same location. You'll use the same path to the transaction every time you require it now that you've discovered its location.


The Ethereum blockchain directly maintains the root node hashes of transactions, states, and receipts; however, it does not allow for the storage of data such as account balances.



In the system above, the root node hash of Ethereum storage, which stores all smart-contract data, identifies the state trie that leads to the blockchain.


Two types of data are stored on the Ethereum blockchain:


  • Permanent (e.g., the record of a transaction that has already been confirmed and cannot be changed)Ephemeral (e.g., the record of a transaction that has already been confirmed and cannot be changed) (e.g., the balance of a particular Ethereum account address that the storage keeps is changed after every individual account.)

  • To manage each of these forms of data, Ethereum structures and stores them separately.

We can compare Ethereum's record-keeping system to the type of ATM/debit card that banks use to keep track of how much money each debit card has. This informs the card's owner whether the card has sufficient funds before confirming the transaction.


Various Ethereum Attempts

To store their tries, Ethereum clients mostly employ two separate database software solutions:


Rocksdb

RocksDB is based on LevelDB and is designed to run on servers with several CPU cores, efficiently utilise fast storage, support IO-bound, in-memory, and write-once applications, and be flexible enough to allow for innovation. Many of the flaws of LevelDB are addressed in RocksDB. Furthermore, the usefulness has been much enhanced. Facebook, Yahoo, LinkedIn, Airbnb, Pinterest, Uber, and Netflix are just a few of the well-known RocksDB users. RocksDB is also used in projects such as CockroachDB, TiDB, and Apache Flink.


Leveldb

Leveldb is a platform-permanent data storage that is often used for system logging. It's an open-source Google key-value storage library with features including forward and backward data iteration, ordered mapping from string keys to string values, custom comparison algorithms, and automated compression. Automatic data compression is provided by the open-source Google compression/decompression library "Snappy." This database is used by GoLang, C++, and Python clients.


Data Encoding

Because the Ethereum blockchain employs its own unique Modified Merkle Patricia Tree implementation during leveldb execution, it delivers encoded results when a user searches it.


The Ethereum Wiki has details on the design and implementation of Ethereum's Modified Merkle Patricia Tree and Recursive Length Prefix (RLP) encodings.


Because Ethereum employs a tree data structure, the Modified Merkle Patricia provides a means of "extending" a node so that the descent can be sped up.


One of the following is a Modified Merkle Patricia tree node:


  • a null string (referred to as NULL)

  • There are 17 elements in this array (referred to as a branch)

  • an array with two items in it (referred to as a leaf)

  • an array with two items in it (referred to as an extension)

  • To inspect all tries

it is recommended that you utilise computer code. For example, we can utilise ethereumjs, which implements Ethereum's virtual machine in Javascript and has easy-to-use repositories. They can also be used to connect to the Ethereum leveldb database.





It's worth noting that Ethereum accounts can be added to a state trie after a transaction has been found. If you use the field "get account new" to establish a new account, it will not be included in the state trie. This is also impossible, even after numerous blocks have been mined.


If a transaction is successful (costs gas and is located in a mined block), it is logged against that account, and the state trie is updated accordingly. This feature protects the state trie from hacker assaults that create new accounts and bloat it.


Problems with Storage

Rapid database growth is one of the most common concerns users confront, resulting in high storage costs. All of the computations memorised by the computers are stored in the database, also known as the Ethereum state. The cost of storing the database is steadily rising, making complete nodes unaffordable for an increasing number of users. As a result, the network can be transformed into a centralised one, with only a few people having access.


Ethereum developers have implemented some very successful protocol-level enhancements, such as sharding to reduce database size.

Geth and Parity recently produced the following modifications to deal with other concerns.


To begin, they proposed removing temporary files from the network history in order to save space. Since last summer, Ethereum has been unable to use hard drive due to high synchronisation times. This update enables entire nodes and Ethereum software to run on a hard disc rather than a solid-state device, resulting in faster synchronisation times (SSD). This has elicited a flurry of favourable feedback from Ethereum users.


Alexey Akhunov, an independent developer, proposed a second update: redesigning the geth client (“turbo geth”) to streamline the whole state procedure. According to him, software adaption can assist operate random access memory (RAM) more faster and allow users to instantaneously synchronise with the network.


Ethereum can also create "stateless clients" that store a compressed version of the overall state. These clients can keep their data if they don't need access to storage from files or block validation. Pruning outdated, useless data, empty or long-inactive accounts, and check processing time will all result in significant savings. There are also issues with code operation: coordination issues that must be resolved in order for the code to continue to function as intended.


The Constantinople update, set to be implemented in October 2018, will present Ethereum users with a new challenge: balancing a network of various stakeholders. The 'difficulty bomb,' a piece of code from the Constantinople update, was created to encourage the platform to adopt new technology. However, it has the potential to make mining blocks less efficient over time. To enable for the execution of transactions and the operation of the blockchain as intended, special procedures should be taken.


The delay in releasing the difficulty bomb had a detrimental influence on Ether inflation; as a result, the Ethereum platform's code must be updated before the difficulty bomb is released.


There are three options for improving Ether inflation (EIPs): EIP 145, EIP 1014, and EIP 1052 will speed up contract verification by facilitating state channels.


Some clients believe that the Constantinople upgrade should also limit the amount of Ether supplied to miners, who use specialised processing hardware to ensure transaction security. ETH traders share this viewpoint, believing that it will help to maintain the currency's and network's value.


Miners have responded by claiming that a fall in their remuneration will lead to a decrease in the Ethereum platform's security.


Also, to avoid some technical concerns, learn more about smart contract faults and dangers during implementation.


Conclusion

We may conclude that Ethereum provides an excellent alternative storage for transactions involving third-party organisations after learning how the Ethereum network and its storage work.


People today prefer to utilise a decentralised programme over a centralised one, as evidenced by the fact that the number of Ethereum supporters is always expanding. This indicates that the blockchain-based technology era will last for a long time. By the way, you have a fantastic opportunity to work with the Cryptoauxiliary team to create your own smart contract that complies with all of your country's legislative standards.


1 view0 comments