This is an old revision of the document!
There are all kinds of errors that can occur in Systems and Applications. Some errors are more or less static in nature and must be addressed before the software can be released. Others can occur during the running of the System or Application. Some of these errors are the result of aborent use of resources such as Out of Memory or Dividion by Zero while others are the result the code not doing what it is intended auch as Invalid Data.
A Syntax Errors are errors in program or script Source Code not meeting (following), or deviating from the standardized Syntax associated with the Programming Language.
Syntax Errors are generally small grammatical mistakes in the Source Code and can seem as trivial as a single character (i.e., a missing semicolon, or quotations, parenthesis, braces, or brackets not balanced). In the C++ code below, there is a Syntax Error on each line. The errors are indicated by comments on the line:
#include <iostream>
using namespace std;
void main()
{ int x = 10 // semicolon missed
int y = 15.4; // Asigning an int with a floating point number
char delimeter = ","; // Using a quotation mark instead of an apostrophy for a character
string myText = 'hello World'; // Using apostrophe instead of a quotation Mark
cout << " "<< meText; // referencing a variable that is not declared
} } // Too many closing braces
Some software Integrated Development Environments (IDEs) check Source Code for Syntax Errors in real-time, while others only generate syntax errors when a program is compiled. Even if a source code file contains one small syntax error, it will prevent an application from being successfully compiled and deployed. Similarly, if you run a script through an interpreter, any Syntax Errors will prevent the script from completing. In most cases, the compiler or interpreter provides the location (or line number) of the Syntax Error, making it easy for the programmer to find and fix the error.
As a general rule, Strongly Typed Languages create more Syntax Errors than Weakly Typed Languages with the idea that these Syntax Errors help prevent harder to diagnose Runtime Errors or Logic Errors.
Solidity Syntax errors are detected within Syntax Highlighting the remix or other Integrated Development Environments (IDEs) such as Microsoft: Visual Studio Code (VS Code) with the Solidity Plug In.
A very important aspect of Syntax Errors caught within the IDE is that these errors are NOT caught on the blockchain, but rather just inside the IDE. This means there is no expenditure of Gas to catch these errors.
Runtime Errors refer to a class of errors occurring during the execution of a program or an Application. Runtime errors imply Bugs in the running code developers expected but were unable to correct. For example, when the Application can not allocate more memory, an Out of Memory is triggered, terminating the Application and resulting in a Core Dump. The Core Dump and a Debugger are some of the most powerful and useful tools in tracking down Runtime Errors.
| Error Name | Description |
|---|---|
| Memory Leak | Memory leaks happen when a program drains your computer’s Dynamic Random Access Memory (DRAM). It often arises from unpatched software, such as when you fail to update the Operating System (OS) to the newest release. |
| Out of Memory | Out of Memory is an error when there is no longer any spare memory to allocate to programs, or the memory requested exceeds the amount of memory available. An Out of Memory error causes programs to terminate or even the entire computer to crash triggering a Core Dump. The Out of Memory occurs when
|
| Heap Error | A Heap Error is when code inadvertently overwrites control information memory management functions use to control heap usage. The application that you are debugging must have been built with the heap check capability. |
| Out of Stack Space | The Stack Memory is the working area of memory that grows and shrinks dynamically with the demands of your executing program. Whenever an Application, program, function, procedure or a declarative block is invoked, or a local Variable is created, memory is allocated from the Stack. Some common reasons for this error are:
|
| Division by Zero Error |
Division by Zero (DIV/0) can occur in any application where the quotient is a Variable value substituted at Run Time. It is an error typically associated with spreadsheets. When formula inputs in the spreadsheet are left blank, the total might display a |
| Encoding Error | Encoding errors happen when you’re rendering a file, say a video file, to convert it into a usable or accessible file format. This is due to the resource-intensive nature of the encoding process. Error messages linked to this type of error include “encoding overloaded” or “encoding failed.” |
| Input/Output Device Error | Input/Output (I/O) device errors occur when issues arise with the read/write function of a device. Common causes include device malfunction, outdated drivers, OS incompatibility, and faulty universal serial bus (USB) ports. As a result, users would get a prompt saying that the device wasn’t accessible, making it impossible to transfer or encode files into it. Usually, the memory drive or the computer only needs to be restarted to get rid of the issue. |
| Overflow Error | Overflow Error occurs when an attempt is made to place a value into memory an integer (whole number) that is too large for the integer data type in a given system. For exaample, putting a 32-Bit value into a 16-Bit data field). Also see: Wrap Around |
| Range Error | A Range Error occurs when a value is not in the set or range of allowed values. For example, a percent might only allow numbers between 0 and 100, and an attempt is made to store a -1 or 101 into the field. |
| Segmentation Fault | Segmentation Fault (SEGFAULT) is an error returned by Hardware (H/W) with memory protection that tells the Operating System (OS) that a memory access violation has occurred. |
| Undefined Object Error | An undefined object error happens when a program attempts to call a function for a PHP or JavaScript object (or a C++ variable) that isn’t defined or assigned a value. The error also occurs for deeply nested objects. In simpler terms, the code “cannot read” or find where a property is because it does not exist or is buried several levels deep within the code. |
| Underflow | An Underflow Error occurs when a mathematical operation results in a number which is smaller than what the device is capable of storing. For example, an negative number being put into an unsigned number space. Also see: Wrap Around. |
| User Defined Exception | User Defined Exception occurs is part of the architecture and design of an Application, routine, methd or object. |
There are always costs associated with Runtime Errors and many of these errors can be traced to poor specification of reqiurements, misuderstanding of what the requirements are, or ignorance of the requirements.
There are some important tools, processes and resources available to help prevent some Runtime Errors before the code is even executed.
Runtime errors occur only after the Smart Contract Code has been compiled to a byte code, deployed to the blockchain and executed on the EVM. These runtime errors occur when Ethereum “thinks” that there is something wrong with the Smart Contract. If the Runtime error occurs during a Transaction, any State Changes made during the Transaction are canceled and the Transaction is reverted. Depending on the kind of error, all or some of the gas in the Transaction is consumed, or a portion is returned. Runtime errors are harder to troubleshoot than Syntax errors because the Solidity Compiler can not help with the diagnostics.
Runtime Errors are more serious than Syntax Errors since the contract has already been deployed to the blockchain, and it is not possible to just update the code by redeploying it.
| Out of Gas | |
|---|---|
| Revert | |
| Invalid OpCode | |
| Invalid Jump | |
| Stack Overflow | |
| Stack Underflow |
Logic Errors occur when there is a fault in the logic expressed by the Software (SW) or when the (i.e., **''if''**-**''then''** statements) through the SW creates a situation which is wrong or incorrect. The chance of a Logic Error, increases with the number of Decision Points found with the SW code.
Logic Errors can originate anywhere in the System Lifecycle from its conception to its execution.
Sometimes Logic Errors are reported as a Bug, however, not all “Bugs” are discovered or reported. Logic errors resulting in a Crash are generally quite obvious and are generally reported. However, Bugs which do not result in a crash but can only be found with a detailed forensic analysis of the Datastores are some of the hardest to discover and even track down.
Sometimes a Logic Error is introduced when a developer misinterprets the requirements or inadvertently implements the boolean calculus used in the Control Flow operations. Some examples:
nulled before it is used<, ⇐, ==, ===, '!=', >, or >=). For example, specifying a numerical check for a percent and specifying p >= 0 && p < 100 instead of p >= 0 && p ⇐ 100==, ===). == converts the variable values to the same type before performing comparison. This is called Type Coercion. === does not do any type conversion (coercion) and returns true only if both values and types are identical for the two variables being compared.=, instead of the comparison operator, ==null“” to a null stringSometimes, a Logic Error is a Bug because it introduces a Weakness making the System or Application Vulnerable for malicious Exploitation. These kinds of “Bugs” could exist for a long time (i.e., years) before they are actually exploited.
Software (SW), Firmware, and Hardware (H/W) weakness types that have security ramifications are also potential Logic Errors. These Weaknesses can be flaws, faults, Bugs, or other errors in Software, Firmware, or Hardware and could have been introduced during any phase of the System Lifecycle from conceptualization, requirements specifications, architecture, code, or implementation.
Currently, there are 900+ Weaknesses defined by the Common Weakness Enumeration (CWE) most of which can be found through Static Code Analysis and Testing