Ethereum: Low-level call execution returned

Ethereum: Low-level call cancellation error

The Ethereum blockchain is a programmable blockchain in which smart contracts can be deployed and executed. However, when executing low-level calls to external functions, such errors as execution cancellation errors may occur.

In this article, we will look at the cause of the execution cancellation error in Ethereum and provide steps to eliminate it.

What causes the abort error?

An execution cancellation error occurs when a smart contract attempts to execute a function call that results in an invalid state or value. This can happen for several reasons:

  • Invalid function signature: The called function is invalid or does not match the expected signature.
  • No required arguments: one or more required arguments are missing from the function call, which causes a failure.
  • Unintended gas cost: Exceeding the allowable gas limit for a function call results in an error canceled by execution.

Example Gas Oracle API Call

In Ethereum, the GasOracle API is used to obtain an estimated gas price for a transaction. This API can be called from another procedure or smart contract using the following syntax:

`solidity

function estimateGas() public returns (uint256) {

// GasOracle API call and result analysis

uint256 estimateGas = 0; // Initialize the variable

GasOracle gasOracle = new GasOracle(address);

gasOracle.estimateGas(); // GasOracle API call

estimateGas = gasOracle.getEstimatedGas(); // Analysis of the result

return estimateGas;

}

In this example, theestimatedGasfunction calls theGasOracleAPI to get the estimated gas value and returns it.


Example of undo execution error





Ethereum: Low-level call execution reverted

Consider an example where we have a simple smart contract that tries to call a function:

solidity

contract Example {

function foo() public {

// Call bar()

callBar();

}

function bar() public pure {

// Modeling of some calculations

uint256 result = 0;

for (uint256 i = 0; i < 100000; i++) {

result += i;

}

return result;

}

}

Suppose we have a GasOracleAPI call in the second procedure, thefoo()function tries to call thebar()function:

solidity

pragma solidity ^0.8.0;

contract Example {

// Call the Gas Oracle API

uint256 public gasCost;

function estimateGas() public returns (uint256) {

gasCost = 0; // Initialize the variable

GasOracle gasOracle = new GasOracle(address);

gasOracle.estimateGas(); // GasOracle API call

gasCost = gasOracle.getEstimatedGas(); // Analysis of the result

return gasCost;

}

}

When trying to callbar(), an execution cancellation error occurs because the function signature is invalid (a required argument is missing). The Ethereum blockchain does not allow calling a function that is not declared "pure" or does not have the correct signatures.


Solution

To solve this problem, we need to make sure that the functions of our smart contract are clearly defined and correspond to the expected function signature. In this case, we can simply change thebar()function to pure:

solidity

contract Example {

function foo() public {

// Call bar()

callBar();

}

function bar() pure public returns (uint256) {

// Modeling of some calculations

uint256 result = 0;

for (uint256 i = 0; i < 100000; i++) {

result += i;

}

return result;

}

}

With this change, we can safely call foo()without encountering a cancellation error. In addition, we need to make sure that theGasOracle` API calls are executed correctly and do not exceed the permissible gas limit.

Comments

mood_bad
  • No comments yet.
  • Add a comment