Understanding the limit of intelligent contract memory Ethereum
When compiling an intelligent blockchain agreement, Ethereum is one of the key aspects of memory. In particular, the maximum amount of memory available for an intelligent contract can be a significant challenge in certain scenarios.
In this article, we are immersed in details of how Ethereum Virtual Machine (EVM) limits the size of the variables and storage function that can be used in an intelligent contract.
Memory limits EVM
EVM has several memory -related restrictions:
1.
- storage functions : in EVM -in there are two types of storage features:
Bake and 'string'. The "Byte" function can store up to 1,073 741,824 bytes (1024^3). On the other hand, the function
stringhas a maximum length of 2^256 - 1 byte.
Use of mapping variables
In your example, the code fragmentation:
Strength
mapping (nint256 => string) public random;
`
Use mapping variables to store chains. The problem is that each variable in the field "randomly" can only hold 20 bytes of memory, which is determined by limiting the size of the EVM variable.
Adding chains with variable length
Suppose you want to add a chain with a length of 1024 bytes to a mapping:
Strength
mapping (nint256 => string) public random;
for (nint256 i = 0; i <10000000; i ++) {) {
Rise [i] = “…. iewjif …; // 1024 each …
Iche
`
In this scenario you can add a large number of chains with a variable length of up to 20 bytes. However, when the entire use of memory exceeds the limit of EVM, things will become problematic.
The consequences of exceeding memory limit
When you try to save the chain with more than 20 bytes in the "random" mapping, you will find a mistake:
ERROR: Storage size exceeded (Max: 1 073 741.824, min: 0)
The reason is that EVM cannot assign enough memory for a variable of 1024 bytes.
Conclusion
Although it is possible to store large chains in Ethereum intelligent contracts using variables and function of "byte", there are limits of how much memory can assign. To avoid mistakes like above, you need to ensure that your code is designed with respect to EVM memory limitations. That could include:
- Division of large chains into smaller pieces
- Usestring ‘instead of’ bytes’
- Application of storage in cache or other optimization techniques
In short, it is necessary to understand EVM memory limitations, and when preparing smart contracts Smart Ethereum, plan to carefully store the data.
Multiple sources
For more information on EVM memory limitations, see the following sources:
- Documentation Ethereum Virtual Machine (EVM): <
- Solita 0.5.12 Documentation: <
- Evm Evm: <