<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Robert Sasu on Medium]]></title>
        <description><![CDATA[Stories by Robert Sasu on Medium]]></description>
        <link>https://medium.com/@sasu.robert?source=rss-8181a67a6c9b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UL38gI7sRcq-oKpG.jpg</url>
            <title>Stories by Robert Sasu on Medium</title>
            <link>https://medium.com/@sasu.robert?source=rss-8181a67a6c9b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:38:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sasu.robert/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Improving the performance of smart contract execution]]></title>
            <link>https://medium.com/elrondnetwork/improving-the-performance-of-smart-contract-execution-5e62808679ac?source=rss-8181a67a6c9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e62808679ac</guid>
            <category><![CDATA[vm]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[wasm]]></category>
            <dc:creator><![CDATA[Robert Sasu]]></dc:creator>
            <pubDate>Wed, 11 Sep 2019 15:50:35 GMT</pubDate>
            <atom:updated>2019-11-19T15:04:42.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*joyhZQ0JrXBWjXenpQoPdQ.jpeg" /><figcaption>https://docs.elrond.com</figcaption></figure><p>The basic architecture of Elrond is a plug-and-play type, where high level components connect/communicate with each other through well defined interfaces. A virtual machine which deploys and executes smart contracts in a specific language is a high level plug-able component in this architecture.</p><p>One such VM has to satisfy an interface and gets read-only access to the data existing in the blockchain through a set of hooks. Through this interface the VM gets access to cryptographic and hash functions as well. A smart contract can interact with the blockchain through a well-defined API. All outputs generated by the SmartContract (e.g. balance change), is saved in a so-called VMOutput at the VM’s level. After the complete execution of the smart contract the VM output is returned to the protocol. The protocol then does the basic verification and updates the state trie of the modified accounts.</p><p>Furthermore, reading from the blockchain is optimized by saving the data from an accessed account into a cache. At consequential reads through the blockchain hooks, the response comes directly from the cache.</p><p>Until now, Elrond had one VM component deployed with the protocol: a formally verified VM for the IELE language, generated by the K Framework with our Go backend. The language is great as it was created for blockchain smart contract purposes, the VM is formally verified meaning it is mathematically demonstrable that all behavior is deterministic.</p><p>But IELE is not a well known language for smart contracts, so we asked ourselves, why not support more languages, more VMs, each being optimal for different things. And because VMs in our architecture are already a modular component, we can create more such components, put them into a container and call the one which is needed for the job at any specific time. So having this in mind we decided to go on and search for the next VM to be integrated into Elrond.</p><p><strong>We had a few goals in mind when choosing a VM and one or more languages to be supported by the Elrond protocol:</strong></p><ul><li>Smart contract code should be easy to read and easy to write.</li><li>Catch obvious bugs at compile-time, and it should have a linter for anything that is impossible to catch at compile-time.</li><li>Compile to very compact bytecode to ensure that it’s cheap to deploy smart contracts.</li><li>It should be easy to discover how to use the API</li><li>It should integrate as well with the rest of the ecosystem as possible, so that the tools can be reused and avoid re-implementing code.</li><li>Tooling support and determinism for general-purpose languages</li></ul><p><strong>And the choice was: WASM</strong></p><p>WebAssembly (often shortened to Wasm) is an<a href="https://en.wikipedia.org/wiki/Open_standard"> open standard</a> that defines a<a href="https://en.wikipedia.org/wiki/Software_portability"> portable</a><a href="https://en.wikipedia.org/wiki/Binary_code"> binary</a> code format for<a href="https://en.wikipedia.org/wiki/Executable"> executable programs</a>, and a corresponding textual<a href="https://en.wikipedia.org/wiki/Assembly_language"> assembly language</a>, as well as interfaces for facilitating interactions between such programs and their host environment. The main goal of WebAssembly is to enable high performance applications on<a href="https://en.wikipedia.org/wiki/Web_page"> web pages</a>, but the format is designed to be executed and integrated in other environments as well.<a href="https://en.wikipedia.org/wiki/WebAssembly#cite_note-5">[5]</a><a href="https://en.wikipedia.org/wiki/WebAssembly#cite_note-6">[6]</a></p><p>WebAssembly is a VM target that (unlike most virtual machines) generally tries to match the semantics of a CPU architecture like ARM or x86 rather than trying to match the semantics of the language that runs on it. As a result, many languages can compile to it unchanged. Since most programming languages are built to expose the semantics of the CPU at some level, having the VM emulate a CPU is a good lowest common denominator. It also allows us to use world-class optimising compilers that were built for ISAs like x86 and ARM — very important when you’re charging by the instruction. solc has an — optimize flag but as far as I can tell all that it does is<a href="https://github.com/ethereum/solidity/blob/develop/libevmasm/JumpdestRemover.cpp"> remove unused jump targets from the list of allowed targets in the assembly’s metadata</a>, which is more of a security feature than an optimisation.</p><p><strong>One downside, however, is that these general-purpose languages were not built to write smart contracts in. That, however, can be solved with the right library.</strong></p><p>Wasm expands the family of languages available to smart contract developers to include Rust, C/C++, C#, Typescript and much more.This means you can write smart contracts in whichever language you’re familiar with, compile it of WASM and even easily debug its WAT human readable format. Additional benefits to WebAssembly:</p><ul><li>Memory-safe, sandboxed, and platform-independent.</li><li>64 and 32-bit integer operation support that maps one-to-one with CPU instructions.</li><li>Easily made deterministic by removing floating point operations</li><li>Supported by the LLVM compiler infrastructure project, meaning that Wasm benefits from over a decade of LLVM’s compiler optimisation.</li><li>Continually developed by major companies such as Google, Apple, Microsoft, Mozilla, and Facebook.</li></ul><p>As for the implementation part we looked at existing integration and debated whether to use interpreters or compilers. One of the reasons of choosing WASM was speed: we wanted to have the fastest VM / engine out there. These engines are mostly written in C++ and our protocol is in GO, but with cgo those two can work well together.</p><p>We wanted to use WASM engines at their best, bare as they are, with as little overhead as possible, preferably none. The eWasm team did a great job of integrating WABT, Bynarien and WAVM through the heraVM into Ethereum and the code looked promising. The WASM engines were left as clean as they are, adding the definition of the blockchain hooks as defined functions at every smart contract run. (BTW this is a place of further improvement — make those calls part of the underlying system, do it only once, not at every run/deploy).</p><p>So we took the code and started to create our own adapter to it, one that supports the Elrond VM interface. But while writing the adapter we made several optimizations, in order for the smart contracts to run faster. A smart contract can access several “system” functions to read and write into the state of the blockchain, to manipulate the balance of the accounts. In our integration of hera, we bring these functions and data as close as possible to the running engine — having most of the data in the adapter directly.</p><p>So, the smart contracts make use of he blockchain hooks only when the adapter does not have the data the smart contract is asking for. If an account was touched through a smart contract run, all of its data is brought to the adapter. The next reads from that accounts will be resolved directly at the adapter — no more overhead of going all the way to the blockchain.</p><p>Furthermore, in Elrond the Virtual Machines only get read access to the blockchain, while any writing they do is made to a local cache, which is written to the state only at the end of the smart contract processing. Writing to these caches is super fast, and in the case of hera this happens directly in the adapter. The final writing into the blockchain state is done only by the protocol, after basic validation — keeping the system safe at all the time.</p><p>As hera implemented the Ethereum Environment Interface and we created an adapter over it, this means Elrond directly supports the EEI: smart contracts written for Ethereum can be deployed and ran in Elrond protocol as well (with a small modification: changing the address handling from 20 bytes to 32 bytes).</p><p><strong>Our benchmarks for smart contracts running on the protocol using WASM:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IfLOj8_SixeSh7d-Mw1l-A.png" /><figcaption>The machine used for this benchmark is an Asus ZenBook — 14 inch ultrabook</figcaption></figure><ul><li>Fibonacci 32 is used in many of the open benchmarks in the space, so we did the same. We wrote a simple contract in C, compiled it to WASM, deployed it in the protocol and called it via transactions. The results: <strong>16ms average processing time</strong></li><li>CPU calculate 8000 was tested as well. Compiled the same way as fibonacci 32. The resulting average processing time: <strong>3.9ms</strong></li><li>String concat 10000: concatenating a 44 character long string 10000 times took an average of <strong>6.7ms</strong>.</li><li>Another test was running ERC20 contracts. Our test contained 100K ERC20 transfer transactions, running that batch several times. The average processing time for a transfer in an ERC20 contract is <strong>0.29ms</strong>. This means in a single block, where the block creation limit is of 1 second, the protocol is capable of putting <strong>~3350 ERC20 transactions </strong>(including validation, processing and commit). In Elrond a round is of 4 seconds, the first second is left for the leader to create a block, the next 3 seconds are for propagation, validation, signing.</li></ul><p><strong>How do we decide which VM is needed for a smart contract?</strong></p><p>In the Elrond protocol the address of any account is of 32 bytes, so there is a big room to play with these bytes and add some meaning to some of them. In case of smart contract we have the following convention for addresses:</p><ul><li>first 8 bytes are zero</li><li>the next 2 bytes define the Virtual Machine Identifier on which the smart contract will run</li><li>Bytes 11–30 are equal with sha256(smart_contract_owner_address + nonce)[11:30]</li><li>The last 2 bytes is the shard identifier</li></ul><p>At deploy time, the owner of the smart contract sends a transaction to the reserved address 0x0000000000000000000000000000000. The protocol knows that this transaction is a special type: smart contract deployment. In the data field of the transaction the owner sends the byte code of the smart contract in hex and the virtual machine identifier (2 bytes) separated by the ‘@’ character. At deploy time, the address of the smart contract is calculated (sha256(smart_contract_owner_address + nonce)) and the code of the smart contract is saved into the state of that address.</p><p>Transactions that call smart contracts will contain the address of the deployed smart contract, the protocol will know from the address which VM it has to call, as the identifier is saved into the address. The function and the arguments for the smart contract call are saved in the data field as well, as a combined string where the first part is the function name followed by the arguments encoded in hex and separated by the ‘@’ character.</p><p>In case of hera, in order to make even the function calls compatible with Ethereum contracts, the adapter changes the hex encoded Elrond type input into Ethereum format: a byte array with the following mentions:</p><ul><li>first 4 bytes are the function selector (sha256(function)[0:4])</li><li>each argument is translated from hex into a 32 bytes long array</li></ul><p><strong>Next steps</strong></p><ul><li>Further optimization of the integrated engines and creating a set of basic libraries with the most needed functionalities.</li><li>Early next steps is to create simple scripts, API explanation for early developers in several languages — starting with C/C++, then for JavaScript, TypeScript, Rust (others may follow).</li><li>But API and scripts are not enough, in order for a developer to feel good when creating a new application they need tools. Elrond will push forward and build/integrate several tools for developers, to make it easy to develop new and amazing dApps.</li></ul><p><strong>Conclusion</strong></p><p>Elrond is built with security and speed in mind. We have shown transaction processing speeds of more than 50k TPS on our sharded architecture and a mature, fast VM is imperative to keep up with our protocol. Integrating WASM, a crucial component of the new decentralized web, is a step forward in achieving very high throughputs even for smart contracts transactions. The advantages of WASM don’t stop here: support for multiple languages, sandboxed environment, developed and maintained by major companies. Our super-fast, specialized adapter combined with the bare-boned WASM engines, have reached very high processing speeds.</p><p><strong>For more information, please visit us</strong>:</p><ul><li><a href="http://www.elrond.com/">Official website</a></li><li><a href="https://github.com/ElrondNetwork">Elrond Github</a></li><li><a href="https://elrond.com/files/Elrond_Whitepaper_EN.pdf">Whitepaper</a></li><li><a href="https://twitter.com/elrondnetwork">Twitter</a></li><li><a href="http://community.elrond.com/">Community platform</a></li><li><a href="https://docs.elrond.com/">Elrond Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e62808679ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elrondnetwork/improving-the-performance-of-smart-contract-execution-5e62808679ac">Improving the performance of smart contract execution</a> was originally published in <a href="https://medium.com/elrondnetwork">Elrond Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security focused Q&A]]></title>
            <link>https://medium.com/elrondnetwork/security-focused-q-a-a829c74caafd?source=rss-8181a67a6c9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a829c74caafd</guid>
            <category><![CDATA[sharding]]></category>
            <category><![CDATA[consensus]]></category>
            <category><![CDATA[randomness]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Robert Sasu]]></dc:creator>
            <pubDate>Tue, 16 Apr 2019 11:14:53 GMT</pubDate>
            <atom:updated>2019-06-19T08:27:05.542Z</atom:updated>
            <content:encoded><![CDATA[<p>The security of our network is of paramount concern to us, thus we are starting a series of posts that discuss our robust design. For a start, this article answers two important questions that came up during our recent interactions with developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qd85TSbu394ZEWrieAZqg.jpeg" /></figure><h3>Q: How do you mitigate if a malicious group creates a signed block with bad cross-shard transactions ?</h3><p>I will start with explaining the minimal requirements of our system. At the first day of the launch, Elrond protocol will have at least 800 validators, 400 for a shard and another 400 for metachain. We have a requirement that any shard has to contain at least 400 validators, otherwise the shard will not be created, or it will be merged with another.</p><p>A few more highlights:</p><ul><li>BFT requirement / assumption 75% of the total nodes are good actors;</li><li>Probabilities are calculated with the assumption that 25% of nodes are malicious. On shard level we accept a maximum of 33% of malicious nodes. Calculations are done with 10 shards, 4000 nodes from which 1000 are malicious.</li><li>The initial validator to shard allocation is random, randomness source for comes from the metachain. When a new validator comes in, it is allocated at random to an existing shard. At most 30% of the nodes are reshuffled at the end of every epoch;</li><li>The consensus group size in metachain is 400, the leader changes at every round (5 seconds), in order to sign a block ⅔+1 has to sign it, which is 267 validators;</li><li>The consensus group size in a shard is 63, it is selected at random from the 400 buffer, changing at every round. ⅔*63 + 1 equals 43 — needed validators to sign a block.</li><li>The random seed is a chain of seeds, un-biasable, un-predictable, unchangeable. The leader of the current block signs the random seed of the previous block with his private key, using BLS single signature scheme, that number is hashed and becomes the random seed for the next group selection;</li><li>BLS single signature — a signed message with a private key result is fixed;</li><li>Block finality: block N is final only if block N-1, block N-2 … block N-K are signed. Metachain only notarized final blocks. Currently we have chosen K = 1;</li></ul><p>The probability that a malicious super majority (&gt;67%) to be selected for the same round in the same consensus is 10^-9, even if 33% of the nodes from the shard are malicious. In that case they can propose a block and sign it — let’s call it BLOCK M, but it will not be notarized by metachain. Metachain notarizes BLOCK M, only if BLOCK M+1 is built on top of it. In order to create BLOCK M+1 the next consensus group has to agree with BLOCK M. Only a malicious group will agree with BLOCK M, so the next group must have a malicious super majority again. As the random seed for group selection cannot be tampered with, the probability of selecting one malicious super majority group is ~10^-9 — to be exact 5.38 * 10^-10.</p><p><strong>The probability of signing two consecutive malicious blocks equals with selecting two subgroups with at least (⅔*63 + 1) members from the malicious group consequently. The probability for this is: ~10^-18.</strong></p><p>Furthermore, the consequently selected groups must be colluding, otherwise the blocks will not be signed.</p><p><strong>We demonstrated that the protocol is provably secure against invalid transactions.</strong></p><h3>Q: How do you mitigate shard-takeover ? Is shard-takeover possible ?</h3><p>The protocol is designed in such a way that it is provably secure and the probability of shard takeover is extremely low: <strong>2.88*10^-78</strong>. A sharded architecture has to be constructed in such a way, that it makes impossible for a shard to be taken over.</p><p><strong>Shard takeover resolution</strong>:</p><p><strong>Fallback solution</strong>, even for this impossible cases. Status: research done, two possible solutions, implementation planned after first test net launch.</p><p><strong>Solution 1:</strong></p><p>At creation of each block, the leader will add a proof that money was not created out of thin air. This proof will be verified by metachain and by each destination shard as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uVDEUUnoKAcMcKdqvHXgXw.png" /><figcaption>Source: <a href="https://docs.google.com/presentation/d/1EVjrZhoxw-ikzelFGGv7czxuJsIIWfl5I-CPIlnjsME/edit#slide=id.g5274d763f8_0_19">Sharded Chains as Data Layers</a></figcaption></figure><p><strong>Solution 2:</strong></p><p>When the leader proposes a block he adds in the header also a merkle proof for a few accounts that changed their balance during the block execution. The selection of these accounts needs to be deterministic, e.g take accounts from first transaction in each miniblock and provide an aggregated proof that goes from all these accounts to the state root hash registered in the block. When one invalid block is proposed by a malicious majority, the state root is tampered with an invalid result (after including invalid changes to the state tree).</p><p>By providing the combined merkle proof for a number of accounts, this allows a challenge for that proof to be raised by an honest node. The honest nodes will provide the block of transactions, the previous reduced merkle tree with all affected accounts before applying the challenged block and the SC states. If the proofs are not provided in the bounded time frame, the challenge is considered incomplete and all messages will be dropped. No slashing occurs, challenged block is considered valid.</p><p><strong>The cost of one invalid challenge is the entire stake of the node.</strong></p><p>This will allow metachain to try and apply the changes as it already has previous state tree (just for affected accounts) and will be able to detect the inconsistency, either invalid transaction, or invalid state root. This can be traced and the consensus group can be slashed. At the same time the challenger can be rewarded with part of the slashed amount. We need to benchmark what is the size of such a proof for maximum allowed transactions in the block. As well if the problem comes regarding a smart contract operation, then the execution of a SC is needed, but for this we can still ensure at least that no funds have been created without validating the correctness of SC execution.</p><p>The solution is further optimized by sending the reduced merkle tree proof only on <strong>challenge</strong>, the challenger presents both the reduced proof before applying the invalid block and the block itself.</p><p>However a malicious group can even hide the block from other nodes — non-malicious ones. In this case the honest nodes, even if they would be aware that new blocks have been produced(by seeing new headers notarized by metachain), they could not raise challenges because they do not have access to the block data. It is impossible to prove that.</p><p>The solution is to make mandatory the propagation of each produced block to the sibling shard, and have them confirm the reception, send confirmation to the metachain. In this case, we could have challenges being raised also from the sibling shard, as those nodes have access to the blocks and could also verify them. Another advantage with this is that there is another channel where honest nodes can request the data if they are denied by their own shard nodes. The communication overhead is further reduced by sending only the intrashard miniblock to the sibling shard. The cross shard miniblocks are always sent on different topics accessible by interested nodes. In the end, challenges can be raised by multiple honest nodes.</p><p>Another protection is given by how the P2P topics and messages are set up. The communication from one shard toward the metachain is done through a defined set of topics / channels — metachain will not accept any other messages from other channels.</p><p>This solution introduces some delay in metachain <strong>only in case of challenges,</strong>which are very low in number and highly un-probable since if detected (high probability of being detected) the nodes risk their entire stake.<strong> </strong>The metachain consensus will execute verification of multiple such proofs coming from different shards. We only notarize the blocks from shards where there are no outstanding challenges, and for the others with challenges try to process them as soon as possible, with a first come first served priority, and do the slashing either for the challenger if there was a false alarm or for the group if the challenge was validated.</p><p>Furthermore, if multiple such challenges are validated the metachain can trigger an early end-of-epoch command. In this case the malicious nodes are instantly slashed and 30% of the total nodes reshuffled — those who still have enough stake. This ensures that no shard takeover will block the protocol for a long time period and there are enough nodes in each shard that can ensure security. Otherwise if we just slash a few times and do not end the epoch, each time we remove 43 nodes from the shard we are left with fewer and fewer nodes and the overall shard security decreases.</p><p><strong>So we described the solution in case the impossible happens, now we prove that the probability is practically 0 for a malicious super majority group to be formed inside a selected shard.</strong></p><p>For shard takeover the malicious group needs to have ⅔+1 members in a single shard from the consensus buffer of 400. This equals 267 validators. Taken into consideration the above assumptions, 25% of the total nodes are malicious, the probability of the malicious groups has super majority in one shard is <strong>2.88*10^-78</strong>.</p><p>If we consider having 33% of total network nodes as malicious, the probability of having 267 malicious nodes (metachain take over attack) is <strong>2.84*10^-47</strong>. Same, if we consider having 400 malicious nodes inside of a shard (full take over attack), in which there is no honest node able to raise a challenge, the probability is practically 0 (<strong>10^-211</strong>).</p><p>If there are less malicious members than ⅔+1, but more than ⅓ of the validators in one shard (less than 267, more than 133), then the shard will only stagnate, it will not create any transactions, as none of the blocks will get its finality status, good nodes will not construct over bad blocks.</p><p>If there are even less than ⅓ of the validators in one shard we reach the situation described and explained in the first question.</p><p><strong>In conclusion, we demonstrated that the system is provably secure against shard take-over attacks.</strong></p><p><strong>Elrond’s official outlets</strong>:</p><ul><li>Elrond Github:<strong> </strong><a href="https://github.com/ElrondNetwork">https://github.com/ElrondNetwork</a></li><li>Elrond Community Platform: <a href="https://community.elrond.com/">https://community.elrond.com</a></li><li>Twitter: <a href="https://twitter.com/elrondnetwork">https://twitter.com/elrondnetwork</a></li><li>Official website: <a href="https://elrond.com/">www.elrond.com</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a829c74caafd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elrondnetwork/security-focused-q-a-a829c74caafd">Security focused Q&amp;A</a> was originally published in <a href="https://medium.com/elrondnetwork">Elrond Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>