Ethereum Virtual Machine is a crucial component of the Ethereum network, enabling the execution of decentralized applications (DApps) and the deployment of smart contracts. Every PoS validator should download this part of ‘software’ on their device to fully run the node.
Now I will try to explain to you what is going on in this picture.
Persistent data 🔴
In the red box we have "persistent data", which is the data that is stored on the blockchain and stored in various transactions and blocks. This data is considered reliable and durable because it remains on the blockchain after transactions are confirmed, and can be accessed and modified through smart contracts and external applications.
opcode
- every time we write a smart contract and compile it (so that a computer can read it), the code is permanently stored and written to the blockchain.
State of smart contracts
. For successful and efficient operation, smart contracts must maintain data and keep records. So in this section we include things like "user balances", "digital asset ownership records" or any other relevant information. Roughly speaking it's like a ledger that you can look into and understand what's going on in the applications work.
storage
. Well, everything is probably clear here. Long-term variables are stored here.
Global Variables ⚫️
Global variables themselves are already built into EVM and Solidity accordingly. With their help we can find out the necessary information about the blockchain, transaction states, messages.
The current variables can be found here:
-> https://docs.soliditylang.org/en/v0.8.17/units-and-global-variables.html
Volatile data 🟠
Programme Counter
Every time the computer reads and executes our smart contract it needs to keep count. It says to itself - "How many lines of code have I read so far? How many more lines of code do I have left to read?". It is the counter that allows it to deal with these questions. It is thanks to the counter that we can calculate how much gas we need to pay for a particular function.
Remaining available gas
As you have already realised this metric is closely related to the programme counter. In the Ethereum blockchain there is a limit of gas per transaction, it is 21,000 gwei. In order to effectively calculate how much gas a function has used it needs this parameter. In case the gas runs out for a certain function, the transaction will be "reverted", i.e. an error. But if the function uses less gas than it should, then the remaining (unused) gas will be returned to the one who called the function. It is worth noting that the user pays the "estimated" amount of gas BEFORE executing a function.
Stack
A stack is a linear data structure. Think of it as a kind of container. This container follows the LIFO (Last-In-First-Out) principle, which means that when we add an item we add it to the very first (top) slot, and when we take an item out, we take it out of the very first (top) layer. For now this understanding is enough. The size of the stack is 1024 slots of 32 bytes each. Any variables we declare in functions are stored here.
Memory
Memory is a very interesting mechanism in the EVM. It allows us to handle a data such as arrays, structs, strings. Due to the fact that EVM processes data in chunks of 32 bytes, it would be problematic to store large arrays of data in a stack, so memory was created to solve this problem. The pros are that memory is cheaper, it can be changed, but it is worth considering that memory is short-term and exists only during the execution of the function. Memory can be imagined as a multi-storey house where each floor is an array of data. If we want to do this or that action, EVM decides on which floor this "action" should be written to.
EVM has definitely started the cryptocurrency revolution. Thanks to this technology, we can create applications, new financial instruments and blockchain-based technologies. Thanks to clear sets of rules, EVM can run non-stop without fear of a sudden shutdown, as each copy is stored on each user's computer.
I hope that most of what I've described above has been clear to you. Thanks!