<?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"><channel><title><![CDATA[Beshoy Shehata]]></title><description><![CDATA[I'm writing to teach myself about Blockchain, Solidity Programming, and DeFi]]></description><link>https://blog.beshoy.io</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 16:55:56 GMT</lastBuildDate><atom:link href="https://blog.beshoy.io/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A Bird's-eye View of Decentralized Finance - (DeFi)]]></title><description><![CDATA[Introduction
This article is part of DeFi Talents mentorship program as an assignment required to graduate from the program. In the article, I'll discuss a general overview of the DeFi ecosystem.
What is Decentralized Finance (DeFi)?
Before we dive d...]]></description><link>https://blog.beshoy.io/a-birds-eye-view-of-decentralized-finance-defi</link><guid isPermaLink="true">https://blog.beshoy.io/a-birds-eye-view-of-decentralized-finance-defi</guid><category><![CDATA[decentralized finance]]></category><category><![CDATA[defi]]></category><category><![CDATA[Web3]]></category><category><![CDATA[Cryptocurrency]]></category><category><![CDATA[DeFi-Talents]]></category><dc:creator><![CDATA[Beshoy Shehata]]></dc:creator><pubDate>Mon, 15 Aug 2022 15:04:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1660575113864/MXQa5eNMF.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-introduction">Introduction</h3>
<p>This article is part of <a target="_blank" href="https://defi-talents.io/">DeFi Talents</a> mentorship program as an assignment required to graduate from the program. In the article, I'll discuss a general overview of the DeFi ecosystem.</p>
<h3 id="heading-what-is-decentralized-finance-defi">What is Decentralized Finance (DeFi)?</h3>
<p>Before we dive deeper into the building blocks of the DeFi ecosystem, let us first get an overview of some essential concepts and general ideas here</p>
<h4 id="heading-a-short-history-of-money-and-value-transfer">A short history of money and value transfer</h4>
<p>Why does finance even matter? And why we should care about "money" and "value"? to answer those questions we need to first know what they mean. Money, - whether it is cash or digital - in its current form is the biggest invention of humans in finance. In the beginning, people used to trade without money but used other goods in exchange for goods they need. And after some time, someone invented gold as a medium of exchange for those same goods and services. But gold has some problems when used to exchange value, it can't be divided into so many smaller pieces to represent much smaller amounts, and it isn't easy to carry, among many others, but those are the ones we care about here. After that, someone said, why can't we just hold that gold in a place and give people a "bond" that represents their "ownership" of the specified amount of gold, and let people exchange that bond among themselves instead of carrying gold all around. And that was the first representation of cash money in history. After that came the invention of banks as a way to protect people's money and let them earn some interest on top of it by using this money to fund (lend) other projects. And that was the true beginning of massively allowing people to transfer value among each other without the need to carry tons of gold and thinking of the security of it and the whole process.</p>
<h4 id="heading-definition-of-defi">Definition of DeFi</h4>
<p>So, how DeFi is related to all the above? Well, as we will see later in the article, DeFi as a concept won't be possible without the invention of Blockchain technology. We can define Decentralized Finance in simple English words as a way to perform traditional finance but in a decentralized way with no intermediaries between a protocol/project and the end user. Also, automation and compossibility are two of its main features as we will find out later.</p>
<h4 id="heading-how-it-works">How it works</h4>
<p>This image below (credits to <a target="_blank" href="https://en.wikipedia.org/wiki/Decentralized_finance#/media/File:The_DeFi_Stack_Figure.jpg">Wikipedia</a>) shows in a very short and visualized manner how DeFi works.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660528942662/8voCxupD0.jpg" alt="The_DeFi_Stack_Figure.jpg" class="image--center mx-auto" />
Decentralized finance is just a fancy word for how many financial components/products are composed and built on top of each other in a permissionless environment. This environment is built on top of the blockchain. See? everything is built on top of something else or by using some other project or protocol - compossibility at its finest.</p>
<h4 id="heading-problems-solved-by-defi">Problems solved by DeFi</h4>
<p>Ok, that's nice, but why didn't traditional financial institutions just be built the same way and everyone will be just happy? Because financial institutions are way multi-layered and there are way too many intermediaries in the middle of everything. For example, a simple traditional bank transfer can take between 3 working days to a week in normal cases for the transfer to arrive at its destination safely. But, imagine that, if somehow we can represent traditional monetary values into a digital form that can be exchanged between parties with no middle man - except for a small tiny program - and the transfer can take between just one second up to 10 minutes trusting nobody and with certain finality of the transaction, Isn't that great? Yea, that's the beauty of blockchain and DeFi.</p>
<h3 id="heading-decentralized-finance-infrastructure-and-building-blocks">Decentralized Finance Infrastructure and Building Blocks</h3>
<p>To better understand how DeFi works, we need to first understand how the underlying technologies that power the DeFi ecosystem work first. Mainly, it comprises the following technologies - Blockchain, Cryptocurrencies &amp; Wallets, Smart Contracts, Tokens, Oracles, and dApps (UI/IX)</p>
<h4 id="heading-blockchain">Blockchain</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660575216076/bk9LilX0M.png" alt="DLTdiagramV2.png" class="image--center mx-auto" />
Blockchain is a distributed ledger and database that is used to record transactions and data in a trustless and permissionless manner. The main difference between a normal database and a blockchain network is how each of them stores its data, in normal databases, we store data in tables with unique keys, to every record, but in the blockchain, world data is stored in blocks of transactions. These transactions can be anything from transferring value between two parties in a trustless way to storing a digital representation of ownership on the blockchain (which is known for short as tokenization).</p>
<h4 id="heading-cryptocurrencies-wallets">CryptoCurrencies / Wallets</h4>
<p>Cryptocurrencies are just the native money of a blockchain network, this "currency" is used to incentive certain people on the network called miners in a Proof-Of-Work blockchain (also called validators in a Proof-Of-Stake blockchain network) to record the transactions we talked about earlier in the blockchain so it'll be available for anybody to verify and validate its authenticity. They are also used as a way for end users to pay those miners/validators to include their transactions in the public network. These currencies can also represent monetary units when used as a medium of exchange of value between two or multiple parties (for example, someone may want to receive his/her transfer in ETH - the native currency of the Ethereum network - rather than USD). Ok, but where can we find and store these cryptic currencies, here comes the job of a digital wallet built for this specific reason, to hold the currency of a public blockchain network in a safe and easy-to-use way after we can easily buy them from an exchange (you can also win them by mining the public network and be part of the network as a miner yourself, but that's for another discussion).</p>
<h4 id="heading-smart-contracts">Smart Contracts</h4>
<p>Another building block of the DeFi ecosystem is Smart Contracts, which are the small tiny programs we touched upon earlier in our discussion, those tiny apps can make money programmable. When we represent monetary value on the blockchain using cryptocurrencies (or tokens, as we will discuss in the next section), we then can use smart contracts to create sci-fi-level scenarios of how this money can be used. For example, imagine if you want to create your own piggy bank and want it to be unlocked only at a certain point in time and won't allow you to withdraw whatever is in it, this can be done with a simple smart contract code on the blockchain, and this promise can't be broken (most of the time, unless there is a bug in the program's logic). This is just a very, very simple use case of the power a smart contract can have.</p>
<h4 id="heading-tokens-fungible-and-non-fungible">Tokens (Fungible and Non-Fungible)</h4>
<p>Tokens in the Ethereum blockchain are just a set of rules that can be implemented using a smart contract, using a set of rules among all tokens will allow compatibility among different protocols and projects to use tokens as a monetary unit or a transfer of value. The main token types are fungible and non-fungible tokens. Fungible tokens are similar tokens that have the same features among them, and each token transferred from one user to another holds the same value. On the contrary, non-fungible tokens are one of a kind that represents ownership of something - a very popular use case is the NFT mania of digital art.</p>
<h4 id="heading-oracles">Oracles</h4>
<p>One big drawback of using major blockchain technologies is the lack of communication to the internet or any other data source for example. The Ethereum network, for example, can't by default connect to the internet to grab the latest price of a stock and use that in a smart contract. Here comes the power of the Oracles, which are small programs that are built in a special way that allows other smart contracts to communicate with their smart contracts to grab specific data points from off-chain sources. A popular example of an oracle network is Chainlink</p>
<h4 id="heading-dapps">dApps</h4>
<p>Communicating directly with smart contracts can only be for the tech-savvy, so there should be a familiar way for users to use the blockchain and communicate easily with smart contracts without the need to invest so much time learning new technologies. And here comes the concept of dApps (which is an abbreviation for Decentralized Applications) which are normal web apps that use special web components to facilitate the communication process with the end user and the blockchain network. dApps aren't a set of rules that are shared between every dApp, no, they're just a concept with a set of tools and technologies that can be used. dApps play an important role here, because, without an easy way to access applications built on top of the blockchain by end users, there'll be no mass adoption of the technology.</p>
<h3 id="heading-decentralized-stablecoins">Decentralized Stablecoins</h3>
<p>Let us here talk about one of the main building blocks (right now) of a decentralized and trustless environment like the blockchain</p>
<h4 id="heading-what-are-stablecoins-and-why-do-we-use-them">What are Stablecoins and why do we use them?</h4>
<p>Cryptocurrencies can be very volatile all the time, and can't be easily used as a store of value without an excessive knowledge of how they work and the economics behind them, and a lot of other areas, still one can't be sure of how that can be used to store the value of a crypto asset. Here comes the introduction of stable-coins, and as the name implies, it's used to stabilize something, this "something" here is the volatility of cryptocurrencies. Stablecoins are just small smart contract applications that are being built on top of a public blockchain as tokens.</p>
<h4 id="heading-how-stablecoins-works">How Stablecoins works</h4>
<p>In simple terms, a stablecoins is just a representation of a real-world currency like USD for example, to be used on-chain as a medium of exchange. There are four main types of stablecoins that are used today: </p>
<ol>
<li><p><strong>Fiat-backed stablecoin</strong>: This is the most used type, and how it works is simple, you just buy a certain amount of dollars, for example, by depositing the dollars into the issuing company bank account and in return, they issue (mint) that same amount on-chain for you to be used as digital dollars (minus the fees), and this is how they maintain the peg of 1-to-1 USD to token ratio all the time. At any point in time, there should be one dollar in a bank account representing each token minted on-chain. One major disadvantage of this type is that they are very centralized. Major examples of this type are, USDC of Circle, USDT of Tether, and BUSD of Binance.</p>
</li>
<li><p><strong>Crypto-collateralized stablecoin</strong>: In this type, a peg of 1-to-1 USD to token ratio is maintained by over-collateralization of a cryptocurrency in the vault of a protocol. For example, to issue (mint) a representation of a 1 dollar token on-chain, a protocol asks for the deposit of a 150% equivalent amount in a specific cryptocurrency. Why is that? To make it safe for the protocol itself if the price of the cryptocurrency falls behind the price at the time of deposit, the protocol will sell the cryptocurrency at a small discount to encourage liquidity and to keep the peg to the dollar as a 1-to-1 maintained all the time. A major example of this type is DAI of MakerDAO.</p>
</li>
<li><p><strong>Algorithmic stablecoins</strong>: This is the most interesting type of stablecoins, in this type the dollar peg is maintained purely by the supply and demand mechanics of the market by utilizing mathematical equations that rule this peg. A major example of algo-stables is FRAX of FraxFinance </p>
</li>
<li><p><strong>Commodity-backed stablecoin</strong>: Similar to the fiat-backed stablecoin, this type is only backed by some kind of a commodity like gold, silver, oil, etc., Major examples of this type are, PAXG Paxos and XAUt of Tether.</p>
</li>
</ol>
<h3 id="heading-decentralized-exchanges-dexs-in-defi">Decentralized Exchanges (DEXs) in DeFi</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660575649885/790AO5w7y.jpg" alt="Decentralized_exchange.jpg" class="image--center mx-auto" />
Another major component of DeFi right now is Decentralized Exchanges (DEXs) which are being used to exchange tokens and currencies on-chain without the need for an off-chain order book to record transactions</p>
<h4 id="heading-what-is-a-decentralized-exchange-dex">What is a decentralized exchange (DEX)?</h4>
<p>Well, with the introduction of the fungible tokens standard (The ERC20 standard on the Ethereum network) a flood of projects started to use the concept to build their own token on top of the Ethereum network instead of building their own network, which is a good thing. But, after some time, a torrent of new tokens is being released every single day. And for these token users' to buy them, the token project itself should apply for listing in a centralized exchange platform, which will get paid a huge amount of money to agree to list the token, and it hugely depends on how large and how much liquidity are there in that exchange. So, a brilliant idea came out, why don't we just let the token owners decide on their prices and provide their own liquidity in a trustless and decentralized way? And that's when the idea and concept of a decentralized exchange came out.</p>
<h4 id="heading-how-a-decentralized-exchange-dex-works">How a decentralized exchange (DEX) works</h4>
<p>There are two main types of DEXs - Automated Market Makers (AMM) and Decentralized Order Books </p>
<ol>
<li><p><strong>AMM</strong>: This is the most used type of DEXs and it comprises over one type, or we can say mechanism of execution. What an AMM is doing is basically adjusting the price of a token or an asset according to the supply and demand for it automatically in a trustless and decentralized way based purely on mathematical equations. The main models of those mathematical equations and hence models of AMMs are - Constant Product Market Maker (CPMM), Constant Sum Market Maker (CSMM), and Constant Mean Market Maker (CMMM). Examples of an AMM DEX are, Uniswap and SushiSwap among many others.</p>
</li>
<li><p><strong>Decentralized Order Books</strong>: Order books are most used in traditional finance daily, it's the most common way of providing liquidity in markets. An order book is basically a matching engine, that matches buy orders with their respective sell orders from different buyers and sellers. The major drawback here is its dependency on a central party for matching buying and selling orders, but with blockchain, we can do it in a more decentralized way. Major examples of decentralized order books are, 0x, dYdX, Loopring DEX, and Serum.</p>
</li>
</ol>
<h3 id="heading-lending-and-borrowing-in-defi">Lending and Borrowing in DeFi</h3>
<p>Like a normal financial system, there should be a way to maximize the use of idle monetary value by depositing it into interest-bearing accounts. Lending and borrowing in DeFi is no different. </p>
<h4 id="heading-what-is-decentralized-lending-and-borrowing">What is decentralized lending and borrowing?</h4>
<p>A lot of platforms arise to use the idle cryptocurrencies and tokens held by blockchain and DeFi users, bearing them interest over time when locking their currencies and tokens with the platform (staking)</p>
<h4 id="heading-how-lending-and-borrowing-in-defi-works">How lending and borrowing in DeFi works</h4>
<p>Users who want to lend to other users make a deposit of the cryptocurrency they want to lend in a DeFi lending protocol managed by a smart contract in a special vault for this specific cryptocurrency, in exchange, the lender gets a virtual token representing their ownership of the lent amount plus the interest earned accrued over time, and it can be redeemed at any point in time (the principal + the interest, and the protocol will destroy that virtual token after that). Users who want to borrow go to the platform and deposit another token or cryptocurrency in exchange for a specific token or currency for a specific amount of time, the borrower usually over-deposits the initial cryptocurrency to be able to get the loan (which we discussed earlier and know as over-collateralization). Examples of these lending and borrowing platforms are, Aave and Compound Finance.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>We just touched upon the major building blocks of DeFi, it has way more than that, but we should always start with the basics. </p>
]]></content:encoded></item><item><title><![CDATA[What is the Ethereum Virtual Machine (EVM)?]]></title><description><![CDATA[Disclaimer:
This is an attempt to research the topic and try to understand it in more detail to find gaps in my understanding of it, I'm not an expert on the topic. I will attach sources throughout the article, so you too can make your own research. ...]]></description><link>https://blog.beshoy.io/what-is-the-ethereum-virtual-machine-evm</link><guid isPermaLink="true">https://blog.beshoy.io/what-is-the-ethereum-virtual-machine-evm</guid><category><![CDATA[Blockchain]]></category><category><![CDATA[Ethereum]]></category><category><![CDATA[Solidity]]></category><category><![CDATA[Web3]]></category><category><![CDATA[Smart Contracts]]></category><dc:creator><![CDATA[Beshoy Shehata]]></dc:creator><pubDate>Sat, 26 Feb 2022 01:14:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/uNXmhzcQjxg/upload/v1645656262310/3NrF4GYba.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>Disclaimer:
This is an attempt to research the topic and try to understand it in more detail to find gaps in my understanding of it, I'm not an expert on the topic. I will attach sources throughout the article, so you too can make your own research. So, any feedback is good feedback.</p>
</blockquote>
<h2 id="heading-intro">Intro</h2>
<p>I've been involved in the Ethereum development space for about 6 or 7 months now, in which I've completed the Blockchain Developer Bootcamp by ConsenSys Academy (thanks to <a target="_blank" href="https://www.arabsinblockchain.com/">Arabs in Blockchain</a>), joined <a target="_blank" href="https://www.developerdao.com/">DeveloperDAO</a> (DEV#5800) and other great communities, deployed a couple of smart contracts and dApps, and learning Javascript along the way. But, it's more than that for me, I need more; I need to deep dive; I want to know the internals of how things really work. So, writing about it may be the way to fulfill this need. So, I decided I'll be writing about development on the Ethereum network using Solidity and will be starting off by talking about the Ethereum Virtual Machine (EVM) today.</p>
<h2 id="heading-definition">Definition</h2>
<p>Let us first start with a definition of what is the EVM. This is how <a target="_blank" href="https://en.wikipedia.org/wiki/Ethereum#Virtual_machine">Wikipedia</a> defines the Ethereum Virtual Machine:</p>
<blockquote>
<p>The Ethereum Virtual Machine (EVM) is the runtime environment for transaction execution in Ethereum. It consists of a stack, memory, gas balance, program counter, and the persistent storage for all accounts (including contract code). When a transaction calls a contract's function, the arguments in the call are added to the stack and the EVM translates the contract's bytecode into stack operations. Stack items may be stored in memory or storage, and data from memory/storage may be added to the stack. The EVM is isolated from the other files and processes on the node's computer to ensure that for a given pre-transaction state and transaction, every node produces the same post-transaction state, thereby enabling network consensus.</p>
</blockquote>
<p>Ok, that's it. Thank you Wikipedia, the article is now finished. Hold on, what the heck does that even mean? <br />
Okay, there must be another clear definition for us. Let me check the official <a target="_blank" href="https://ethereum.org/en/developers/docs/ethereum-stack/#ethereum-virtual-machine">Ethereum</a> website docs: </p>
<blockquote>
<p>The Ethereum Virtual Machine (EVM) is the runtime environment for smart contracts in Ethereum. All smart contracts and state changes on the Ethereum blockchain are executed by transactions. The EVM handles all of the transaction processing on the Ethereum network.</p>
</blockquote>
<p>Really? <br /> OK <br />
So far we knew the EVM is: </p>
<ul>
<li>A runtime environment for Smart Contracts.</li>
<li>A state machine.</li>
<li>Consisted of stack, memory, storage, and gas balancer.</li>
<li>Virtual and isolated machine.</li>
<li>Turing-complete machine.</li>
<li>Capable of executing/handling transactions instantiated by Externally Owned Accounts (EOA) or other Smart Contracts.</li>
</ul>
<h2 id="heading-evm-break-down">EVM Break-down</h2>
<p>Well, let's break down each of those points separately</p>
<h3 id="heading-evm-is-a-runtime-environment">EVM is a runtime environment</h3>
<h4 id="heading-what-is-a-runtime-environment">What is a runtime environment</h4>
<p>In short, think of the runtime as a middle-man between an operating system/hardware and the software/applications that run and use the capabilities of those two components. It is part of the execution layer of any operating system, in our case, the operating system here is the Ethereum Virtual Machine and the software are our little apps called Smart Contracts.</p>
<h4 id="heading-how-evm-is-a-runtime-environment">How EVM is a runtime environment</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645834441650/geEf9f7az.png" alt="Execution-process-of-ethereum-virtual-machine.png" /> Credits: <a target="_blank" href="https://www.researchgate.net/figure/Execution-process-of-ethereum-virtual-machine_fig4_350498403">ResearchGate</a></p>
<p>Well, Ethereum is trying to be the computer of the internet, and the main component of any computer is its operating system which is the EVM in our case. Operating systems need to have software so they can communicate with their hardware components and use the capabilities offered by the operating system. EVM runs on every full node on the Ethereum network, so if we considered Ethereum to be the computer of the internet, that computer processing power is distributed between every node on the network, which makes it more interesting and secure. <br /><br />
Solidity, among other programming languages (like Vyper, and LLL for example) are used to program our little smart apps (Smart Contracts) to be run on top of the Ethereum network, but our computer operating system only understands <a target="_blank" href="https://en.wikipedia.org/wiki/Bytecode">Bytecode</a>. Bytecode is not directly understandable by computer hardware, but it's easily understandable by a virtual machine. So, here comes the runtime environment aspect, the EVM translates/compiles the code written in Solidity and other programming languages to bytecode and the virtual machine translates it to the corresponding machine code that can be run on every Ethereum node. <br /><br />
So, to recap what the EVM is really doing here in short simple words. We write smart contract code in Solidity, for example, that code is then translated to bytecode when compiled so the EVM can understand the logic behind the written code and then executes it on the Ethereum network accordingly after compiling it to machine code by the virtual machine compiler first.</p>
<p>Here is another great illustration of how the runtime aspect of the EVM work from <a target="_blank" href="https://twitter.com/XamHans/status/1497602578657521672">XamHans</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645893567393/pYBWN9Y5A.jfif" alt="FMiNm1bWQAwER1o.jfif" /></p>
<hr />
<h3 id="heading-evm-is-a-state-machine">EVM is a state machine</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645712080431/quZWZzWbx.png" alt="Turnstile_state_machine.png" /> Image credits: <a target="_blank" href="https://en.wikipedia.org/wiki/Finite-state_machine">Wikipedia</a><br /></p>
<p>In computer science, a system is described as <a target="_blank" href="https://en.wikipedia.org/wiki/Program_state">stateful</a> if it is designed to remember preceding events or user interactions. The Ethereum network is designed in a way that allows the whole network to have only one state at any given block, and only one state. For example, a variable in a smart contract when stored in the storage (more on that later) can only have one value at any point in time. The EVM here is the one responsible for changing that state by allowing users (EOA) or other smart contracts to send transactions (or message calls in case of a smart contract) that contain data with the new state. Like a turnstile, it only has one state at any given point in time, and you need to insert a coin inside of it to change that state.</p>
<hr />
<h3 id="heading-evm-consists-of-stack-memory-storage-and-gas-balancer">EVM consists of stack, memory, storage, and gas balancer</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645569825685/W6HwoqvyN.png" alt="evm.png" /> Image credits: Official Ethereum <a target="_blank" href="https://ethereum.org/en/developers/docs/evm/">website</a>. <br /><br /></p>
<p>Mainly, three of them are used for storing data (stack, memory, storage), and the gas balancer have other uses. So, let's break down each one of them separately.</p>
<h4 id="heading-stack">Stack</h4>
<p>What is a <a target="_blank" href="https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29">stack</a> in computer science? It is an abstract data type that serves as a collection of elements, with two main principal operations: <br />
01) Push=&gt; which adds an element to the collection <br />
02) Pop=&gt; which removes the most recently added element that was not yet removed <br /> 
Okay, but how's that related to the EVM? Well, EVM is designed as a stack machine as a design choice, we can visualize a stack as a storage type that has a medium-term memory span, or more precisely, it can only store a certain type of data, which is our smart contract local variables in our case. But there is a catch here, the stack storage is limited to a certain amount of values (1024 values). Stack storage is so cheap, compared to storage type.</p>
<h4 id="heading-memory">Memory</h4>
<p>The memory type is a kind of storage that only lives during the lifespan of a function call, and the data will be discarded and deleted from the blockchain afterward. Because of the nature of this type, it's also so cheap and usually used for on-the-fly computations that don't need to be persistent on the network.</p>
<h4 id="heading-storage">Storage</h4>
<p>Storage may be referred to also as Account, at the end every Ethereum address is an account that holds a balance of Ether, and this balance must be saved inside of persistent storage so it only gets updated when a transaction occurs. Smart contracts need to use storage so they can have persistent data, for example, a smart contract needs to persistently store account balances for each user of any ERC20 token like DAI or Tether. Storage costs are very high, but they can have/take relatively large space on the Ethereum network compared to other storage types.</p>
<h4 id="heading-gas-balancer">Gas Balancer</h4>
<p>Ok, what is gas on the Ethereum network? Okay, gas is simply gas, it's the fuel that powers all the transactions that occur on the Ethereum network. Ethereum is designed on top of a consensus mechanism called <a target="_blank" href="https://en.wikipedia.org/wiki/Proof_of_work">Proof of Work</a> (PoW) and one of its main features is incentivizing network participants with the network native currency, Ether in our case, so a user who is using the network for their own benefit should spend a little bit of their holdings of Ether as an incentive for the network participants so they provide their computing power to the network to continue functioning. This incentive is called GAS. Their is also another aspect of how gas works on Ethereum, the more the network is being used by many users, the more the gas fees a user should pay to incentivize a network participant to pick his/her request first (more on that and how gas fees are calculated on another day) and the gas balancer is the part responsible for adjusting those gas fees according to how busy is the whole network is.</p>
<hr />
<h3 id="heading-evm-is-virtual-and-isolated">EVM is virtual and isolated</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645835197845/bglu9ncmX.jpg" alt="ethereum-virtual-machine.jpg" /><br /><br /></p>
<p>A virtual machine is defined as an abstraction layer on top of any physical machine. How is that related to Ethereum, anyway? Well, no one would be happy if any malicious actor in the network figured out a way to run malicious code on every physical computer of each node in the Ethereum network, that would be devastating. So, the EVM here provides an abstraction layer on top of the physical hardware of the full nodes on the network who are contributing computing power and resources to the network, and this abstraction only allows actors and developers to use the full capacity of the network but with the limitations of only what the EVM offers, which is a lot. <br /><br />
Then comes the isolation part, which ensures nobody has access to the file system, the underlying network, and the processors of the full nodes except the virtual machine, and this ensures that all code and the logic behind it will run the same way (deterministic execution, meaning that we will get the same results whenever we provide the same inputs each time we run the program) on all nodes.</p>
<hr />
<h3 id="heading-evm-is-turing-complete">EVM is Turing-complete</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645835393005/hUDmrde45.jpg" alt="2718748079_preview_012_Xnor_4_4.jpg" /></p>
<p><a target="_blank" href="https://academy.binance.com/en/glossary/turing-complete">Turing</a> Complete refers to a machine that, given enough time and memory along with the necessary instructions, can solve any computational problem, no matter how complex. The EVM is designed to handle and solve any computational logic provided by smart contracts, but there is a catch here, we don't want our virtual machine to be running non-stop on each node in the network to solve infinite loops for example. That would make the whole network collapse, that's where the concept of gas which we talked about earlier comes to play. <br /><br />
Gas cost simply caps the amount of time and execution steps needed by any function call or smart contract interaction to be completed. This ensures that the state doesn't change until the function call is complete, and it's not complete if the capped gas limit is exceeded, this will result in the function being reverted to the initial state.</p>
<hr />
<h3 id="heading-evm-is-capable-of-executinghandling-transactions">EVM is capable of executing/handling transactions</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645829773401/0l_Ke3Edu.png" alt="tx.png" /></p>
<p><a target="_blank" href="https://ethereum.org/en/developers/docs/transactions/">Transactions</a> on Ethereum are one of two types, first is the one initiated by EOA to another EOA or to a smart contact by cryptographically signing a request on the network that would change the state of the EVM. The second type is a message call initiated by a smart contract to another smart contract. Ok, why transactions are that important? Because the nature of the Ethereum network is designed as a state machine (as we discussed earlier) and what a transaction really does is that it broadcasts the request of the initiator to every node on the network so they pick up the data contained inside of the request and do any processing required to change the state of anything on the network. Transactions should be picked-up by miners (network participants) to be valid, and a miner will be choosing a transaction that has more gas fees than others, so they could have more profit maximization (which we were talking about earlier).</p>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<p>Okay, I guess I should add my final thoughts here on this spot, well, there is so much I learned about from writing about EVM. Mainly, the EVM is the main killer feature of the Ethereum network, being Turing-complete and capable of computing complex logic may actually lead it to be the computer of the internet for real. Also, understanding what is gas and how it works under the hood, is very crucial for writing a cost-efficient smart contract both for the deployer and for the end-user. There is so much more to understanding the underlying workings of the EVM, you can find on the <a target="_blank" href="https://ethereum.github.io/yellowpaper/paper.pdf">Yellow Paper</a>, we just had a general understanding of what is going on. For the next series of articles I'll start deep diving into Solidity programming language to learn it more in-depth; stay tuned. 
<br /><br />
If there is an error or something that needs more clarification, or I just still have an understanding gap about it, or to just connect with each other, please reach out to me here on comments or on Twitter <a target="_blank" href="https://twitter.com/0xBeshoy">@0xBeshoy</a><br />
Peace ✌.</p>
]]></content:encoded></item></channel></rss>