<?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 Rosario De Chiara on Medium]]></title>
        <description><![CDATA[Stories by Rosario De Chiara on Medium]]></description>
        <link>https://medium.com/@rosdec?source=rss-841663334bca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*blbEerspY3oWs_TgULYHJA.jpeg</url>
            <title>Stories by Rosario De Chiara on Medium</title>
            <link>https://medium.com/@rosdec?source=rss-841663334bca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:31:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rosdec/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[The byzantine generals and modern distributed systems]]></title>
            <link>https://medium.com/coinmonks/the-byzantine-generals-and-modern-distributed-systems-ba8fdc12d067?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba8fdc12d067</guid>
            <category><![CDATA[hyperledger-sawtooth]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[byzantine-fault-tolerance]]></category>
            <category><![CDATA[blockchain-technology]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Fri, 01 Apr 2022 05:44:59 GMT</pubDate>
            <atom:updated>2022-04-01T15:15:45.362Z</atom:updated>
            <content:encoded><![CDATA[<h4>A moving story about a city siege and the difficulties of communication in modern distributed systems</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s2KpKPhpxVYlHB-W" /><figcaption>Photo by <a href="https://unsplash.com/@timschmidbauer?utm_source=medium&amp;utm_medium=referral">Tim Schmidbauer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>A historical digression</h4><p>Once known as Byzantium at the time of classical antiquity, Constantinople has been subjected to many sieges (so many that their list has <a href="https://en.wikipedia.org/wiki/List_of_sieges_of_Constantinople">its own page</a> on Wikipedia!). The generals surrounding the city had the problem of deciding to whether attack or not. To reach a consensus about whether to attack or not, generals can exchange messages and must cope with the problem of possible traitors among them. This kind of (fictional) scenario has been elected as the paradigm of the possible weakness of distributed systems like a blockchain: blockchain evolves its state only when it reaches the consensus on the next block to be added and this consensus must be reached considering failing nodes, sketchy nodes injecting fake messages and slow network: this is a Byzantine fault scenario.</p><h4>Communication in the wild internet</h4><p>“Distributed systems” is just the name we give to components deployed in a way where the communication channels connected them are (partially) outside your <em>jurisdiction</em>: this means: you cannot rely on who will propagate your messages, you can assume somebody may eavesdrop on them, it might happen that some malicious agent will inject bad messages into your traffic, etc…</p><p>Of course, this generic scenario applies to <em>any</em> communication on the internet, so this is something that engineers and computer scientists learned to cope with for ages. The interesting thing is that this inherently unreliable way of communicating is exactly the same the generals in the example above had to cope.</p><p>In [1] the authors present the Byzantine generals and their communication problems as a paradigm for distributed systems and also provide some approaches to let them cooperate and coordinate their efforts in the modern era internet. This is so much important that the expression <a href="https://en.wikipedia.org/wiki/Byzantine_fault">byzantine fault</a> refers to the failure in a distributed system caused by imperfect communication.</p><h4>The blockchain and the generals</h4><p>One of the most disruptive approaches in designing distributed systems is the blockchain which has the purpose of representing value by the means of a distributed database of transactions: such an approach must take into account byzantine failures and how to rely on them in the process of synchronizing the copies of the database while allowing each of the nodes to (potentially) add more transactions, the purpose is to reach the <strong>Byzantine fault tolerance</strong> (<strong>BFT</strong>) (see? still the generals).</p><p>Different algorithms can be used to achieve the BFT, and the same blockchain can be deployed having different BFT algorithms.</p><p>A good starting point to study them can be Hyperledger Sawtooth which can run a variety of consensus algorithms, including Practical Byzantine Fault Tolerance (PBFT) and Proof of Elapsed Time (PoET), letting the user craft the performances of the blockchain in the most suitable way depending on the specific requirements.</p><p>Check this post of mine on the Logrocket blog for more an in-depth discussion of different algorithms and some tests: <a href="https://blog.logrocket.com/hyperledger-sawtooth-introduction/">Hyperledger Sawtooth: A gentle introduction</a></p><h3>References</h3><ol><li><em>Leslie Lamport, Robert Shostak, and Marshall Pease. 1982. The Byzantine Generals Problem. ACM Trans. Program. Lang. Syst. 4, 3 (July 1982), 382–401. DOI:https://doi.org/10.1145/357172.357176</em></li></ol><blockquote>Join Coinmonks<a href="https://t.me/coincodecap"> Telegram Channel</a> and<a href="https://www.youtube.com/c/coinmonks/videos"> Youtube Channel</a> learn about crypto trading and investing</blockquote><h3>Also, Read</h3><ul><li><a href="https://coincodecap.com/trading-signal">What are the Trading Signals?</a> |<a href="https://coincodecap.com/bitstamp-coinbase"> Bitstamp vs Coinbase</a> |<a href="https://coincodecap.com/buy-solana"> Buy Solana</a></li><li><a href="https://coincodecap.com/profitfarmers-review">ProfitFarmers Review</a> |<a href="https://coincodecap.com/cornix-trading-bot"> How to use Cornix Trading Bot</a></li><li><a href="https://coincodecap.com/best-cryptocurrency-blogs">10 Best Cryptocurrency Blogs</a> |<a href="https://coincodecap.com/youhodler-review"> YouHodler Review</a></li><li><a href="https://coincodecap.com/myconstant-review">MyConstant Review</a> |<a href="https://coincodecap.com/best-swing-trading-bots"> 8 Best Swing Trading Bots</a></li><li><a href="https://medium.com/coinmonks/mxc-exchange-review-3af0ec1cba8c">MXC Exchange Review</a> |<a href="https://coincodecap.com/pionex-vs-binance"> Pionex vs Binance</a> |<a href="https://coincodecap.com/pionex-arbitrage-bot"> Pionex Arbitrage Bot</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba8fdc12d067" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/the-byzantine-generals-and-modern-distributed-systems-ba8fdc12d067">The byzantine generals and modern distributed systems</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Sovereign Identity: a path for the adoption]]></title>
            <link>https://medium.com/coinmonks/self-sovereign-identity-a-path-for-the-adoption-1ca43d068907?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ca43d068907</guid>
            <category><![CDATA[self-sovereign-identity]]></category>
            <category><![CDATA[digital-identity]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[wallet]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 16:54:16 GMT</pubDate>
            <atom:updated>2022-03-28T14:31:54.572Z</atom:updated>
            <content:encoded><![CDATA[<h4>SSI cannot be successful without an ecosystem (like every new app we are designing in the 21st century, by the way)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pxVIJ1zbahIxYSw7" /><figcaption>Photo by <a href="https://unsplash.com/@raimondklavins?utm_source=medium&amp;utm_medium=referral">Raimond Klavins</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Self-Sovereign Identity, SSI for short, is a paradigm shift in the way digital identities are managed and, in a wider sense, perceived by the citizens, first, and the rest of institutions that issue, handle and verify identities and credentials, then.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*Yn_pyuhOeYUGueiv.png" /><figcaption>Progress in digital identities (image credits: <a href="https://innovalor.nl/en/Blogs/self-sovereign-identity">https://innovalor.nl/en/Blogs/self-sovereign-identity</a>)</figcaption></figure><p>In the figure above you can see how the SSI can be seen as a mandatory step in the evolution of digital identities: from the centralized, first cut to the digital identities, a progressive and incremental evolution can be envisioned toward a future where a distributed way of handling such identities will be the usual way of handling them.</p><p>It is worth noting that the meaning of the adjective <em>distributed </em>is not only referring to the architecture of the components where credentials will be kept but, mainly, to<strong> the distribution of the responsibilities</strong> of how credentials are issued, kept, and shared: this is the exact meaning of <em>self-sovereign</em>, the holder, the citizens or the legal representative of a company, will be in charge of her own credentials and will apply control on the life-cycle of such credential.</p><h4>An ecosystem is what we need</h4><p>No matter how fascinating such a vision is, it is necessary to clarify that no SSI solution can work on its own, an SSI solution must, first of all, foster an <em>ecosystem </em>as florid as it can get, in which to host all the processes.</p><p>I have personally followed the development of at least three different wallet apps, each with subtle differences, and, for each of them, once you clarify the details of the user experience and the way you keep your secret stuff in a safe place on your mobile, it became clear you need to develop an issuer and a verifier, to demonstrate how your pretty <a href="https://www.w3.org/TR/vc-data-model/">JWT</a> will be exchanged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hPFrNyoAu3ohhnSAVHreXg.png" /><figcaption>A modern SSI logic architecture: the ecosystem is composed by wallets, issuers, verifiers and ledger</figcaption></figure><p>In the diagram above, you can see a simple sketch showing how a modern SSI system is composed.</p><p>Let’s just shortly comment on each of the components:</p><ul><li>The wallet: it is an app (it can be a web app but it is not relevant in this technological framework: the two concepts coincide), it must be able to receive asynchronous messages, scan QR-codes, get access to two different local storages;</li><li>The storages: one is encrypted and protected by biometry, the other just provides the persistency that is functional to the state of the application. The differences between them are numerous but, shortly, if you lose your phone the encrypted storage will be hardly accessible to anybody who will find it, so it is a good place where to keep your secrets (e.g. the private key);</li><li>The ledger: it can be a blockchain (of course) but it is not necessary, going for the blockchain will open access to the <em>purest</em> form of SSI, the blockchain will play the role of the <em>single source of truth</em>, open, public, resilient to failures and to crashes, unstoppable and tamper-proof.</li><li>The registries: you will need at least a revocation registry, to record the credentials and presentations that will be revoked. It may appear that more registries will be needed but it will be just a variation of the revocation registry;</li><li>Issuers and verifiers: those are the other actors, beyond the wallet, of each of the exchanges in SSI, they will have specific roles and, most importantly, will create credentials for others and ask for a presentation, of such credentials, to verify them, for the purposes of their roles.</li><li>Distributed Identifiers: this is the DID infrastructure containing DIDs and DID documents (check <a href="https://www.linkedin.com/pulse/decentralized-identifiers-francesco-zurolo/">this nice article</a> by my good friend Francesco Zurolo);</li><li>Asynchronous communication channels: this channel must factor in the idea of exchanging encrypted information between certified endpoints that will have to be cryptographically demonstrated to control such endpoints.</li></ul><h4>Fostering the ecosystem: issuers and verifiers</h4><p>Issuer and verifier are the most complex part that hardly will be under the control of who is designing the SSI system and the wallet: issuers and verifiers (in this exact sequence) must be involved as soon as possible in the process.</p><p>The issuer must be authoritative for a given set of credentials, some examples: a group of universities for diplomas, a set of city municipalities for parking permissions, some small business for a loyalty program.</p><p>Verifiers should be included but this is way easier because once your wallet will have been hosting credentials it will be clear that checking them will enable citizens to have a new way to access services: students will be able to certify their own diplomas when looking for jobs, parking permissions will be tamper-proof and easily checked by officers, more customers will be engaged by the idea of collecting loyalty points doing shopping.</p><p>Both issuers and verifiers are subjects that <em>already have processes involving credentials</em>, it will be needed to imagine software kits to facilitate them in the process of adding a totally new way of doing what they already do: issuing credentials (e.g. diplomas, parking permissions, loyalty points) and verifying them. It must be clear that is necessary that there will be a process when both credentials, the traditional, maybe even paper-based, ones and the new SSI ones, will co-exist so processes must be able to accommodate both.</p><h4>Conclusion</h4><p>SSI is an unavoidable evolution of digital identities, planning ahead is necessary (of course) and it is fundamental to aim at having an ecosystem, the sooner the better, of issuers and verifiers. The adoption of the SSI approach is a battle that deserves to be fought but cannot be won alone.</p><blockquote>Join Coinmonks<a href="https://t.me/coincodecap"> Telegram Channel</a> and<a href="https://www.youtube.com/c/coinmonks/videos"> Youtube Channel</a> learn about crypto trading and investing</blockquote><h3>Also, Read</h3><ul><li><a href="https://medium.com/coinmonks/3commas-review-an-excellent-crypto-trading-bot-2020-1313a58bec92">3Commas Review</a> |<a href="https://coincodecap.com/pionex-review-exchange-with-crypto-trading-bot"> Pionex Review</a> |<a href="https://medium.com/coinmonks/coinrule-review-2021-a-beginner-friendly-crypto-trading-bot-daf0504848ba"> Coinrule review</a></li><li><a href="https://medium.com/coinmonks/ledger-vs-ngrave-zero-7e40f0c1d694">Ledger vs Ngrave</a> |<a href="https://medium.com/coinmonks/ledger-nano-s-vs-x-battery-hardware-price-storage-59a6663fe3b0"> Ledger nano s vs x</a> |<a href="https://medium.com/coinmonks/binance-review-ee10d3bf3b6e"> Binance Review</a></li><li><a href="https://medium.com/coinmonks/bybit-exchange-review-dbd570019b71">Bybit Exchange Review</a> |<a href="https://coincodecap.com/bityard-reivew"> Bityard Review</a> |<a href="https://coincodecap.com/jet-bot-review"> Jet-Bot Review</a></li><li><a href="https://medium.com/coinmonks/3commas-vs-pionex-vs-cryptohopper-best-crypto-bot-6a98d2baa203">3Commas vs Cryptohopper</a> |<a href="https://medium.com/coinmonks/earn-crypto-interest-b10b810fdda3"> Earn crypto interest</a></li><li>The Best Bitcoin<a href="https://medium.com/coinmonks/hardware-wallets-dfa1211730c6"> Hardware wallet</a> |<a href="https://medium.com/coinmonks/bitbox02-review-your-swiss-bitcoin-hardware-wallet-c36c88fff29"> BitBox02 Review</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ca43d068907" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/self-sovereign-identity-a-path-for-the-adoption-1ca43d068907">Self-Sovereign Identity: a path for the adoption</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three approaches to Self-Sovereign Identity based on blockchain]]></title>
            <link>https://medium.com/coinmonks/three-approaches-to-self-sovereign-identity-based-on-blockchain-301b18a49345?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/301b18a49345</guid>
            <category><![CDATA[self-sovereign-identity]]></category>
            <category><![CDATA[digital-identity]]></category>
            <category><![CDATA[decentralized-identifier]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Wed, 20 Oct 2021 07:25:50 GMT</pubDate>
            <atom:updated>2021-10-20T07:25:50.783Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this short article, we investigate three different approaches to how SSI concepts map on the blockchain infrastructure.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yOw4INdTsVzAf9Zgj1HdcQ.jpeg" /><figcaption>Teatro Augusteo (Salerno, Italy), detail of the roof (photo by Rosario De Chiara)</figcaption></figure><p>This is the first of a series of articles about SSI, Self-Sovereign Identity</p><p>In this short article, we shortly compare three different approaches to implement a system of Self-Sovereign Identity (SSI) based on public-ledger/blockchain. We intend to classify the approaches by considering how much of the information is stored on the blockchain. In general speaking, the role of the blockchain in an SSI ecosystem is to keep track of the interactions between the actors by keeping hashes of the credentials and presentations that are issued and requested.</p><ul><li>The first approach is used by <a href="https://www.hyperledger.org/use/hyperledger-indy">Hyperledger Indy</a>: the blockchain Indy is based on is <a href="https://github.com/hyperledger/indy-plenum">Plenum</a>, a domain-specific blockchain, that is in charge of collecting the interactions that happen between issuer/verifier/holder. SSI is the single purpose of the blockchain and credentials, identities and presentations are “first-class citizens”.</li><li>The second approach is the one adopted by smartcontracts based solutions like <a href="https://alastria.io/">Alastria</a>: identities, credentials, and presentations are kept in specialized registries within the storage of smart contracts on a generic Ethereum-compatible blockchain. The hashes of credentials, presentations, fragments of the DID Documents, the credential schemas, are kept in specialized registries that are hosted in smartcontracts that are in charge of protecting access to given actors.</li><li>The third approach is, in a way, derived from the previous one, and is the one pursued by <a href="https://www.uport.me/">uPort/Serto</a>: the blockchain has one single registry that tracks down just the revocation of credentials, everything else, credentials issuance, the life-cycle of a presentation request/response, credential schemas, trusted issuers/verifiers, is outside the specification, every actor can issue whatever credential it likes to whomever; any further requirements for additional enforcement on who can do what has to be designed and developed from scratch.</li></ul><p>These three approaches, Indy, Alastria, and uPort/Serto can be placed within different categories to compare them.</p><blockquote>Subscribe to <a href="https://www.youtube.com/c/coinmonks/videos"><strong>Coinmonks Youtube Channel</strong></a> to get daily crypto news.</blockquote><h3>Decentralized Identifiers (DIDs) creation</h3><p>The differences between the three approaches are evident in the process of the creation of a new DID and, in general, what a DID in each system corresponds to.</p><p>In Indy, DID can be generated for each interaction between actors, each DID is a synonym of the controller; this is the extrema ratio to disable any chance of correlations between a single identity (e.g. a citizen) and its credential/presentation. This is pretty effective to avoid the risk of having a list of the DID that, for instance, have had a retired driving license.</p><p>Alastria handles DID by deploying a copy of a smartcontract, called Identity Proxy, when a DID is created; the address of the smartcontract became part of the identifying string. The Identity Proxy smartcontract is used to mask the transactions to modify the state of the registries, to circumvent the risk of correlating different transactions to a single DID.</p><p>The most lightweight approach is adopted by uPort/Serto: every Ethereum address is a DID but this is not prone to correlation because no registry tracks credential issuance or presentations response. Only the hash of a revoked credential is tracked in the revocation registry and it does not contain any reference to the DID to whom such credential was issued.</p><h3>Discussion</h3><p>Indy has a clear approach to preserving the privacy of each actor by putting a lot of effort to handle the generation of the synonym. Alastria, on the other hand, offers a lot of surface for customizations like implementing sophisticated policies to handle authorization: you can have registries to collect some specific kind of issuers, for instance, you can allow policies on the credential schemas each of the issuers can handle, and so on. uPort/Serto can be seen in the middle between these two approaches by having the strict necessary in a registry (the revocation list) and nothing more but also not closing the door to let the adopter implement something more expressive.</p><p>In the background, there is the fact that Indy requires a very specific, single-purpose, installation of blockchain, Plenum, while Alastria and uPort/Serto can easily be installed on any Ethereum blockchain both in public and private installment, letting the SSI be just one use case on a general-purpose blockchain.</p><p><em>Thanks to </em><a href="https://www.linkedin.com/in/francesco-zurolo-6481002/"><em>Francesco Zurolo</em></a><em> and </em><a href="https://www.linkedin.com/in/paolo-servillo-86b4a926/"><em>Paolo Servillo</em></a><em> for the interesting feedback on this article</em></p><blockquote>Join Coinmonks <a href="https://t.me/coincodecap">Telegram Channel</a> and <a href="https://www.youtube.com/c/coinmonks/videos">Youtube Channel</a> learn about crypto trading and investing</blockquote><h4>Also, Read</h4><ul><li><a href="https://blog.coincodecap.com/futures-trading-signals">Best Futures Trading Signals</a> | <a href="https://blog.coincodecap.com/liquid-exchange-review">Liquid Exchange Review</a></li><li><a href="https://medium.com/coinmonks/3commas-review-an-excellent-crypto-trading-bot-2020-1313a58bec92">3Commas Review</a> | <a href="https://blog.coincodecap.com/pionex-review-exchange-with-crypto-trading-bot">Pionex Review</a> | <a href="https://medium.com/coinmonks/coinrule-review-2021-a-beginner-friendly-crypto-trading-bot-daf0504848ba">Coinrule review</a></li><li><a href="https://medium.com/coinmonks/ledger-vs-ngrave-zero-7e40f0c1d694">Ledger vs Ngrave</a> | <a href="https://medium.com/coinmonks/ledger-nano-s-vs-x-battery-hardware-price-storage-59a6663fe3b0">Ledger nano s vs x</a> | <a href="https://medium.com/coinmonks/binance-review-ee10d3bf3b6e">Binance Review</a></li><li><a href="https://medium.com/coinmonks/bybit-exchange-review-dbd570019b71">Bybit Exchange Review</a> | <a href="https://blog.coincodecap.com/bityard-reivew">Bityard Review</a> | <a href="https://blog.coincodecap.com/coinspot-review">CoinSpot Review</a></li><li><a href="https://medium.com/coinmonks/3commas-vs-pionex-vs-cryptohopper-best-crypto-bot-6a98d2baa203">3Commas vs Cryptohopper</a> | <a href="https://medium.com/coinmonks/earn-crypto-interest-b10b810fdda3">Earn crypto interest</a></li><li>The Best Bitcoin <a href="https://medium.com/coinmonks/hardware-wallets-dfa1211730c6">Hardware wallet</a> | <a href="https://medium.com/coinmonks/bitbox02-review-your-swiss-bitcoin-hardware-wallet-c36c88fff29">BitBox02 Review</a></li><li><a href="https://medium.com/coinmonks/blockfi-vs-celsius-vs-hodlnaut-8a1cc8c26630">BlockFi vs Celsius</a> | <a href="https://medium.com/coinmonks/hodlnaut-review-best-way-to-hodl-is-to-earn-interest-on-your-bitcoin-6658a8c19edf">Hodlnaut Review</a> | <a href="https://blog.coincodecap.com/kucoin-review">KuCoin Review</a></li><li><a href="https://medium.com/coinmonks/bitsgap-review-a-crypto-trading-bot-that-makes-easy-money-a5d88a336df2">Bitsgap review</a> | <a href="https://medium.com/coinmonks/quadency-review-a-crypto-trading-automation-platform-3068eaa374e1">Quadency Review</a> | <a href="https://medium.com/coinmonks/bitbns-review-38256a07e161">Bitbns Review</a></li><li><a href="https://medium.com/coinmonks/top-10-crypto-copy-trading-platforms-for-beginners-d0c37c7d698c">Crypto Copy Trading Platforms</a> | <a href="https://medium.com/coinmonks/coinmama-review-ace5641bde6e">Coinmama Review</a></li><li><a href="https://medium.com/coinmonks/bitcoin-exchange-in-india-7f1fe79715c9">Crypto exchanges in India</a> | <a href="https://medium.com/coinmonks/bitcoin-savings-account-e65b13f92451">Bitcoin Savings Account</a></li><li><a href="https://blog.coincodecap.com/okex-kucoin">OKEx vs KuCoin</a> | <a href="https://blog.coincodecap.com/celsius-alternatives">Celsius Alternatives</a> | <a href="https://blog.coincodecap.com/buy-vechain">How to Buy VeChain</a></li><li><a href="https://blog.coincodecap.com/binance-futures-trading">Binance Futures Trading</a> | <a href="https://blog.coincodecap.com/mudrex-3commas-etoro">3Commas vs Mudrex vs eToro</a></li><li><a href="https://blog.coincodecap.com/buy-monero">How to buy Monero</a> | <a href="https://blog.coincodecap.com/idex-review">IDEX Review</a> | <a href="https://blog.coincodecap.com/bitkan-trading-bot">BitKan Trading Bot</a></li><li><a href="https://medium.com/coinmonks/coindcx-review-8444db3621a2">CoinDCX Review</a> | <a href="https://blog.coincodecap.com/crypto-margin-trading-exchanges">Crypto Margin Trading Exchanges</a></li><li><a href="https://blog.coincodecap.com/bookmap-review-2021-best-trading-software">Bookmap Review</a> | <a href="https://blog.coincodecap.com/crypto-exchange-usa">5 Best Crypto Exchanges in the USA</a></li><li><a href="https://blog.coincodecap.com/ftx-futures-trading">How to trade Futures on FTX Exchange</a> | <a href="https://blog.coincodecap.com/okex-vs-binance">OKEx vs Binance</a></li><li><a href="https://blog.coincodecap.com/coinloan-review">CoinLoan Review</a> | <a href="https://medium.com/coinmonks/youhodler-4-easy-ways-to-make-money-98969b9689f2">YouHodler Review</a> | <a href="https://blog.coincodecap.com/blockfi-review">BlockFi Review</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=301b18a49345" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/three-approaches-to-self-sovereign-identity-based-on-blockchain-301b18a49345">Three approaches to Self-Sovereign Identity based on blockchain</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Random maze from Entombed]]></title>
            <link>https://medium.com/codex/random-maze-from-entombed-8bb3b34e8f9b?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bb3b34e8f9b</guid>
            <category><![CDATA[atari]]></category>
            <category><![CDATA[commodore]]></category>
            <category><![CDATA[videogames]]></category>
            <category><![CDATA[retro-gaming]]></category>
            <category><![CDATA[basic-programs]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Sun, 28 Mar 2021 20:17:50 GMT</pubDate>
            <atom:updated>2021-04-05T05:45:54.018Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="http://medium.com/codex">CODEX</a></h4><h4>A mysterious algorithm from Atari 2600 to Commodore 64</h4><p>Thanks to a random Twitter list I have found an interesting paper and I have become aware of the existence of a field of research called <em>Archeogaming </em>which uses the approaches and the methodology coming from archeology, historiography, and software engineering to dissect and analyze the design and the implementation of ancient video games.</p><p>The paper is <a href="https://doi.org/10.22152/programming-journal.org/2019/3/4"><em>Entombed: An archaeological examination of an Atari 2600 game</em></a> and is a first, successful (in my opinion) attempt to formalize the Archeogaming field of research.</p><p>The paper is really interesting and it is fun to read and, as the title suggests, it provides a detailed analysis of the implementation of the videogame Entombed for Atari 2600: I will not go in details here because the paper has everything you need to know well explained but, for the sake of clarity, you just need to know that the game is about a character, driven by the player, that has to run across a <em>randomly</em> generated maze.</p><p>The emphasis on the word randomly is because having a different maze on every new game would greatly benefit the <em>replayability of the game</em>, that is the fact of being suitable for or worth playing more than once.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F5ObOxi-B9zM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5ObOxi-B9zM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F5ObOxi-B9zM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/41a996a48c9fabe80350123546d633d9/href">https://medium.com/media/41a996a48c9fabe80350123546d633d9/href</a></iframe><h4>The generation of a new line of the maze</h4><p>In the video is clearly shown how the game works: the player has to keep moving downward while the maze scrolls toward him. The maze is composed by</p><p>The algorithm provides a simple way to generate a new line of the maze as long as it scrolls upward. The maze is 20 blocks wide and each line of the maze has the two leftmost and rightmost blocks always occupied by a wall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*77yDIl8YgONnFCMsPNxPQg.png" /><figcaption>An image of the playfield (Image took from the original paper)</figcaption></figure><p>Every new line is a function of the line immediately above and it has to fill the remaining 16 blocks of the line. Another simplification, which also adds some kind of aesthetic to the generated maze, is the fact that only 8 leftmost blocks are generated while the remaining 8 blocks are just the same blocks but mirrored: in the next figure you can see a schematic representation of the algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7zc_fSPnphBhIdc5aGYzDQ.png" /><figcaption>The generation of a new line (handwritten by me)</figcaption></figure><h4>Drunk late-night programming</h4><p>The generation of each new block takes into account the context of that block. In the next figure you can see how this happens: to generate the block in position <em>X</em> the content of the blocks in position <em>a,b,c,d,e </em>is considered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*kw0jJDFDG5CtE6blSJBtxQ.png" /><figcaption>The context to generate block X is the content of the block a,b,c,d,e (image from the original paper)</figcaption></figure><p>The algorithm uses a table to decide the content in block <em>X</em> the table has an entry for each combination of the blocks. In the following figure you can see the first 12 rows the table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*9i0wJmHH3vhhxRJC0c5XIw.png" /><figcaption>Extract of the Mystery table mapping used for maze generation (full table in the original paper)</figcaption></figure><p>It is worth noting that the table, is dubbed as <em>Mystery table</em> in the paper because there is no clear pattern describing how the rows were defined nor the original programmer was able to recall how he actually did it because <em>“he was drunk and whacked out of his brain, he coded it up in assembly overnight before he passed out, but now could not for the life of him remember how the algorithm worked”</em></p><p>Each row of the table, depending on the values of the cells in the position <em>a,b,c,d,</em> and <em>e</em>, contains a 0, 1, or random: 0 means that the <em>x</em> cell will contain empty space, in which the player’s character will be able to walk; 1 will generate a wall block in the <em>x</em> cell and random will randomly generate a block or space.</p><h4>Porting to Commodore 64 Basic</h4><p>Porting to Commodore 64 Basic v2 in the 21st century is an interesting job. At the core, there is the Mystery table that has been rendered as an array loaded from that DATA statement of C64 Basic. Another detail of the C64 version is that it uses the standard random number generator instead of the implementation of a pseudo-random number generator, as described in the paper.</p><p>Following you will find the source code in pure C64 Basic:</p><pre>10 DIM Z(31):FOR I=0 TO 31:READZ(I):NEXTI:?&quot;{CLEAR}&quot;:S=1986:K=102<br>20 FOR I=0TO1:POKE 1984+I,K:POKE2003-I,K:NEXT I<br>30 FOR X=S TO 1993<br>40 A=-(PEEK(X-2)&gt;32)*16:IF X=S THEN A=16<br>50 B=-(PEEK(X-1)&gt;32)*8:IF X=S THEN B=0<br>60 C=-(PEEK(X-41)&gt;32)*4:IF X=S THEN C=INT(RND(1)+.5)*4<br>70 D=-(PEEK(X-40)&gt;32)*2<br>80 E=-(PEEK(X-39)&gt;32)<br>90 V=Z(A+B+C+D+E):IF V=2 THEN V=(INT(RND(1)+.5))<br>100 IF V=1 THEN POKEX,K:POKE3987-X,K<br>110 NEXT X:SYS 59626:GOTO 20<br>120 DATA 1,1,1,2,0,0,2,2,1,1,1,1,2,0,0,0<br>130 DATA 1,1,1,2,0,0,0,0,2,0,1,2,2,0,0,0</pre><p>Line 10 — Initialization of the array Z that contains the Mystery table with data read from lines 120–130. Initialization of a couple of variables: S is the first position generated by the algorithm (two cells rightward to the lower-left screen cell)</p><p>Line 20 — Draws the two cells stripes on the leftmost and rightmost part of the newly generated line, which is always the lowest line on the screen</p><p>Line 30 — Here it begins the proper drawing cycle whose body finishes on line 110. On each line is calculated the value for <em>a,b,c,d,</em> and <em>e </em>by PEEKing in the C64 screen memory. The five values are combined in a bit string whose value, as an integer, is used for the index to select the proper line in the Mystery table, kept in an array Z().</p><p>Lines 40 to 80 — Calculate the letters <em>a,b,c,d,</em> and <em>e</em>. Note that lines 40, 50, and 60 a special check is performed: as described in the original paper, the leftmost cell of the new line of the maze is calculated differently because a, b and c will coincide with the always present two cells stripe (generated on line 20). The values, in this special case, are a=1, b=0, and c equal to a random number between 0 and 1.</p><p>Line 90 — Recover the proper line Z by adding <em>a,b,c,d,</em> and <em>e. </em>If the value the array Z() is 2 then the cell can be randomly empty or full.</p><p>Line 100 — Draw a cell if, in the previous line, we got a 1 from the lookup in the table or generated it: in this case the cell, at the address X, is POKEd with the character whose code is kept in K.</p><p>Line 110 — Close the cycle. The SYS call will just scroll upward the screen adding a blank line. The GOTO will restart the cycle drawing a new line of the maze.</p><p>The result is shown in the following image, your run will (hopefully) be different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*NjfJVKs6VjcBInYwmuBtfg.png" /><figcaption>Execution of the resulting maze running on an emulated C64</figcaption></figure><h3>Conclusion</h3><p>Where to move on from here, a couple of hints: the code presents can be compressed in order to have a compact version and, maybe, participate in the <a href="https://gkanold.wixsite.com/homeputerium/rules2021">BASIC TENLINER CONTEST</a>. An example is the following code (CAVEAT: not totally functionally equivalent to the previous) that runs on just 5 lines of code:</p><pre>10dIZ(31):fOI=0TO31:rEZ(I):nE:?&quot;{CLEAR}&quot;:S=1986:K=102:<br>20fOI=0TO1:pO1984+I,K:pO2003-I,K:nE:fOX=STO1993<br>40V=Z(-(pE(X-2)&gt;32)*16-(pE(X-1)&gt;32)*8-(pE(X-41)&gt;32)*4-(pE(X-40)&gt;32)*2-(pE(X-39)&gt;32)):IFV=2tHV=INT(rN(1)+.5)<br>50IF V=1 THEN POKEX,K:POKE3987-X,K<br>60NEXT:SYS59626:gO20:dA1,1,1,2,,,2,2,1,1,1,1,2,,,,1,1,1,2,,,,,2,,1,2,2,,,</pre><p>The code above, which can still be compressed, even more, leaves room for adding the game logic, for a fully functional Entombed clone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bb3b34e8f9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/random-maze-from-entombed-8bb3b34e8f9b">Random maze from Entombed</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity: who the heck is msg.sender?]]></title>
            <link>https://medium.com/coinmonks/solidity-who-the-heck-is-msg-sender-de68d3e98454?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/de68d3e98454</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[virtual-machine]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Mon, 15 Mar 2021 07:52:26 GMT</pubDate>
            <atom:updated>2021-03-17T09:51:29.051Z</atom:updated>
            <content:encoded><![CDATA[<p>Here we will shortly discuss how the msg.sender mechanism works. As usual we will experiment with small chunks of Solidity that you will be able to run in your browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lqrFZ5_mSnuwP4ef" /></figure><p>At the core of the blockchain is the mechanism of adding blocks of transactions to the chain of blocks: this is the job carried out by the miners that keep the state of the Ethereum Virtual Machine (EVM) consistent; miners are in a competition to append transactions to blocks.</p><p>The state of the EVM is the effect of the execution of all the transactions collected in blocks: in a way Ethereum (and blockchains in general) are a <em>distributed log file </em>that collect the result of operations performed by smart contracts. Another way is to consider the blockchain as a <a href="https://solidity.readthedocs.io/en/v0.4.21/introduction-to-smart-contracts.html#transactions"><em>globally shared, transactional database</em></a>.</p><p>Operations on smart contracts are ignited by a simple mechanism of sending gas to an address, if the address is a smart contract it will produce an invocation of a method whose name is hashed within the transaction payload. following an example of how to invoke a method store(uint256) on a smart contract with the parameter 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*yWggUKJ9vnmV138XvNGmHQ.png" /><figcaption>The method store(uint256) and its invocation with parameter 1, notice the input and decoded input</figcaption></figure><p>What really happens in a transaction containing a method invocation is that the method signature, store(uint256) is hashed with <a href="https://en.wikipedia.org/wiki/SHA-3">keccak256</a> and the first 4 bytes are packed together with the arguments; this sequence of bytes is the content of the input field in the transaction above. More complex parameters (e.g. strings, arrays etc..) are packed in a sensible way by serializing them and concatenating together with the function hash.</p><p>In depth analysis can be found <a href="https://medium.com/linum-labs/a-technical-primer-on-using-encoded-function-calls-50e2b9939223">here</a> but, for the sake of the clarity of this article, the sense of this packing is to have a compact representation of the function name together with all the parameters and this is what you find in the input field of the transaction in <a href="https://remix.ethereum.org/">Remix</a> and you also find it decoded in the inspector.</p><h3>The sender of the transaction</h3><p>Among the fields of each of the transactions, in Remix, you may notice the field from which is the originating account of the transaction. In Remix it is pretty straightforward to notice how the content of this field matches exactly with the field Account, on the left (see next figure)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLSiwrgoxrwAYx8B9AhxjQ.png" /><figcaption>As you may expect the account on the left matches the field from in the transaction receipt</figcaption></figure><p>This mechanism is quite easy but in the Ethereum specification there are two different functions to access, in Solidity, to the sender of a transaction: msg.senderand tx.origin. A couple of simple functions allows you to check that both functions returns exactly the same value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hAoF62Y4KWPs4OfxAUyQaQ.png" /><figcaption>inspectOrigin and inspectSender return the same value: the account used to call them</figcaption></figure><p>Are they redundant? Not at all, there is a difference, and can be emphasized in the section.</p><h3>A simple smart contract to show the difference</h3><p>The difference between the two is thatmsg.sender contains the address that has originated the call while tx.origin contains the originator of the transaction. To clarify the way the two variables work you can use the following piece of code, ready to be tested right in Remix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3611f1a2a1468f1fb0be6f25f9330059/href">https://medium.com/media/3611f1a2a1468f1fb0be6f25f9330059/href</a></iframe><p>The source contains two different contracts, one called Storage the other one is Caller and contains an instance of Storage in the field StorageObject.</p><p>The instance of Storage is created in the constructor of Caller(line 28).</p><p>Both contracts contain the same functions that will return the content of msg.sender and the content of tx.origin. But what really will shed light on the difference are the two methods (line 34 and 42): they will return the content of msg.sender and tx.origin from the point of view of the instance of Storage.</p><p>As usual the test is more explanatory than words describing it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*dNg5Q9L_SjJwCQ_ySDojGQ.png" /></figure><p>What you can see here is: the tx.origin contains the same value in both contracts, Storage with the function inspectOrigin and Caller with the function inspectInspectOrigin, because for both the originator of the call is the account 0x5B38...C4. You may notice the difference with the result of inspectSenderand inspectInspectSender, they both return the msg.sender but, respectively, for Callerand Storagethe result is different, as expected. For Callerthe msg.sender(function inspectSender) is, again, the account 0x5B38...C4 while for the smart contract Storage it is the address 0x9d7f...99, which <em>is the address of the smart contract </em>Caller.</p><p>The documentation (you can find it <a href="https://docs.soliditylang.org/en/v0.5.3/miscellaneous.html?highlight=tx.origin#global-variables">here</a>) is simple but it is always interesting to check what really happens under the hood.</p><blockquote>Join Coinmonks <a href="https://t.me/joinchat/EPmjKpNYwRMsBI4p">Telegram group</a> and learn about crypto trading and investing</blockquote><h4>Also, Read</h4><ul><li>The Best <a href="https://medium.com/coinmonks/crypto-trading-bot-c2ffce8acb2a">Crypto Trading Bot</a></li><li><a href="https://medium.com/coinmonks/bitcoin-exchange-in-india-7f1fe79715c9">Bitcoin exchange in India</a></li><li><a href="https://medium.com/coinmonks/bitcoin-savings-account-e65b13f92451">Bitcoin Savings Account</a></li><li>The Best <a href="https://medium.com/coinmonks/best-crypto-tax-tool-for-my-money-72d4b430816b">Crypto Tax Software</a></li><li><a href="https://blog.coincodecap.com/grid-trading">Grid Trading</a> | <a href="https://medium.com/coinmonks/blockfi-review-53096053c097">BlockFi Review</a></li><li><a href="https://medium.com/coinmonks/crypto-exchange-dd2f9d6f3769">Best Crypto Exchange</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de68d3e98454" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/solidity-who-the-heck-is-msg-sender-de68d3e98454">Solidity: who the heck is msg.sender?</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Theory of complexity: a gentle introduction]]></title>
            <link>https://rosdec.medium.com/theory-of-complexity-a-gentle-introduction-72270e1037ae?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/72270e1037ae</guid>
            <category><![CDATA[birds]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[bonds]]></category>
            <category><![CDATA[complexity]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 17:33:00 GMT</pubDate>
            <atom:updated>2020-10-24T17:33:00.031Z</atom:updated>
            <content:encoded><![CDATA[<p>Reality is complex: please note that in the previous sentence complex has a very specific meaning; let’s just investigate a little more about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yhLkxEvnbM0Yw7w_" /><figcaption>Photo by <a href="https://unsplash.com/@hikeshaw?utm_source=medium&amp;utm_medium=referral">H Shaw</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Complexity</h3><p>Complexity theory has been inspired by some famous problems that come to the attention of the scientific community in the final decades of ‘800. One famous instance of such a family of problems is the <a href="https://en.wikipedia.org/wiki/Three-body_problem">Three-body problem</a>: let pick three <em>bodies</em> in space (planets, satellites, etc…); we know that they are subject to the gravitational laws; to simplify things let consider them far away from each other object, so we can suppose that gravitational laws are applied just to them three; given the initial positions and velocities of such bodies we want calculate their positions in any successive moment in time.</p><p>There is no general analytical solution to the three-body problem given by simple algebraic expressions and integrals: that is there is no compact way of represent the positions of the bodies.</p><p>Having an analytical solution would allow to forecast any future position of the bodies directly and precisely, furthermore it would also allow to “invert” the calculation letting us to answer, precisely, to the question “Where would the three bodies should be at time t₀ to meet here in such position in time tₙ?”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*VhYbffEDXIOJ2EU8yuNHLw.png" /><figcaption>Three bodies subject to the gravitation laws, where they will end up?</figcaption></figure><p>Just to have a taste of how fast complexity arises consider that the <a href="https://en.wikipedia.org/wiki/Two-body_problem">Two-body problem </a>does actually have an analytic solution that can be used to calculate the position of the two bodies starting from the initial conditions.</p><p>Other examples of problems where complexity arises are the following:</p><ul><li>Cellular automata</li><li>Interactions within the terrestrial crust to forecast earthquakes</li><li>Weather forecast</li><li>Ecosystems in general, social systems and economical systems in details, for example</li><li>The complex interactions between our organs</li></ul><p>You might instinctively see a pattern here: the more components are involved and the largest is the variety of interactions and relations between such elements, the more the <em>complexity </em>of the system is. In previous example just going from <em>two</em> bodies to <em>three</em> bodies makes things <em>complex</em>. Another characteristic of complex systems is that they usually present an <em>emergent behavior</em>: a complex behavior that cannot be forecast and that has not been forced by any of the laws the systems obey to.</p><h3>Emergent behaviors</h3><p>A nice example of this emergent behavior is displayed in the following video (you can play with the code from <a href="https://github.com/jackaperkins/boids">this repository on github</a>)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQbUPfMXXQIY%3Fstart%3D65%26feature%3Doembed%26start%3D65&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQbUPfMXXQIY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQbUPfMXXQIY%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/542dba12a9d38216f218e68151cd67be/href">https://medium.com/media/542dba12a9d38216f218e68151cd67be/href</a></iframe><p>In the video you can see a bunch some sort of simulated birds, <em>birdoids, boids </em>for short, or generally speaking, agents. Each of the agent obey to simple rules (you can read more <a href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.103.7187">here </a>where the general idea was described):</p><blockquote>1. Collision Avoidance: avoid collisions with nearby flockmates</blockquote><blockquote>2. Velocity Matching: attempt to match velocity with nearby flockmates</blockquote><blockquote>3. Flock Centering: attempt to stay close to nearby flockmates</blockquote><p>The rules are simple, each of the agent take a decision by its limited awareness of the boids around it. There is no central coordination, there is not even a proper communication between the boids: they just keep an eye on the few flockmates that are around.</p><p>The emergent behavior is that soon or later scattered boids will end up in one single flock: the single flock will <em>emerge</em> even if it is not encoded in any of the rules followed by the boids.</p><h3>Simulations</h3><p>So we have that boids are a complex system, that cannot be represented in a compact form, so it cannot be studied analytically, it is a form of n-body system, so even more complex than the three-body problem described above; we cannot analyze it but we can efficiently <em>simulate it</em> and by simulate I mean you can impose initial condition and check how it evolves.</p><p>Simulations are a powerful and effective tool to tackle complexity, they allow to wrap our mind around problems that you cannot state as equations, they enable you to check how your problems scale up when tens of components (agents, cars, planets etc…) are involved.</p><p>For example with <a href="https://ccl.northwestern.edu/netlogo/">Netlogo </a>you can simulate the n-bodies problem, <a href="http://www.netlogoweb.org/launch#http://www.netlogoweb.org/assets/modelslib/Sample%20Models/Chemistry%20&amp;%20Physics/Mechanics/Unverified/N-Bodies.nlogo">right into your browser</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*akX3T7nSDoNuATSAfPD5ew.png" /><figcaption>A 16-bodies problem running right in your browser</figcaption></figure><h3>Conclusion</h3><p>In conclusion, complexity is right behind the corner in a wide range of useful, interesting, funny, problems. A stimulating way to tackle the complexity is to setting up a simulation where you will be allowed to inspect your problem and forecast about how it scales and behave.</p><h3>References</h3><ol><li>Reynolds, Craig (1987). <em>Flocks, herds and schools: A distributed behavioral model</em>. <em>SIGGRAPH ’87: Proceedings of the 14th Annual Conference on Computer Graphics and Interactive Techniques</em>. Association for Computing Machinery. pp. 25–34.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72270e1037ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity: Do We Really Need a Safer Math?]]></title>
            <link>https://medium.com/better-programming/solidity-do-we-really-need-a-safer-math-733ea7a9ea44?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/733ea7a9ea44</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Thu, 08 Oct 2020 17:39:36 GMT</pubDate>
            <atom:updated>2020-10-08T17:39:36.311Z</atom:updated>
            <content:encoded><![CDATA[<h4>A look at the SafeMath library from OpenZeppelin</h4><figure><img alt="Crystals" src="https://cdn-images-1.medium.com/max/1024/0*n0-bQNcRIOm_6WPm" /><figcaption>Photo by <a href="https://unsplash.com/@lazycreekimages?utm_source=medium&amp;utm_medium=referral">Michael Dziedzic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>In Solidity, there are plenty of different alternatives to things you take for granted in other languages. <a href="https://medium.com/better-programming/solidity-playing-with-strings-aca62d118ae5">Strings</a> and math are two examples.</p><blockquote>“Arithmetic operations in Solidity wrap on overflow. This can easily result in bugs, because programmers usually assume that an overflow raises an error, which is the standard behavior in high level programming languages. `SafeMath` restores this intuition by reverting the transaction when an operation overflows.</blockquote><blockquote>Using this library instead of the unchecked operations eliminates an entire class of bugs, so it’s recommended to use it always.” — <a href="https://docs.openzeppelin.com/contracts/3.x/api/math">OpenZeppelin docs</a></blockquote><p>“Operations in Solidity wrap on overflow” refers to a specific thing bound to the way numbers are represented in computers and in Solidity, in particular.</p><p>In the following smart contract, I have implemented a simple method to test the underflow and the overflow (as usual, right in <a href="https://remix.ethereum.org/">Remix</a>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14e85ebdcf947ac749959021d544e34c/href">https://medium.com/media/14e85ebdcf947ac749959021d544e34c/href</a></iframe><p>Once compiled, you will be able to invoke the two methods that — with the appropriate inputs — will show the weakness of the native number representation:</p><figure><img alt="Input of methods" src="https://cdn-images-1.medium.com/max/428/1*zTAPOmrWIYD9H5zvZDD-UQ.png" /></figure><p>Please note how I’ve used int8 as the type of input and output of the methods. This will allow me to rapidly describe the implementation.</p><figure><img alt="Output of methods" src="https://cdn-images-1.medium.com/max/440/1*E_sXOe3R_EBf1hB6MGhUZg.png" /></figure><p>What you see in the previous figure is what the sentence “operations in Solidity wrap on overflow” means. Now, just imagine if the uint8 we fiddled with represents an amount of some precious assets. This just means that your system will work gloriously in the majority of cases (increments and decrements far from the limits of the representation) and will fail dramatically, producing an inconsistent state.</p><p>At this point, it is clear that <em>we do need a safer math — </em>even in the simplest smart contract.</p><p>Let’s now see how the previous example works using <a href="https://docs.openzeppelin.com/contracts/2.x/api/math#safemath">SafeMath</a> for the increments/decrements.</p><p>SafeMath is provided by OpenZeppelin for uint256. This means that it will never overflow with our example that uses uint8. For example, you should overflow if you pass a 255, but it will not because it will be represented within SafeMath as a uint256.</p><p>For the sake of clarity, I have “developed” a uint8 SafeMath version by simply replacing uint256 with uint8 in the original SafeMath. And I have named it SafeMath8:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f64a04047ff967c4932ffa201297558f/href">https://medium.com/media/f64a04047ff967c4932ffa201297558f/href</a></iframe><p>You can use it right in Remix and import it as shown in the following example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b68ffecbaee5611434d33d46d766cdf/href">https://medium.com/media/2b68ffecbaee5611434d33d46d766cdf/href</a></iframe><p>As you may notice, we ask Solidity to “attach” the methods defined in SafeMath8 to the uint8. This way, we are allowed to invoke the methods sub() and add() that represent the new, safer way of subtracting and adding two unsigned integers.</p><p>The next figure shows what you get by invoking the two methods with the parameters to get overflow/underflow:</p><figure><img alt="Result of invoking the two methods" src="https://cdn-images-1.medium.com/max/442/1*qkOkR8TBeaDsIjMVjkGITQ.png" /></figure><p>By invoking the methods, you will not get any result apart from what is shown in the console for the two invocations:</p><figure><img alt="Result in the console" src="https://cdn-images-1.medium.com/max/1024/1*gz0eAm_k0ACsEaXp9HtkHA.png" /></figure><p>The two methods fail with a proper error message returned in human-readable form.</p><h3>Conclusion</h3><p>SafeMath (and SafeMath8) is the foundation on which to build a safe smart contract. This is particularly important considering that you will usually handle assets that (hopefully) will be worth hundreds of <em>fiat coins</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=733ea7a9ea44" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/solidity-do-we-really-need-a-safer-math-733ea7a9ea44">Solidity: Do We Really Need a Safer Math?</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity: Playing With Strings]]></title>
            <link>https://medium.com/better-programming/solidity-playing-with-strings-aca62d118ae5?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/aca62d118ae5</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[hashing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Mon, 28 Sep 2020 16:24:36 GMT</pubDate>
            <atom:updated>2022-04-30T08:14:49.698Z</atom:updated>
            <content:encoded><![CDATA[<h4>Getting started with Solidity</h4><figure><img alt="The word “WORLD” spelled in LED lights in a dark room." src="https://cdn-images-1.medium.com/max/1024/0*O8QzLOh7HE65dAcX" /><figcaption>Photo by <a href="https://unsplash.com/@martimbraz?utm_source=medium&amp;utm_medium=referral">Martim Braz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>Strings of characters represent the very heart of every programming language because, you know, computers often interact with humans. For this reason, handling strings is one of the first functionalities developed in any language. Furthermore, the first test traditionally <a href="https://en.wikipedia.org/wiki/%22Hello,_World!%22_program">prints the string</a> “Hello, world!”</p><p><a href="https://solidity.readthedocs.io/en/v0.7.1/">Solidity</a> is not an exception. It has native support for strings, but still, their use is not complete like in high-level languages such as JavaScript, Python, or Java. For instance, out of the box, Solidity does not offer a native way of comparing or concatenating strings. However, the documentation offers a valid solution for both functions that rely on abi.encodePacked() (we’ll talk about it later) to compare two strings:</p><pre>keccak256(abi.encodePacked(s1)) == keccak256(abi.encodePacked(s2)) </pre><p>And to concatenate two strings:</p><pre>abi.encodePacked(s1, s2)</pre><p>To better understand the inner mechanics of these two simple functions, as usual, we will use a simple toy implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c72fe0422b6290d779745c114efbe8d/href">https://medium.com/media/9c72fe0422b6290d779745c114efbe8d/href</a></iframe><p>As usual, you can comfortably play with it by using <a href="https://remix.ethereum.org/">Remix</a>. Once it is compiled, you will be able to invoke the two methods right from the interface:</p><figure><img alt="Screenshot showing how to invoke the methods." src="https://cdn-images-1.medium.com/max/445/1*k6IRXJWuwfXlsLCRYCxwtw.png" /><figcaption>The interface to invoke the methods.</figcaption></figure><p>Calling the two methods will sign a transaction containing an invocation to the method passing the arguments. The output of the transaction is displayed in the console windows following the execution of the string concatenation (to fully display the results, remember to click on the small arrow on the right):</p><figure><img alt="Decoded output." src="https://cdn-images-1.medium.com/max/771/1*7Ag33gEYo7UbBUBr9zQJOw.png" /><figcaption>Execution of the ‘concatenate’ method.</figcaption></figure><p>At the core of these two simple implementations is the function abi.encodePacked(), which performs a tight packing of the variables passed as arguments. In the following figure (taken from the <a href="https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#non-standard-packed-mode">documentation</a>), you can see how the bits of each of the arguments are simply concatenated in the output:</p><figure><img alt="Hand-written breakdown of how the arguments are packed." src="https://cdn-images-1.medium.com/max/688/1*svUelXdjHOadeiHo03gELA.png" /><figcaption>An example of how the arguments passed to encodePacked are actually packed.</figcaption></figure><p>An interesting point in this encoding is that it is <em>inherently ambiguous </em>so there is no way of decoding it. In the following code, we simply test this ambiguity by comparing the encoding of two sets of different strings. With the in-place packing, the two invocations will return the exact sequence of bytes because both invocations will return the string &quot;aab&quot; without considering the different length of the input strings:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d25100c17c109d427fd187d84f28669/href">https://medium.com/media/1d25100c17c109d427fd187d84f28669/href</a></iframe><p>Comparing the results of the encoding by usingkeccak256() is a common approach in Solidity because of its gas efficiency.</p><h3>Conclusion</h3><p>Basic string manipulation is offered by Solidity not natively but through a pretty standardized use of some native and efficient use.</p><p>There are more sophisticated string <a href="https://github.com/willitscale/solidity-util">manipulation</a> <a href="https://github.com/Arachnid/solidity-stringutils">libraries</a> available. There is <a href="https://github.com/chrisdotn/jsmnSol">even a JSON parser library</a>.</p><p>My personal advice is to keep this kind of manipulation as low as possible. Messages for the user, complex JSON manipulation, etc. should be kept away from the blockchain. Blockchain should be considered a specialized back end whose performances rely on the representation of each of the variables involved.</p><h3>References</h3><ol><li><a href="https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#non-standard-packed-mode">Solidity 7.1 Documentation</a></li><li><a href="https://github.com/Arachnid/solidity-stringutils">String &amp; slice utility library for Solidity</a></li><li><a href="https://github.com/willitscale/solidity-util">Solidity Standard Utilities</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aca62d118ae5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/solidity-playing-with-strings-aca62d118ae5">Solidity: Playing With Strings</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity: A Small Test of the Self-Destruct Operation]]></title>
            <link>https://medium.com/better-programming/solidity-what-happens-with-selfdestruct-f337fcaa58a7?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/f337fcaa58a7</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Mon, 14 Sep 2020 18:46:20 GMT</pubDate>
            <atom:updated>2020-09-18T16:43:29.872Z</atom:updated>
            <content:encoded><![CDATA[<h4>How ‘selfdestruct’ works in Solidity and how it affects the life of the freshly self-destructed smart contract</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UoyAmhflJpoAmaQnMaYzQA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@harrisonkugler?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Harrison Kugler</a> on <a href="https://unsplash.com/s/photos/crypto?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>For the purpose of this article, I have read some good sources, starting with “<a href="https://arxiv.org/pdf/2005.07908.pdf">Why Do Smart Contracts Self-Destruct? Investigating the Selfdestruct Function on Ethereum</a>,” a recent publication that really digs into self-destruct mechanisms. The selfdestruct command stands out in the general immutability of the blockchain: selfdestruct renders inoperable a smart contract. A motivating example of why an immutable blockchain needs such a powerful command is reported in this paper:</p><blockquote>“The DAO attack continued for several days and the organization even noticed that their contract had been attacked at that time. However, they could not stop the attack or transfer the Ethers because of the immutability feature of smart contracts. If the contract contains a selfdestruct function, the DAO organization can transfer all the Ethers easily, and reduce the financial loss.”</blockquote><p>If you want to know more about the DAO attack and its consequences, you can refer to references [2] and [3] at the end of this article.</p><p>About the opcode that is generated at the compilation of the selfdestruct method there is a nice story about the sensibility of the Ethereum community: Originally the opcode was named SUICIDE but they decided to rename it as SELFDESTRUCT because</p><blockquote>“Suicide is a heavy subject<strong> </strong>and we should make every effort possible to not affect those in our development community who suffer from depression or who have recently lost someone to suicide.” — <a href="https://eips.ethereum.org/EIPS/eip-6">EIP6</a></blockquote><p>Below you will find a small toy example that contains the smallest amount of logic to make some tests. It is easily executable using <a href="https://remix.ethereum.org/">Remix</a>, so you can try it even without installing the development environment.</p><pre>pragma solidity &gt;0.6.0;</pre><pre>contract Storage {<br> address payable private owner;<br> uint256 number;</pre><pre> constructor() {<br>  owner = msg.sender;<br> }</pre><pre> function store(uint256 num) public {<br>  number = num;<br> }</pre><pre> function retrieve() public view returns (uint256){<br>  return number;<br> }<br> <br> function close() public { <br>  selfdestruct(owner); <br> }<br>}</pre><p>Below is what happens after the deployment of the contract. In Remix, each of the methods of the smart contract is easily accessible on the left pane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*v9hzrpP5BkGlquY6CSWnJQ.png" /><figcaption>The methods of the smart contract right after the deployment</figcaption></figure><p>The first method to test is store, which will just store the integer value passed as a parameter in the internal state of the smart contract. The next method to test is retrieve, which, as the smartest among you might already have figured out, retrieves the value stored beforehand in the internal state. Calling this method before actually storing anything will just return 0 because <a href="https://solidity.readthedocs.io/en/v0.6.0/control-structures.html?highlight=default#scoping-and-declarations">the variable is zeroed by default</a>.</p><p>Invoking the close method will just execute selfdestruct without any further notification than what is reported in the next figure, a correctly executed transaction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9aSTS-gg1IQH4L4WhZoMpw.png" /></figure><p>From now on, each interaction with the smart contract will be successful but still will not do anything.</p><p>This is, in a way, an inconsistency: The client that invokes the smart contract is not aware of the fact that the smart contract has been destroyed. For instance, in this particular smart contract, calling the retrieve method before and after the selfdestruct will return no error, and in the particular case where the internal variable contains 0, the two calls are indistinguishable (see the following figure).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3T8Z65x9nu9p9fy6jz1MVw.png" /><figcaption>The retrieve method called before (first call) and after (secondo call) the selfdestruct</figcaption></figure><p>The wrap up is, selfdestruct is designed to be the <em>extrema ratio</em> for a malfunctioning contract. It is the emergency button, the <a href="https://en.wikipedia.org/wiki/Scram">SCRAM</a> of your smart contract. Still, before calling it, consider adding additional logic to, for example, pass control to another smart contract.</p><p>As a further reading, I strongly suggest reference [1], below.</p><h3>References</h3><ol><li>Jiachi Chen, Xin Xia, David Lo, and John Grundy. 2016. “<a href="https://deepai.org/publication/why-do-smart-contracts-self-destruct-investigating-the-selfdestruct-function-on-ethereum">Why Do Smart Contracts Self-Destruct? Investigating the Selfdestruct Function on Ethereum</a>” (January 2016), 27 pages</li><li><a href="https://en.wikipedia.org/wiki/The_DAO_(organization)">https://en.wikipedia.org/wiki/The_DAO_(organization)</a></li><li><a href="https://www.coindesk.com/understanding-dao-hack-journalists">https://www.coindesk.com/understanding-dao-hack-journalists</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f337fcaa58a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/solidity-what-happens-with-selfdestruct-f337fcaa58a7">Solidity: A Small Test of the Self-Destruct Operation</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logstash to Azure Event Hub]]></title>
            <link>https://rosdec.medium.com/logstash-to-eventhub-d1089dc4ebdb?source=rss-841663334bca------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1089dc4ebdb</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[event-hub]]></category>
            <category><![CDATA[enterprise-technology]]></category>
            <category><![CDATA[logstash]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Rosario De Chiara]]></dc:creator>
            <pubDate>Fri, 26 Oct 2018 08:12:40 GMT</pubDate>
            <atom:updated>2020-10-25T06:40:12.927Z</atom:updated>
            <content:encoded><![CDATA[<h3>Send data from Logstash to Azure Event Hubs</h3><p>In this short tutorial I will try to summarize few simple steps to configure <a href="https://www.elastic.co/products/logstash">Logstash</a> to emit data to <a href="https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-about">Azure Event Hubs</a> Before starting just few words to describe the two components we will work on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k8ru5eOynu_4gNmF" /><figcaption>“brown tree log lot” by <a href="https://unsplash.com/@dimitri_tyan?utm_source=medium&amp;utm_medium=referral">Dimitri Tyan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><em>Logstash</em> — it’s a data processing pipeline that ingests, as rapidly as it can, data from a multitude of sources simultaneously, (slightly) transforms it, and then sends it to your favorite “stash”. It is designed to read logs, wherever they are hosted, and send them over, as fast it is possible, to the broker that will memorize, manipulate, display them. The general advice is to keep the pipeline as light is possible (i.e. coarse grain filtering, clean up date format etc…) by delegating heavy lift (i.e. regex, correlations between different log lines etc…) to dedicated components, for example <a href="https://www.elastic.co/">Elasticsearch</a> or to Azure Event Hubs</p><p><em>Azure Event Hubs</em> — Azure Event Hubs is a streaming platform and event ingestion service, capable of receiving and processing millions of events per second. It is a PaaS available on Microsoft Azure and is greatly scalable with a pay as you go model.</p><h3>Dan Rosanova on Twitter</h3><p>2.0066 TRILLION requests to #AzureEventHubs on May 23 2018. That&#39;s some scale! @Azure</p><p>Event Hubs are similar to <a href="https://kafka.apache.org/">Apache Kafka</a>.</p><p>The problem we intend to solve in this tutorial is to connect Logstash to Event Hubs: the task is pretty straightforward but there are <em>at least </em>two ways of doing this: (a) to use Event Hubs http endpoint; (b) use the <a href="https://azure.microsoft.com/en-us/blog/azure-event-hubs-for-kafka-ecosystems-in-public-preview/"><em>experimental</em></a> (at the time of writing) Kafka interface of Event Hubs. The general idea is to keep this simple so we go for (a). The next picture represents the (simple) architecture of the system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*8_izs14TZ-lpRUMdhnxppQ.png" /><figcaption>Architecture of the system</figcaption></figure><ul><li>Let start from Event Hub: the first step is to create an Event Hubs Namespace and within it create an Event Hubs. Event Hubs will collect different hubs. This hierarchy will be translated to a proper URL for each hub according to the following schema:</li></ul><pre>https://{yournamespace}.servicebus.windows.net/{yourhub}</pre><ul><li>Commonly to many other Azure PaaS components the access to the service is ruled by randomly generated key. These can be found in the SAS (Shared access policy) page on your Event Hubs Namespace. The Keys will come handy when you have to generate the URL to be called within the Logstash configuration. In the next image is shown the SAS Policy page showing the (redacted) keys for my namespace.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*lipL7ER1mTaGuDRra8rYww.png" /><figcaption>SAS Policy page</figcaption></figure><ul><li>To verify that your installation works and it is reachable from your network (not so obvious considering enterprises’ proxies) you can use the <a href="https://github.com/paolosalvatori/ServiceBusExplorer">Service Bus Explorer</a>. By using the connection string from the previous step, you will be able to connect to the Event Hub and verify that everything is working.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*8B5BIeBdx2NGqz1zlxyNXA.png" /></figure><ul><li>The next step is to generate the SAS token that is the real chunk of byte useful to actually connect on the REST interface. To do so go to <a href="https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token">this page</a>, choose your language and generate the SAS token. This process is pretty straight forward: it will just use the data you can find in the SAS Policy page (previous item) and fill the fields in the code. As and example following you find the Powershell chunk of code to generate the SAS token, the code is pretty simple but you must take care of some details: replace the {yournamespace} and {yourhub} with the proper strings from your Event Hubs; the variable $Access_Policy_Name contains the name o the policy, the value you find in the code is fine in the most common case, in case you have more complex policy schema you have to replace this with the policy you are going to use; the variable $SASToken will contain the SAS token (!) to be used in your Logstash configuration: it has an expiration date that is set to now+300 seconds, as stated in the code, modify the 300 value to give the token a longer expiration date.</li></ul><blockquote>SAS token usually tend to expires the morning you have the big demo so carefully set this value to sometimes in a distant future.</blockquote><pre>[Reflection.Assembly]::LoadWithPartialName(“System.Web”)| out-null<br>$URI=”{yournamespace}.servicebus.windows.net/{yourhub}”<br>$Access_Policy_Name=”RootManageSharedAccessKey”<br>$Access_Policy_Key=”myPrimaryKey”<br>#Token expires now+300<br>$Expires=([DateTimeOffset]::Now.ToUnixTimeSeconds())+300<br>$SignatureString=[System.Web.HttpUtility]::UrlEncode($URI)+ “`n” + [string]$Expires<br>$HMAC = New-Object System.Security.Cryptography.HMACSHA256<br>$HMAC.key = [Text.Encoding]::ASCII.GetBytes($Access_Policy_Key)<br>$Signature = $HMAC.ComputeHash([Text.Encoding]::ASCII.GetBytes($SignatureString))<br>$Signature = [Convert]::ToBase64String($Signature)<br>$SASToken = “SharedAccessSignature sr=” + [System.Web.HttpUtility]::UrlEncode($URI) + “&amp;sig=” + [System.Web.HttpUtility]::UrlEncode($Signature) + “&amp;se=” + $Expires + “&amp;skn=” + $Access_Policy_Name<br>$SASToken</pre><ul><li>The key you will generate in the previous step is in <a href="https://tools.ietf.org/html/draft-hardt-oauth-01">WRAP format</a>, whatever it is. For the purposes of this article it is enough to know that it means will have this format (beware of the placeholders):</li></ul><pre>SharedAccessSignature sr={yournamespace}.servicebus.windows.net%2f{yourhub}&amp;sig={redactedkey}&amp;se={expirationtime}&amp;skn=RootManageSharedAccessKeyù</pre><ul><li>Now we can work on the Logstash side. Once again, for the purposes of the article I will keep this as simple is possible so I will just configure Logstash to take input from stdin (your keyboard) and send them to Event Hub with any further elaboration. Following you find the Logstash configuration file (beware of the placeholders), please note that it is particularly important to properly set the headersof the http request.</li></ul><pre>input { stdin{} }<br>filter {}<br>output {<br> stdout { codec =&gt; rubydebug }<br> http {<br>  url =&gt;    <br> &quot;https://{yournamespace}.servicebus.windows.net/{yourhub}/messages&quot;<br>  content_type =&gt; <br>   &quot;application/x-www-form-urlencoded&quot;<br>  http_method =&gt; <br>   &quot;post&quot;<br>  format =&gt; <br>   &quot;message&quot;<br>  message =&gt;<br>   &#39;%{@timestamp} : %{message}&#39;<br>  headers =&gt; {<br>    &quot;Host&quot; =&gt; &quot;{yournamespace}.servicebus.windows.net&quot;<br>    &quot;Authorization&quot; =&gt; &quot;SharedAccessSignature sr={yournamespace}.servicebus.windows.net%2f{yourhub}&amp;sig={redactedkey}&amp;se={expirationtime}&amp;skn=RootManageSharedAccessKey&quot;<br>  }<br> }<br>}</pre><ul><li>Now all should be set to test the whole thing with logstash -f yourconfiguration.conf . Please not that in the configuration we have left stdout among the output, allowing us to print on the console what we are going to send to Event Hub. If everything is correctly set then you should see something like this every time you type some text and press Enter:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*bWuASN-EYIJAGyvJGQ4CMQ.png" /></figure><ul><li>In the Service Bus Explorer window you should be able to see the messages coming through as along as you type them in the console:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*377tfclX4ijgk5HnmFSXkw.png" /><figcaption>Messages finally reaching Event Hub</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1089dc4ebdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>