Ethereum: “message”:”execution reverted: arithmetic underflow or overflow”
Ethereum 2.0: Understanding of the “returned execution: arithmetic undercurrent or overflow” error
While Ethereum develops and improves, new problems are determined that can affect the stability and safety of the network. Such a problem is an error that has certain smart contract interactions with the Virtual Machine (EVM) from Ethereum. In this article, we will deal with the details of the error of the “execution: arithmetic undercurrency or overflow” and explain what it means for your intelligent contracts.
What is the “execution back: arithmetic undercoance or overflow”?
The “execution represents: arithmetic undercurrency or overflow” occurs when an intelligent contract tries to carry out arithmetic operation that causes an underfloor. This error is normally caused by incorrect handling of sliding-made numbers or other types of data.
How does the error affect intelligent contracts?
The mistake, which is referred to as the “integer division” or “floating point underlay”, occurs when an intelligent contract is trying to share two integers with an integer arithmetics. For example:
`
Uint256 Value = 123/456; // integer -division error
Uint256 result = value; // wrong result
`
In this scenario, the / operator carries out a integer department, which leads to “result = 0”. However, if the dividend is too small (e.g. “value is less than 456”) or too large (e.g. “value is greater than” 2^256-1 “), the result is a shelter.
Causes of the error
The exact cause of this error can vary depending on the specific smart contract and its implementation. However, the frequent causes include:
- Wrongly bypassing the point numbers or other data types
- Use
uint256for signed integers
- Do not validate the proper review of user inputs or errors
** What does this mean for your intelligent contracts?
The “execution is left back: arithmetic undercoance or overflow” can have significant consequences for your intelligent contracts, especially for those with high value transactions. Include some potential problems:
- Wrong handling of large numbers, which leads to incorrect results and potential returns
- The non -proper validation of user inputs, which leads to errors and potential returns
- Rounding errors or other precision problems that can lead to unexpected behavior
Mastive the risk
In order to alleviate this risk, it is important:
- Use the right data types : Make sure that intelligent contracts use the right data type for the expected entries and outputs.
- Validate user input : Valide the user input thoroughly to prevent errors and returns.
- Extensive : carry out carrying tests to identify and remedy potential problems before you provide your intelligent contract.
By understanding the “execution used back: arithmetic undercurrency or overflow” you can take steps to alleviate the effects on your intelligent contracts and ensure the stability and the secret of your applications based on Ethereum.
Example fix
To prevent this error in a simple example:
`Solidity
Pragma solidity ^0.8.0;
Contract Simpletoken {
Uint256 public value;
Constructor (address [] Speicher -setupaddys, Uint256 _TottaltoKensforsal, Uint256 _SoftCap) {
// initialize the token with a fixed value
Value = 10000000000; // 1 million units of tokens
}
Functional transmission (address receiver, Uint256 amount) public {
If (amount> value) revert (“insufficient balance”);
Value -= amount;
}
}
`
In this test we made a simple solution by using the data type “Uint256” for the value of the tokens and the validation of the user input to prevent errors.