Ethereum: Storage ops / gas spent
Unlock the secrets of Ethereum Storage Ops: Can we know the spent gas?
As loans of blockchain and cryptocurrency, we are always looking for ways to better understand the internal functioning of our favorite ecosystem. In recent months, we have explored various aspects of the storage of decentralized data from Ethereum, including the concept of gas spent by operation (Gasops). Today, we will immerse ourselves if it is possible to know the quantity of storage operations (or gases spent) carried out between four specific functions or a complete contract on the Ethereum network.
What are the gas ops?
Gas ops refer to all transactions that occur during the execution of intelligent contracts, including data operations such as storage operations. These transactions imply the displacement of ether (ETH) from one address to another in exchange for gas costs. When we talk about gas spent by operation, we want to understand how many ETHs are transferred and spent by these different transactions.
Can we know the spent gas?
Unfortunately, the answer is no. Unlike other aspects of Ethereum, such as the number of transactions or the block number, there is no direct means of knowing the quantity of gas spent per operation between four specific functions or a full contract. The reason lies in the complex interaction of the Ethereum transaction and storage mechanisms.
Here is what is happening behind the scenes:
- Transaction control
: When several transactions are executed together, they are not stored separately in memory. Instead, they are combined in a single batch of transactions called “lot”.
- Gas de lots : Lots transactions share a common gas pool, which is allocated to all transactions within the lot. This means that even if a transaction spends more gas than another, this does not necessarily mean that other transactions will always spend this amount.
- Storage and gas allocation operations : when a storage operation (for example, “Storage” or “storage display”) is executed, it attributes a certain number of gas units to store the chain data.
Can the foundry help?
Although we cannot directly measure the gas spent by OP between four functions or a full contract, the latest Foundry update provides some clues. Foundry offers a functionality called “gas accounting” which allows users to follow the total gas used for specific types of transactions and operations.
The foundry gas accounting mechanism is based on a combination of metadata (for example, transaction newspapers) and a tailor -made indexing system. This approach allows the foundry to estimate the quantity of gas spent by OP between four functions or a full contract by analyzing these measures.
To demonstrate this, consider a hypothetical example:
Suppose we wanted to analyze the use of gas for three storage operations (“storage”, “viewstorage” and “setstorage” executed on an Ethereum network. We can use the Foundry gas accounting function to follow the total gas used For each OP by analyzing the transaction newspapers.
Although this approach is not perfect, it shows that the foundry is capable of providing information on the gas spent by OP between four functions or a full contract.
Conclusion
In conclusion, although we cannot directly measure the gas spent by OP between four functions or a full contract on Ethereum, the latest update from Foundry provides some clues. By taking advantage of their gas accounting characteristic and by analyzing the metadata associated with transactions, the foundry is able to estimate the amount of gas used for specific types of operations.
While the Ethereum ecosystem continues to evolve, we can expect more tools and emerging features that help us better understand the internal functioning of our favorite blockchain. Whether it is gas accounting or something else, it will be exciting to see how the foundry and other developers continue to innovate in this area.