Milestone 4. Ensure execution errors are not lost
A major issue with the development of Solidity contracts is that, if there is an issue, the error is lost. This makes for a bad developer experience. Fixing this has two parts: extending the metadata with error information, and encoding the error in the return buffer if there is an error.
Some examples of this are:
Example A:
A solidity function contains the line:
require(balance > 0, “not enough balance”);
If for some reason balance is zero, then currently the text ‘not enough balance’ is not emitted
anywhere.
Example B: Math overflow checks are enabled.
uint8 x = 255;
x = x + 1;
Now currently there is no hint as to why this code fails.
The first step is amending the generated metadata for all functions and constructors to return a Result<> rather simply the return values for the solidity function. So the Result should have the Solidity function return values for the Ok<> value, and an enum for the Err<>. The error enum should like so:
enum SolidityError {
ArgumentEncodingIncorrect,
NonpayableReceivedValue,
FunctionNotFound,}
DividisionByZero,
ContractTerminated,
ContractNotFound,
AddArithmeticOverflow,
SubArithmeticUnderflow,
MulArithmeticOverflow,
PowArithetmicOverflow,
IndexOutOfBounds,
PopEmptyArray,
Revert(String)
}
The second part is to update the generated code for encoding the return data. This should include the error if it occurs. If the error is caused by a Solidity revert(“test”) then it should include the provided string.
Success is here that whenever an error occurs in Solidity code, the developer has easy access to what the error was, to help debug the issue.
This feature should have tests at
https://github.com/hyperledger-labs/solang/tree/main/integration/substrate
Success means that a pull request has had all its review comments addressed and it is merged.