Skip to content

Gas and Execution Issues

Back to Troubleshooting

Insufficient GAS at Runtime

error: execution failed: insufficient GAS

Cause: The transaction's system fee doesn't cover the execution cost.

Diagnosis:

  1. Check gas consumption with gasleft():

    solidity
    function expensiveOperation() external {
        uint256 gasBefore = gasleft();
        // ... operation ...
        uint256 gasUsed = gasBefore - gasleft();
        Runtime.log(string(abi.encodePacked("Gas used: ", gasUsed)));
    }
  2. Use the withGasLimit modifier from FrameworkBase:

    solidity
    function criticalOp() external withGasLimit(50000000) {
        // Reverts early if < 0.5 GAS remaining
    }

Common gas-heavy operations:

OperationApproximate Cost
System.Storage.Put (new key)200,000+ GAS units
System.Storage.Put (update)100,000+ GAS units
System.Contract.Call32,768 GAS units
CryptoLib.verifyWithECDsa1,000,000+ GAS units
Large array iterationScales with array size

WARNING

Neo GAS uses 10^8 decimals (not 10^18 like Ethereum). 1 GAS = 100,000,000 fractional units. Adjust your constants accordingly.


MIT Licensed