6

Distributed Ledgers: The Next Logical Step

 3 years ago
source link: https://hackernoon.com/distributed-ledgers-the-logical-next-step
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Distributed Ledgers: The Next Logical Step

Roman Nguyen from RSquad, one of the developers of the Free TON blockchain ecosystem, talks about how modern blockchains approach the problem of data storage in decentralized systems. FreeTON offers an elegant solution to this problem, he says. The data structure itself has existed since time immemorial and has been used successfully in both centralized and decentralized systems, including blockchains. In FreeTON's different approach is a hash of the public key (can be taken as part of the code of the smart contract) and the address itself, the address of the key is calculated from the same code of initial data.
Free TON

Innovative, ultrafast, free blockchain platform

This is the second article of the series; the first one was about True NFT. This time, Roman Nguyen from RSquad, one of the developers of the Free TON blockchain ecosystem, talks about how modern blockchains approach the problem of data storage in decentralized systems and what advantages such a complex has in comparison with the existing model of token transfer.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

What is a Distributed Ledger?

If we talk about distributed ledger systems as such, there are a lot of implementations — from torrents and IPFS to blockchains. The approach is not new, and, lately, it has been increasingly developing towards blockchains. Blockchain, as a technology, solves a number of diverse problems, from ensuring the reliability of information to its storage. As a rule, these are the regular “key-value” pairs, where some identifier corresponds to a certain value. For example "number-balance", "name-status" or "domain name-address". In any blockchain with smart contracts, we will have similar structures in one way or another.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

What's the Problem with Regular Ledgers?

In general, nothing at all. The data structure itself has existed since time immemorial and has been used successfully in both centralized and decentralized systems, including blockchains. However, in blockchain any action (except reading) costs something, and in some blockchains, such as FreeTON, data storage is not free either.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

In terms of data storage, the key problem is always the limitations of the media — a conditionally infinite ledger requires a conditionally infinite amount of storage. In real life, we can think of a large data center as a kind of single media, which, if necessary, can be expanded. In decentralized systems (blockchains with smart contracts) this approach is not possible.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

It is simply impossible to store an infinite amount of data in one contract: we will inevitably run into, for example, the size of the block or catch a collision, which will lead to unpredictable consequences. This is the same as in real life, not adding new media to the data center, but building another one nearby. The comparison is very abstract, but it illustrates the situation.

Additionally, existing ledgers in blockchains, as a rule, are a large smart contract that supports a complete list of records or a tree-like solution that splits the list into parts based on certain parameters. Such solutions disappear due to lack of scalability, high maintenance costs, long search time with increasing data volume, single point of failure, and so on.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

So What To Do?

  • A set of criteria that a solution must meet:
  • it must be able to store data in key-value format;
  • it must be conditionally infinitely scalable;
  • it must perform crud (create read update delete) operations;
  • the user experience of interacting with the solution should not differ from that of regular ledgers.

The first thing that comes to mind is that the ledger records should be divided into some parts, which will not exceed a certain maximum possible size. But creating a mass of contracts with ledger parts makes no sense, they need to be linked somehow.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

You can create a blockchain on a blockchain and try to link the records to each other — that way, each record will have one or two links to similar records and will represent something like a table row. But in this case, you will have to deal with the issue of deleting and creating records, which will entail changing not only the record on which the operation is performed but also others.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Creating a central contract and remembering record references is also not suitable - even an array of line references can be conditionally infinite within one contract.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

That leaves one thing — the records must be linked somehow, while not remembering the links to them. It would be nice to come up with a way to search and verify records, as well as to create and provide irreplaceable records, without having to remember the parts.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Sounds like a fantasy, but Free TON offers an elegant solution to this problem. 

0 reactions
heart.png
light.png
money.png
thumbs-down.png

In regular blockchains, the contract address is usually either a public key or some hash from it. In Free TON it's different. The address is a hash of the public key (can be taken as part of the initial data), the code of the smart contract itself, and the initial data.

Since all addresses are calculated from the contract code, public key, and initial data, we can deploy the same contract code with the same public key (usually zero), changing only its initial data. This allows you to calculate a contract address from anywhere by specifying a unique identifier in the initial data. The principle remains — we, as in a centralized ledger, can get the address of the contract, which contains data, by a unique identifier without creating a ledger as such, while completely excluding the possibility of replacing a child contract. In the latter case, when you change the address of the child contract will also change the code, leading to a change in subsequent addresses.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

That is, if we put a unique ID in the contract initial data, we will get a unique address.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

In general, the ledger will look like the following scheme:

0 reactions
heart.png
light.png
money.png
thumbs-down.png

But how do you get a record? The client accesses the root smart contract, which already contains the child contract code, transfers the initial data (in our example, only the identifier), and calculates the contract address. It turns out the address of the contract - an identifier that points to a ledger string.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

This approach is not only possible by changing the initial data, the code itself can also be changed. A "salt" code has been added to TIP-31, which makes it possible to change the contract code without changing its functionality by adding some data structure directly to it. This is useful if you need to separate ledger lines in two different ledgers and when searching for a contract by code hash.

Issues and Security

But how do you solve the problem of "fake" contracts that can be deployed with the same parameters without referring to the parent contract? 

0 reactions
heart.png
light.png
money.png
thumbs-down.png

To do this, all child contracts write the address of the parent contract in the initial data in addition to the ID. This gives you the ability to check in the constructor when deploying a contract, who deploys that contract, and whether it is parental, otherwise the message is rejected.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

If this verification is removed and the contract is recompiled, the contract code will change, which will still lead to the wrong address in terms of the parent contract.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

________________________

The described approach allows you to look at the blockchain from an unfamiliar angle - as a database storing the format [contract code, initial data] -> contract address. This opens the door to the world of distributed ledgers of unlimited scalability, which will undoubtedly lead to the creation of a new generation of distributed ledger systems, which is what True NFT is.

Also published on: https://freeton.house/en/distributed-ledgers-the-approach-dictated-by-modern-blockchains/

0 reactions
heart.png
light.png
money.png
thumbs-down.png
7
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png
by Free TON @freetonhouse. Innovative, ultrafast, free blockchain platformBecome a part of Free TON
Join Hacker Noon

Create your free account to unlock your custom reading experience.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK