<?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 Gabriel Coutinho de Paula on Medium]]></title>
        <description><![CDATA[Stories by Gabriel Coutinho de Paula on Medium]]></description>
        <link>https://medium.com/@GCdePaula?source=rss-52129b06f1b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N9clDyUs2EwOipRop9UQ3A.jpeg</url>
            <title>Stories by Gabriel Coutinho de Paula on Medium</title>
            <link>https://medium.com/@GCdePaula?source=rss-52129b06f1b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:11:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@GCdePaula/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[Scaling Content]]></title>
            <link>https://medium.com/cartesi/scaling-content-90de6f3ca4fa?source=rss-52129b06f1b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/90de6f3ca4fa</guid>
            <category><![CDATA[layer-2]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[ict]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[rollup]]></category>
            <dc:creator><![CDATA[Gabriel Coutinho de Paula]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 13:52:20 GMT</pubDate>
            <atom:updated>2023-01-27T08:02:49.663Z</atom:updated>
            <content:encoded><![CDATA[<h3>Scaling Content: How to truly tackle blockchain’s scalability problem</h3><h4>Bringing modern development ecosystems to smart contracts.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ANSUNVAKulFZai62_of5NQ.png" /></figure><p>Ethereum and similar blockchains are facing a scalability crisis. Scaling Ethereum is crucial for the network’s usefulness and adoption, and current transaction fees are certainly not constructive to that end. Making anything except the simplest of DApps is <em>impossible</em>.</p><p>This infamous problem has proven to be very hard to solve without compromising on security and decentralization. Piet Hein said a problem worthy of attack proves its worth by fighting back, and blockchain scalability has certainly been a mean bruiser.</p><p>However, current discussions on scalability are generally missing a key idea, which is perhaps as important as increasing transaction throughput and reducing fees. The processing limitations of the blockchain are not the only constraint making complex DApps impossible. Focusing only on <em>computational scalability</em> is a mistake; to create these impossible DApps we must do more than that.</p><p>There’s a second constraint present in Ethereum which must be addressed to truly tackle the scalability problem: that of <em>content scalability</em>¹. To explain what content scalability means, we’ll quote Friedrich Hayek’s seminal article “The Use of Knowledge in Society”:</p><figure><img alt="We make constant use of formulas, symbols, and rules whose meaning we do not understand and through the use of which we avail ourselves of the assistance of knowledge which individually we do not possess." src="https://cdn-images-1.medium.com/max/1024/1*uoZdiX4cHN1RQ-csy9ulJw.png" /></figure><p>This idea, although written about civilizations, should ring uncannily familiar to programmers. As software developers, we are the masters of abstractions². We create them by compositionally³ building upon other abstractions, which have already proved successful at their own level and without having to think about how they were implemented. This ecosystem of layered abstractions we’ve built bottom-up contains the collective knowledge of the entire computer science field and is the foundation upon which software is developed. In this sense, abstractions in computer science can be thought of as an <em>abstraction of content</em>: they’re a process of <em>information hiding</em>, wherein the underlying implementation is hidden from the user and is accessed through an interface. Through this process of information hiding, abstraction in computer science consists in the <em>enlargement of content</em>⁴.</p><p>Alfred Whitehead has said that “<em>civilization advances by extending the number of important operations which we can perform without thinking about them</em>”, and the same can be said about technology of all kinds. For example, take something as simple as driving a car, which we can do thoughtlessly. Now try to imagine the amount of technology that exists inside said car. Imagine the number of collective human hours it has taken to design a car engine and the decades of accumulated knowledge it contains. And we can apply this thought process recursively to the engine’s sub-components and the tools used to build them; they each hide information about the underlying subsystem and enable the next layer to perform more operations without thinking about them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pzlZ7KrYjK1D___ZVC2HfQ.png" /></figure><p>This is a crucial characteristic of human-made complex systems. They are compositionally built on top of other subsystems, structured in a way where each layer hides information about what’s underneath. These layers make up what we are calling <em>content</em>. And through this process of layering abstractions, one enlarges content.</p><p>In Software, one can observe this layered abstraction structure in the existing ecosystem. This stack — made of libraries, tools, operating systems, compilers, interpreters, and many other components — each abstracts away the underlying system and extends what one can do without thinking. Modern software is very intricate; to write it, quoting Hayek, we must avail ourselves of the assistance of knowledge which individually we do not possess. To this end, we leverage tried and tested <em>content</em> that has been iterated over and over for the past decades, without having to write them or understand their inner workings ourselves.</p><p>At Cartesi, we are building our own scalability solution. At its core is this crucial idea of extending the number of important operations one can do without giving them thought; to write impossible DApps, there must be content scalability. Current blockchain technologies do not have this characteristic. The computers in which smart contracts are executed are novel, in all the bad ways. None of the past forty years of developed software can actually run on them. There’s no ecosystem to speak of and no <em>content</em> in any way. To create complex systems in Ethereum, one would have to build all the abstractions from the ground up, requiring knowledge no single individual holds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDBx7WCvbQtS9HWWw1gl4g.jpeg" /><figcaption>Imagine the hypothetical scenario of going to a computer store to buy a new computer. You’re offered a super-fast one that was just released, but it cannot run anything that exists today: applications, libraries, tools, operating systems, compilers, interpreters, you name it. It can only run its own flavor of machine code.</figcaption></figure><p>Imagine the hypothetical scenario of going to a computer store to buy a new computer. You’re offered a super-fast computer that was just released, but it cannot run anything that exists today: applications, libraries, tools, operating systems, compilers, interpreters, you name it. It can only run its own flavor of machine code. The vendor could try to persuade you by saying “ah, but new software can be developed, from the ground up, for this specific computer”. Which, in many ways, is how software used to be developed before high-level compilers and operating systems. Performance notwithstanding, such a computer would be useless. There’s a reason why we’ve outgrown old software practices. Without any of the abstractions painstakingly built and iterated over for the past decades, no one in their right mind would even consider buying such a computer. There’s no <em>content</em> for this computer at any level.</p><p>Ethereum smart contracts are much like this computer, except they are also super slow. Scalability solutions are poised to break the processing constraints present in these smart contracts. However, without also tackling content scalability, their usefulness is rather limited; the emphasis solely on computational scalability is misplaced.</p><p>Imagine running a compression and decompression algorithm. On the computers we use every day, this is a trivial task. We just import the relevant, mature, battle-tested library and make a single function call to it, benefitting from decades of accumulated knowledge no single individual holds. On the blockchain, however, such a task is impossible. There’s no computational power to do it, and there are no implementations for it. Addressing just the first issue is not enough; we’d have a fast computer but no <em>content</em>. How can we address these two constraints?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSqSkCBZZSiFnWbtQHBgyA.png" /></figure><p>Currently, the most important scalability solution for Ethereum is rollups, with many competing designs and implementations. Vitalik Buterin has written a great guide about it, which can be found <a href="https://vitalik.ca/general/2021/01/05/rollup.html">here</a>. The basic idea of rollups is shifting the bulk of the computation from the blockchain to a <em>layer-2</em> protocol, using the blockchain for verifying proofs that what was executed off-chain is following the rules. This shift from <em>layer-1</em> to <em>layer-2</em> greatly reduces the cost of computations, since running things on-chain is extraordinarily expensive. But to truly address the scalability issue, we must also tackle content scalability. To create impossible DApps, one must be able to tap into the accumulated knowledge contained in modern development ecosystems.</p><p>At Cartesi, we are developing our own rollups solution, which is our answer to the scalability problem. Unlike other solutions, we bring content scalability to the table, as well as computational scalability. The key insight for scaling content is dragging into Ethereum the same computer we work with daily, using it as the infrastructure for previously impossible DApps. Inscribed in this computer are decades of rich, mature, and battle-tested <em>content</em>; with it, we can run the entire modern development stack inside the blockchain.</p><p><strong>Bottom line, we’ve put Linux and all of its toolchains inside Ethereum.</strong> One is no longer resigned to Solidity, confined by an extraordinarily costly computer; now we can use a modern development ecosystem running on a fast computer. We have decades of <em>content</em> inside the blockchain. We really can just import a compression library and use it, within our favorite programming language to boot. You may be wondering, how did we do this? We’ve gone in-depth on previous articles, <a href="https://medium.com/cartesi/rollups-cartesi-node-3000b3ffec74">Rollups: Cartesi Node</a> and <a href="https://medium.com/cartesi/rollups-on-chain-d749744a9cb3">Rollups On-Chain</a>:</p><ul><li><a href="https://medium.com/cartesi/rollups-cartesi-node-3000b3ffec74">Rollups: Cartesi Node</a></li><li><a href="https://medium.com/cartesi/rollups-on-chain-d749744a9cb3">Rollups On-Chain</a></li></ul><p>There&#39;s also our whitepaper <a href="https://cartesi.io/cartesi_whitepaper.pdf">here</a>.</p><p>And we are not even restricted to Linux. Other operating systems such as seL4, an open-source security-focused kernel with end-to-end proof of implementation correctness, can be leveraged by our technology. We can develop smart contracts with Python, Rust, OCaml, JavaScript, C++, Java, or all of them, along with all their combined ecosystems and existing libraries. We can even use actual databases. The benefits of this cannot be overstated: we are making use of knowledge that we individually do not possess, inscribed in trustworthy compilers and interpreters, preexisting mature libraries, and battle-tested operating systems.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcMrMLjne8r4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcMrMLjne8r4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcMrMLjne8r4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/142d008629b057e22ac9bea02a82d4eb/href">https://medium.com/media/142d008629b057e22ac9bea02a82d4eb/href</a></iframe><p>A concrete example that showcases the power of Cartesi is our <a href="https://github.com/cartesi/poker">Texas HODL’em</a>, a decentralized Texas Hold’em Poker game. It leverages the <a href="https://www.nongnu.org/libtmcg/">LibTMCG</a> library⁵ to implement the <a href="https://en.wikipedia.org/wiki/Mental_poker">mental card game</a> logic. Running intensive algorithms of this sort on layer-1 is not possible: the computer is just too slow. Additionally, just moving it to a faster layer-2 is not enough. The complexity of understanding the intricacies of mental poker cryptography, and then writing a robust reimplementation of LibTMCG in Solidity makes this an impossible DApp. With Cartesi rollups, on the other hand, we can just import this already existing library from our preferred programming language and use it normally, running everything on a fast computer.</p><p>This is the power of Cartesi. Developers can tap into this rich, mature, and battle-tested ecosystem decades in the making, containing knowledge no single individual holds. It’s not that it’s hard to build remarkable DApps without proper <em>content</em>; it’s actually not possible. Developers are hamstrung before they write even a single line of code, and the spectacular potential of blockchain is curbed at any attempt to make intricate ideas concrete. Scaling content breaks the fetters holding us back, unleashing the full range of possibilities of blockchains; the promises of blockchain cannot be fulfilled otherwise.</p><p>Dive deeper and check out our most recent tech thesis on Application-Specific Rollups:</p><p><a href="https://medium.com/cartesi/application-specific-rollups-e12ed5d9de01">Application-Specific Rollups</a></p><p>Get BUIDLing with Cartesi:</p><p><a href="https://docs.cartesi.io/">Homepage | Cartesi Documentation</a></p><h3>About Cartesi</h3><p>Cartesi Rollups is a modular execution layer that elevates simple smart contracts to decentralized Linux runtimes. It allows developers to launch highly scalable rollup chains, and code decentralized logic with their favorite languages and software components.</p><ul><li>Every DApp has its own high-performing rollup chain;</li><li>No cannibalization of resources from other DApps in Cartesi’s ecosystem;</li><li>No network gentrification;</li><li>Enable an entirely new class of DApps that currently cannot run on EVM chains;</li><li>Preserve the strong security guarantees of the underlying blockchain</li></ul><h3>Follow Cartesi across official channels:</h3><p><a href="https://t.me/cartesiannouncements">Telegram Announcements</a> | <a href="https://t.me/cartesiproject">Telegram</a> | <a href="https://discord.gg/UqzU93hXCW">Discord (Development Community)</a> | <a href="https://www.reddit.com/r/cartesi/">Reddit</a> | <a href="https://twitter.com/cartesiproject">Twitter</a> | <a href="https://github.com/cartesi">Github</a> | <a href="https://stackoverflow.com/questions/tagged/cartesi">StackOverflow</a> | <a href="https://www.linkedin.com/company/cartesiproject">LinkedIn</a> | <a href="https://www.facebook.com/cartesiproject/">Facebook</a> | <a href="https://www.instagram.com/cartesiproject/">Instagram</a> | <a href="https://www.youtube.com/c/Cartesiproject/videos">Youtube</a> | <a href="https://github.com/cartesi/cips/discussions">Cartesi Improvement Proposal (CIP)</a> | <a href="https://cartesi.io/">Website</a></p><p>[1] Researcher Nick Szabo has used the term <a href="https://unenumerated.blogspot.com/2017/02/money-blockchains-and-social-scalability.html"><em>social scalability</em></a> with a similar meaning, but in a different context. As such, I’ve decided against using the same term, as I feel it doesn’t capture the essence of what I’m trying to communicate.</p><p>[2] Colburn, Timothy &amp; Gary Shute, 2007, “Abstraction in Computer Science”, <em>Minds and Machines</em>, 17(2): 169–184. doi:10.1007/s11023–007–9061–7</p><p>[3] <a href="https://plato.stanford.edu/entries/compositionality/">Compositionality</a> is the principle that a system should be designed by composing smaller subsystems, and reasoning about the system should be done recursively on its structure.</p><p>[4] Colburn, Timothy R., 1999, “Software, Abstraction, and Ontology”, <em>The Monist</em>, 82(1): 3–19. doi:10.5840/monist19998215</p><p>[5] Schindelhauer, Christian. (1998). <em>A Toolbox for Mental Card Games.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90de6f3ca4fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cartesi/scaling-content-90de6f3ca4fa">Scaling Content</a> was originally published in <a href="https://medium.com/cartesi">Cartesi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cartesi Rollups Rollout — Transaction Manager]]></title>
            <link>https://medium.com/cartesi/cartesi-rollups-rollout-transaction-manager-4a49af15d6b9?source=rss-52129b06f1b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a49af15d6b9</guid>
            <category><![CDATA[rollup]]></category>
            <category><![CDATA[cartesi]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ict]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Gabriel Coutinho de Paula]]></dc:creator>
            <pubDate>Thu, 22 Jul 2021 12:59:17 GMT</pubDate>
            <atom:updated>2021-07-22T12:59:17.370Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cartesi Rollups Rollout — Transaction Manager</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iZ_I9pQv5MJ8mmx6" /></figure><p>At Cartesi, we run into issues related to a lack of mature tooling every day. Blockchain is a nascent technology, and the software stack is still in its early days and evolving at a fast pace. Writing <em>ad-hoc</em> solutions to these issues is not scalable. A better approach is building abstractions on top of established lower-level solutions in a way that they can be reused.</p><p>It must be noted that these lower-level solutions are open source, developed by the community. In the same way, we’ve benefited from those, we are publishing our own in-house tools that may benefit the community.</p><p>Previously, we talked about <a href="https://medium.com/cartesi/state-fold-cfe5f4d79639">reading the state of smart contracts with the State Fold</a>, the first step in interacting with the blockchain. The Transaction Manager is the next step. This tool addresses the issue of sending transactions to the blockchain. It is, in many ways, the dual of the State Fold: the State Fold reads the state of the ledger, and the Transaction Manager writes to the state of the ledger.</p><h3>Background</h3><p>Transactions move the blockchain state forward. They are the way users outside the blockchain enact state changes to the ledger. Common types of transactions include transferring Ether to other addresses, invoking smart contracts’ methods (such as an ERC20 token transfer) and instantiating smart contracts. In the context of Cartesi rollups, examples of transactions are adding inputs to the rollups, making state hash claims, and interacting with fraud-proof disputes.</p><p>Transactions are sent by user accounts, also known as externally owned accounts. Transactions are first signed by the user, using the account’s private key, and then broadcasted to the network to be included in the ledger at a future block. They contain information such as the “to” address (which can be another user account or a smart contract), the payload (containing data we want to send to smart contracts), gas price, and the value we want to transfer in Ethers.</p><p>From the miners’ side of things, transactions are first added to what’s called the transaction pool. The transaction pool is a structure local to each Ethereum node. It holds the set of transactions miners draw from when they are creating new blocks. Think of them as a queue of transactions to be included in the blockchain. However, as this queue is local to each node, its ordering is decided by each individual miner.</p><p>Generally speaking, miners first choose the transactions that will yield the highest profit: the order in which the transactions are added to the blockchain does not correspond to the ordering in which they were added to the pool. A reasonable heuristic for the profitability of adding transactions to the blockchain is the transaction’s gas price. As such, transactions with a higher gas price are usually added to the ledger first.</p><p>Transactions sent to the blockchain from a user account must be uniquely numbered, in ascending order, without gaps. This numbering is called the <em>nonce</em> and is part of the transaction. Transactions with duplicated nonces are mutually exclusive. If the transaction pool contains two transactions with the same nonce, the miner can only include one of them to the blockchain (generally the one with the higher gas price).</p><p>In practice, when we want to send a transaction, we do it through Ethereum’s JSON-RPC API, which is usually wrapped in some high-level library like web3.js. This library communicates with a remote provider, which we must specify before using it. Trust in this provider is imperative: a malicious provider could simply ignore our requests and refuse to broadcast our transactions. However, it cannot forge or modify our transactions: the cryptographic signature makes sure of that.</p><p>Since the provider must communicate with the Ethereum network, it must run an Ethereum node. There are generally two ways of setting this provider up. The first one is doing it ourselves. We choose an implementation of the Ethereum protocol, such as Geth or Parity, and run it in some machine. This setup is not trivial. The second way is delegating this to some external provider, such as Infura or Alchemy.</p><h3>Sending Transactions</h3><p>Making sure a transaction gets added to the blockchain is easier said than done. There are multiple pitfalls and obstacles to managing transactions, which must be addressed if we wish to create a robust application.</p><p>The first step is to build the transaction data itself, before signing it and sending it to an Ethereum node. Part of the transaction data is fixed, in the sense that we may not arbitrarily change it without altering the effects of a transaction. Examples of those are the “to” address, payload and Ether value. They are intrinsic to the transaction and are a part of the “application logic”, separate from the “submit transaction logic”.</p><p>There are parameters of the transaction data that are extrinsic, in the sense that they (generally) do not change the effects of the transaction. Examples of those are the nonce and the gas price. They are not part of the application logic and are, in a sense, purely bureaucratic.</p><p>Nevertheless, they must be carefully chosen to ensure our transitions are added to the blockchain: a wrong nonce will cause the transaction never to be added, and specifying a low gas price will clog the user account. Even then, gas prices are not constant and are subject to wild fluctuations. Submitting a transaction with a seemingly reasonable gas price may still clog the user account if the gas price spikes, and specifying a gas price that is too high will waste money.</p><p>Discovering the correct nonce in a robust way is not as straightforward as it may initially appear. The canonical way of getting the nonce is by counting how many transactions by that user account have been added to the blockchain. This works well if the user sends transactions infrequently, always waiting for the previous transaction to be mined before sending the next one. Otherwise, we may run into duplicate nonces: the transaction pool may contain further transactions that are not counted.</p><p>Making things worse, transactions may be dropped from the transaction pool arbitrarily. Along with possibly missing an important reaction, a dropped transaction may poison the user account: if there are gaps in the nonce numbering, the account will not be able to include further transactions until the gap is filled.</p><p>It is clear that we cannot just submit a transaction and expect it to be added to the ledger. There must be some bookkeeping logic between the application and the provider if we want to write a robust application. This bookkeeping logic also has to be resilient to process restarts: we must be able to turn on our application with a clean slate and have it function properly.</p><h3>Transaction Manager</h3><p>The Transaction Manager is our solution for robustly submitting transactions to the blockchain. It is available as a Rust library (a crate, in Rust parlance), and handles all this bookkeeping logic.</p><p>To submit a transaction through the manager, we must first specify the intrinsic transaction data and a <em>submission strategy</em>. The strategy is used to determine the gas price. The manager will constantly monitor the blockchain and gas prices, and will resubmit transactions with outdated prices following the submission strategy.</p><p>If a transaction is dropped from the transaction pool, it will be resubmitted automatically by the manager. Nonces are also managed automatically. When a transaction is first submitted, the manager will allocate the correct nonce to the transaction, reusing the nonce when re-submitting the transaction. If a transaction is submitted with a higher strategy than previous transactions, the manager will promote the old transactions to the newer strategy. This is done to make sure old underpriced transactions will not clog the user account. All of this is handled concurrently and does not block the main application.</p><p>Our manager can also attempt to cancel sent transactions. Cancelling transactions is not a guaranteed thing. Once committed to the blockchain, transactions cannot be revoked. However, while they are still in the transaction pool, we may attempt to override them. The trick consists of submitting a new transaction that does nothing (like transferring zero ether to oneself), but with the same nonce as the transaction we wish to cancel, and with a higher gas price. This way, there’s a chance miners will include the transaction with the higher gas price instead of the original one, effectively cancelling the original transaction. The user still has to pay the base cost of a transaction.</p><p><a href="https://github.com/cartesi/tx-manager">We are releasing the first version of our Transaction Manager</a>. There are multiple improvements in the pipeline that we are eager to share with the community when they are ready, including adjustments related to EIP-1559.</p><p><a href="https://github.com/cartesi/tx-manager">GitHub - cartesi/tx-manager: Blockchain Transaction Manager</a></p><h4>About Cartesi</h4><p><a href="https://cartesi.io/">Cartesi</a> is a multi-chain layer-2 infrastructure that allows any software developer to create smart contracts with mainstream software tools and languages they are used to while achieving massive scalability and low costs. Cartesi combines a groundbreaking virtual machine, optimistic rollups and side-chains to revolutionize the way developers create blockchain applications.</p><p><strong>Cartesi’s Ecosystem Links:</strong></p><p>Website: <a href="https://cartesi.io/">https://cartesi.io</a></p><p>Explorer: <a href="https://explorer.cartesi.io/">https://explorer.cartesi.io</a></p><p>Discord (Development Community): <a href="https://discordapp.com/invite/Pt2NrnS">https://discordapp.com/invite/Pt2NrnS</a></p><p>Twitter: <a href="https://twitter.com/cartesiproject">https://twitter.com/cartesiproject</a></p><p>Telegram: <a href="https://t.me/cartesiproject">https://t.me/cartesiproject</a></p><p>Telegram Announcements: <a href="https://t.me/cartesiannouncements">https://t.me/cartesiannouncements</a></p><p>GitHub: <a href="https://github.com/cartesi">https://github.com/cartesi</a></p><p>Reddit: <a href="https://www.reddit.com/r/cartesi/">https://www.reddit.com/r/cartesi/</a></p><p>Youtube: <a href="https://www.youtube.com/cartesiproject">https://www.youtube.com/cartesiproject</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a49af15d6b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cartesi/cartesi-rollups-rollout-transaction-manager-4a49af15d6b9">Cartesi Rollups Rollout — Transaction Manager</a> was originally published in <a href="https://medium.com/cartesi">Cartesi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cartesi Rollups Rollout — State Fold]]></title>
            <link>https://medium.com/cartesi/state-fold-cfe5f4d79639?source=rss-52129b06f1b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfe5f4d79639</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ict]]></category>
            <category><![CDATA[rollup]]></category>
            <category><![CDATA[cartesi]]></category>
            <dc:creator><![CDATA[Gabriel Coutinho de Paula]]></dc:creator>
            <pubDate>Wed, 14 Jul 2021 12:42:24 GMT</pubDate>
            <atom:updated>2021-07-14T12:45:12.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cartesi Rollups Rollout — State Fold</h3><h4>The first standalone tool of Cartesi Rollups on Testnet</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SscxopPK3-BgUz2sFlnHUw.png" /></figure><p>At Cartesi, we run into issues related to a lack of mature tooling every day. Blockchain is a nascent technology, and the software stack is still in its early days and evolving at a fast pace. Writing <em>ad-hoc</em> solutions to these issues is not scalable. A better approach is building abstractions on top of established lower-level solutions, in a way that can be reused.</p><p>It must be noted that these lower-level solutions are open source, developed by the community. In the same way, we’ve benefited from those, we are publishing our own in-house tools that may benefit the community.</p><p>The issue we are going to tackle here is reading the state of the blockchain. This is the first step of interacting with the blockchain: to decide what we’ll do at each moment, we first need to know the state of our smart contracts.</p><h3>Reading the State of the Blockchain</h3><p>The state of the blockchain is ever-moving. With each new block, things may arbitrarily change. The goal of a <em>reader</em> is to keep up with these changes. Note that readers are dApp specific, and must be created to fit specific smart contracts.</p><p>The canonical way of interacting with the blockchain is through Ethereum’s JSON-RPC API. Usually, the API is wrapped in some high-level library like web3.js. Trust in the remote server that implements this API is imperative. A malicious server could give us wrong responses, or simply not answer us. This server must communicate with the Ethereum network and, as such, must run an Ethereum node.</p><p>There are generally two ways of setting this server up. The first one is doing it ourselves. We choose an implementation of the Ethereum protocol, such as Geth or Parity, and run it in some machine. This setup is not trivial. The second way is delegating this to some external provider, such as Infura or Alchemy. This is a much easier solution but has associated costs. These services charge for each query past a certain limit. Readers that decide to use Infura must take this into consideration.</p><p>One convenient way smart contracts publish their state is through <em>diff</em> events. The idea is simple: at each state change, we notify only what was changed. For example, imagine a smart contract that stores all past prices of a certain asset. Instead of emitting an event with all past prices every time a new entry is added, we emit an event with only the new entry. This way, the reader can reconstruct the entire list by accumulating all past events. Complex data structures like graphs and collections can only be efficiently communicated through diffs. We run into those quite frequently at Cartesi.</p><p>The main obstacle to creating a consistent reader has to do with consensus finality. Finality is related to persistence: once a block is committed, it may not be altered. However, things in Ethereum are not exactly written in stone. At any point, history may be rewritten through a process called a <em>chain reorganization</em>, and some states we read in the past may no longer be part of the blockchain.</p><p>Chain reorganizations usually happen when two or more blocks are mined at the same time, creating alternate realities. At some point, one of the realities will be considered the correct one and the others will die off. If we read the state of one that died off, we may run into inconsistencies. For instance, imagine we’re dealing with diff events. If we mix up events from different realities, we end up in an inconsistent state.</p><p>The silver lining is that Ethereum has what’s called <em>probabilistic finality</em>. The chance of reorganizations becomes vanishingly small the further we go into the past. As such, one simple solution to creating a consistent reader is waiting for blocks to become old. We can calibrate the age of the blocks to some safety threshold: the older it is, the safer the reader. However, this results in a high-latency reader.</p><p>Therefore, creating both a reader that is consistent and real-time is not trivial. The issue becomes even worse when we consider that each dApp has its own specificities like events and getters. We also want a reader that avoids making excessive calls to the remote server, since we want to use services like Infura. Our reader should be able to run locally as well as remotely, and generally, be lightweight and fast.</p><h3>The <em>State Fold</em></h3><p>We are pleased to present the <a href="https://github.com/cartesi/state-fold">release of State Fold&#39;s implementation</a>.</p><p><a href="https://github.com/cartesi/state-fold">GitHub - cartesi/state-fold: Blockchain Reader Library</a></p><p>The State Fold is our solution to this issue of reading blockchain state. Its design is heavily inspired by ideas from functional programming, which allows us to create more robust software. The underlying insight is that the state of the blockchain is immutable <em>at a specific block hash</em>. The latest block is ever-changing, and blocks at a certain number may change due to reorganizations. However, blocks with a specific hash never change. They may eventually be revoked from the blockchain, but they remain immutable. And with this immutability, we can drag in concepts from functional programming.</p><p>In functional programming, <em>fold</em> (sometimes called <em>reduce</em>) is commonly used to iterate over collections when we want to accumulate its elements. It is a higher-order function, which takes an initial value and combining operator, and yields a final value. If you’re not familiar with this concept, we recommend learning more about it! Here is <a href="https://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia&#39;s article</a> on this topic, which should be a good introduction.</p><p>The first issue we have to deal with is flexibility. Since readers are dApp specific, there must be a way of configuring the State Fold to adapt to each smart contract’s needs. The State Fold accomplishes this through programmability: the developer specifies its behavior through a callback object that acts as a delegate. These delegates are dApp dependent and implement the necessary blockchain state fetching logic required for each specific smart contract.</p><p>To this end, the developer must provide a pair of functions: sync and fold. Both sync and fold create a <em>block state</em>, corresponding to the state of a smart contract at a specific block. Sync creates a new state from scratch by querying the blockchain. Fold advances the state by one step, using both the previous state and blockchain queries. Note that these queries can only be done at a specific block hash, making them immutable.</p><p>At a high level, the State Fold logic is reasonably easy. The State Fold calls sync to produce the first state and then uses fold to update the state one block at a time. As such, when we first turn on the State Fold, it will call sync to generate the initial state. Then, at every new block, it will call fold on the previous state, generating the next state. The property these two functions must satisfy is that syncing to a block and folding up to that block has to yield the same result. We can think of syncing at a block as a fast-track of folding from genesis to this block.</p><p>Going into more detail, the branching nature of the blockchain yields a tree-like structure of blocks. For example, if multiple miners create a block at the same time, the blockchain will temporarily fork, creating separate realities. The State Fold stores these realities internally in a tree-like data structure, representing the blockchain itself. This structure associates blocks to <em>block states</em>, which fully describes the state of our smart contracts at each block in the blockchain. This structure is simply a cache, since we may reconstruct it entirely from the blockchain.</p><p>When a new block is added to the blockchain, the State Fold finds the parent of this new block in the cache and advances its state one step through folding. If there are gaps in the cache (for example, it only has the grandparent block), this procedure is applied recursively. If the cache does not contain an ancestor block, we use sync instead. This process elegantly keeps consistency when faced with reorganizations, which enables the State Fold to operate in real-time without fear of inconsistent states.</p><p>Inside the delegate, the developer has the entire JSON-RPC reader methods available, albeit restricted to queries only at certain block hashes (because of our immutability restriction). This allows for the same flexibility as using raw web3.js, but real-time, with consistency guarantees and without added complexity.</p><p><a href="https://github.com/cartesi/state-fold">Our implementation is in Rust, available as a library (in Rust parlance, a crate)</a>. The delegates are also written in Rust and must be compiled with the library. As such, it can run locally as well as remotely.</p><h3>Analysis</h3><p>A good tool that solves the same problem in a different way is called <em>The Graph</em>. However, The Graph made certain design choices with an unpalatable trade-off profile for certain parts of our software stack. The first thing to note is that our goals are a lot more modest than The Graph, which in turn has made The Graph a lot more complex than necessary for our needs. Here we make a short analysis of what goals our reader achieves, to justify our choice of rolling out our own solution.</p><p>The first goal is flexibility. Flexibility is the capacity in which the reader is capable of reading arbitrary observable blockchain states. We consider a state observable if we can read it through the Ethereum JSON-RPC API. Our solution exposes the entire API to the developer, which makes it maximally flexible.</p><p>Programming our State Fold is done entirely in Rust. We provide an actual strongly-typed programming language, in which the developer actively fetches data using the standard API. We believe this imposes fewer restrictions, simplifies the overall computational model, and reduces cognitive load.</p><p>Note that this flexibility, in turn, enables multiple optimizations to make a lighter use of services like Infura. These services, past a certain limit, charge users for each query. The State Fold, if programmed correctly, is very light on them. Also, when folding, we naturally reuse past states, bypassing the need for querying Infura too much.</p><p>It should be noted that the State Fold works on any provider. All it needs is an Ethereum JSON-RPC endpoint. We designed our reader to be lightweight and to be easy on the provider. One consequence of this is that there’s not much overhead when syncing. It can also be easily deployed either locally or remotely on our own infrastructure, which simplifies using it.</p><p>The second goal is real-time consistency. Consistency is the degree to which the observed state is correct in relation to the blockchain, and real-time is the ability to do so at the latest block. The challenge is creating a reader that can operate at the “quantum foam” while safely dealing with reorganizations. We achieve these properties through the use of the functional programming fold.</p><p>Another design goal that should not be overlooked is the ability to compose State Folds. This allows for a modular approach when writing delegates, which greatly simplifies implementing complex logic and enables the reuse of code. The ability to create abstractions is one of the most important tools in a programmer’s toolbox.</p><h4>About Cartesi</h4><p><a href="https://cartesi.io/">Cartesi</a> is a multi-chain layer-2 infrastructure that allows any software developer to create smart contracts with mainstream software tools and languages they are used to while achieving massive scalability and low costs. Cartesi combines a groundbreaking virtual machine, optimistic rollups and side-chains to revolutionize the way developers create blockchain applications.</p><p><strong>Cartesi’s Ecosystem Links:</strong></p><p>Website: <a href="https://cartesi.io/">https://cartesi.io</a></p><p>Explorer: <a href="https://explorer.cartesi.io/">https://explorer.cartesi.io</a></p><p>Discord (Development Community): <a href="https://discordapp.com/invite/Pt2NrnS">https://discordapp.com/invite/Pt2NrnS</a></p><p>Twitter: <a href="https://twitter.com/cartesiproject">https://twitter.com/cartesiproject</a></p><p>Telegram: <a href="https://t.me/cartesiproject">https://t.me/cartesiproject</a></p><p>Telegram Announcements: <a href="https://t.me/cartesiannouncements">https://t.me/cartesiannouncements</a></p><p>GitHub: <a href="https://github.com/cartesi">https://github.com/cartesi</a></p><p>Reddit: <a href="https://www.reddit.com/r/cartesi/">https://www.reddit.com/r/cartesi/</a></p><p>Youtube: <a href="https://www.youtube.com/cartesiproject">https://www.youtube.com/cartesiproject</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfe5f4d79639" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cartesi/state-fold-cfe5f4d79639">Cartesi Rollups Rollout — State Fold</a> was originally published in <a href="https://medium.com/cartesi">Cartesi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>