Ewasm Contract Interface (ECI)
The Ewasm Contract Interface (ECI) specifies the structure of a contract module.
Every contract must be stored in the WebAssembly Binary Encoding format (in short, WASM bytecode).
A contract can only import symbols specified in the Ethereum Environment Interface or EEI.
In practice, this means that all imports specified by an ewasm module must be from the
and having a function signature and name directly correspondent to a function specified in the EEI.
As mentioned below, there is a
debug namespace as well, but that is disallowed in production systems.
Debug-mode is a special VM option, where an additional set of debugging interfaces are available to contracts. On a live VM, any bytecode trying to import these symbols should be rejected.
The imports are available under the
print32(value: i32) - print value
print64(value: i64) - print value
printMem(offset: i32, len: i32) - print memory segment as printable characters
printMemHex(offset: i32, len: i32) - print memory segment as hex
printStorage(pathOffset: i32) - print storage value as printable characters
printStorageHex(pathOffset: i32) - print storage value as hex
A contract must have exactly two exported symbols:
memory: the shared memory space available for the EEI to write into.
main: a function with no parameters and no result value.
The method exported as
main will be executed by the VM.
On successful execution, the code should return via a normal code path.
If it needs to abort due to a failure, an unreachable instruction should be executed.
The use of a start function is disallowed.
Note: This decision was made on WebAssembly version 0xb (pre version 1) and should be revisited.
If execution of wasm code triggers the wasm trap, the contract execution is
terminated with failure and all remaining gas is consumed (OOG-like exception).
This includes execution of