The Ethereum Environment Interface exposes the core Ethereum API to the ewasm environment. The Ethereum module will be implemented in the Ethereum client's native language. All parameters and returns are restricted to 32 or 64 bit integers. Floats are disallowed.
We define the following Ethereum data types:
bytes: an array of bytes with unrestricted lengthbytes32: an array of 32 bytesaddress: an array of 20 bytesu128: a 128 bit number, represented as a 16 bytes long little endian unsigned integer in memoryu256: a 256 bit number, represented as a 32 bytes long little endian unsigned integer in memory
We also define the following WebAssembly data types:
i32: same asi32in WebAssemblyi32ptr: same asi32in WebAssembly, but treated as a pointer to a WebAssembly memory offseti64: same asi64in WebAssembly
Subtracts an amount to the gas counter
Parameters
amounti64 the amount to subtract to the gas counter
Returns
nothing
Gets address of currently executing account and stores it in memory at the given offset.
Parameters
resultOffseti32ptr the memory offset at which the address is to be stored (address)
Returns
nothing
Trap conditions
- store to memory at
resultOffsetresults in out of bounds access.
Gets balance of the given account and loads it into memory at the given offset.
Parameters
addressOffseti32ptr the memory offset to load the address from (address)resultOffseti32ptr the memory offset to load the balance into (u128)
Returns
nothing
Trap conditions
- load from memory at
addressOffsetresults in out of bounds access, - store to memory at
resultOffsetresults in out of bounds access.
Gets the hash of one of the 256 most recent complete blocks.
Parameters
numberi64 which block to loadresultOffseti32ptr the memory offset to load the hash into (bytes32)
Returns
result i32 Returns 0 on success and 1 on failure
Note: in case of failure, the output memory pointed by resultOffset is unchanged.
Trap conditions
- store to memory at
resultOffsetresults in out of bounds access (also checked on failure).
Sends a message with arbitrary data to a given address path
Parameters
gasi64 the gas limitaddressOffseti32ptr the memory offset to load the address from (address)valueOffseti32ptr the memory offset to load the value from (u128)dataOffseti32ptr the memory offset to load data from (bytes)dataLengthi32 the length of data
Returns
result i32 Returns 0 on success, 1 on failure and 2 on revert
Trap conditions
- load
addressfrom memory ataddressOffsetresults in out of bounds access, - load
u128from memory atvalueOffsetresults in out of bounds access, - load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access.
Copies the input data in current environment to memory. This pertains to the input data passed with the message call instruction or transaction.
Parameters
resultOffseti32ptr the memory offset to load data into (bytes)dataOffseti32 the offset in the input datalengthi32 the length of data to copy
Returns
nothing
Trap conditions
- load
lengthnumber of bytes from input data buffer atdataOffsetresults in out of bounds access, - store
lengthnumber of bytes to memory atresultOffsetresults in out of bounds access.
Get size of input data in current environment. This pertains to the input data passed with the message call instruction or transaction.
Parameters
none
Returns
callDataSize i32
Message-call into this account with an alternative account's code.
Parameters
gasi64 the gas limitaddressOffseti32ptr the memory offset to load the address from (address)valueOffseti32ptr the memory offset to load the value from (u128)dataOffseti32ptr the memory offset to load data from (bytes)dataLengthi32 the length of data
Returns
result i32 Returns 0 on success, 1 on failure and 2 on revert
Trap conditions
- load
addressfrom memory ataddressOffsetresults in out of bounds access, - load
u128from memory atvalueOffsetresults in out of bounds access, - load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access.
Message-call into this account with an alternative account’s code, but persisting the current values for sender and value.
Parameters
gasi64 the gas limitaddressOffseti32ptr the memory offset to load the address from (address)dataOffseti32ptr the memory offset to load data from (bytes)dataLengthi32 the length of data
Returns
result i32 Returns 0 on success, 1 on failure and 2 on revert
Trap conditions
- load
addressfrom memory ataddressOffsetresults in out of bounds access, - load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access.
Sends a message with arbitrary data to a given address path, but disallow state
modifications. This includes log, create, selfdestruct and call with a non-zero
value.
Parameters
gasi64 the gas limitaddressOffseti32ptr the memory offset to load the address from (address)dataOffseti32ptr the memory offset to load data from (bytes)dataLengthi32 the length of data
Returns
result i32 Returns 0 on success, 1 on failure and 2 on revert
Trap conditions
- load
addressfrom memory ataddressOffsetresults in out of bounds access, - load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access.
Store 256-bit a value in memory to persistent storage
Parameters
pathOffseti32ptr the memory offset to load the path from (bytes32)valueOffseti32ptr the memory offset to load the value from (bytes32)
Returns
nothing
Trap conditions
- load
bytes32from memory atpathOffsetresults in out of bounds access, - load
bytes32from memory atvalueOffsetresults in out of bounds access.
Loads a 256-bit a value to memory from persistent storage
Parameters
pathOffseti32ptr the memory offset to load the path from (bytes32)resultOffseti32ptr the memory offset to store the result at (bytes32)
Returns
nothing
Trap conditions
- load
bytes32from memory atpathOffsetresults in out of bounds access, - store
bytes32to memory atresultOffsetresults in out of bounds access.
Gets caller address and loads it into memory at the given offset. This is the address of the account that is directly responsible for this execution.
Parameters
resultOffseti32ptr the memory offset to load the address into (address)
Returns
nothing
Trap conditions
- store
addressto memory atresultOffsetresults in out of bounds access.
Gets the deposited value by the instruction/transaction responsible for this execution and loads it into memory at the given location.
Parameters
resultOffseti32ptr the memory offset to load the value into (u128)
Returns
nothing
Trap conditions
- store
u128to memory atresultOffsetresults in out of bounds access.
Copies the code running in current environment to memory.
Parameters
resultOffseti32ptr the memory offset to load the result into (bytes)codeOffseti32 the offset within the codelengthi32 the length of code to copy
Returns
nothing
Trap conditions
- load
lengthnumber of bytes from the current code buffer atcodeOffsetresults in out of bounds access, - store
lengthnumber of bytes to memory atresultOffsetresults in out of bounds access.
Gets the size of code running in current environment.
Parameters
none
Returns
codeSize i32
Gets the block’s beneficiary address and loads into memory.
Parameters
resultOffseti32ptr the memory offset to load the coinbase address into (address)
Returns
nothing
Trap conditions
- store
addressto memory atresultOffsetresults in out of bounds access.
Creates a new contract with a given value.
Parameters
valueOffseti32ptr the memory offset to load the value from (u128)dataOffseti32ptr the memory offset to load the code for the new contract from (bytes)dataLengthi32 the data lengthresultOffseti32ptr the memory offset to write the new contract address to (address)
Note: create will clear the return buffer in case of success or may fill it with data coming from revert.
Returns
result i32 Returns 0 on success, 1 on failure and 2 on revert
Trap conditions
- load
u128from memory atvalueOffsetresults in out of bounds access, - load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access. - store
addressto memory atresultOffsetresults in out of bounds access.
Get the block’s difficulty.
Parameters
resultOffseti32ptr the memory offset to load the difficulty into (u256)
Returns
nothing
Trap conditions
- store
u256to memory atresultOffsetresults in out of bounds access.
Copies the code of an account to memory.
Parameters
addressOffseti32ptr the memory offset to load the address from (address)resultOffseti32ptr the memory offset to load the result into (bytes)codeOffseti32 the offset within the codelengthi32 the length of code to copy
Returns
nothing
Trap conditions
- load
addressfrom memory ataddressOffsetresults in out of bounds access, - load
lengthnumber of bytes from the account code buffer atcodeOffsetresults in out of bounds access, - store
lengthnumber of bytes to memory atresultOffsetresults in out of bounds access.
Get size of an account’s code.
Parameters
addressOffseti32ptr the memory offset to load the address from (address)
Returns
extCodeSize i32
Trap conditions
- load
addressfrom memory ataddressOffsetresults in out of bounds access.
Returns the current gasCounter
Parameters
none
Returns
gasLeft i64
Get the block’s gas limit.
Parameters
none
Returns
blockGasLimit i64
Gets price of gas in current environment.
Parameters
resultOffseti32ptr the memory offset to write the value to (u128)
Returns
nothing
Trap conditions
- store
u128to memory atresultOffsetresults in out of bounds access.
Creates a new log in the current environment
Parameters
dataOffseti32ptr the memory offset to load data from (bytes)dataLengthi32 the data lengthnumberOfTopicsi32 the number of topics following (0 to 4)topic1i32ptr the memory offset to load topic1 from (bytes32)topic2i32ptr the memory offset to load topic2 from (bytes32)topic3i32ptr the memory offset to load topic3 from (bytes32)topic4i32ptr the memory offset to load topic4 from (bytes32)
Returns
nothing
Trap conditions
- load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access, numberOfTopicsis greater than 4,- load
bytes32from memory attopic1results in out of bounds access, - load
bytes32from memory attopic2results in out of bounds access, - load
bytes32from memory attopic3results in out of bounds access, - load
bytes32from memory attopic4results in out of bounds access.
Get the block’s number.
Parameters
none
Returns
blockNumber i64
Gets the execution's origination address and loads it into memory at the given offset. This is the sender of original transaction; it is never an account with non-empty associated code.
Parameters
resultOffseti32ptr the memory offset to load the origin address from (address)
Returns
nothing
Trap conditions
- store
addressto memory atresultOffsetresults in out of bounds access.
Set the returning output data for the execution. This will halt the execution immediately.
Parameters
dataOffseti32ptr the memory offset of the output data (bytes)dataLengthi32 the length of the output data
Returns
doesn't return
Trap conditions
- load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access.
Set the returning output data for the execution. This will halt the execution immediately and set the execution result to "reverted".
Parameters
dataOffseti32ptr the memory offset of the output data (bytes)dataLengthi32 the length of the output data
Returns
doesn't return
Trap conditions
- load
dataLengthnumber of bytes from memory atdataOffsetresults in out of bounds access.
Get size of current return data buffer to memory. This contains the return data
from the last executed call, callCode, callDelegate, callStatic or create.
Note: create only fills the return data buffer in case of a failure.
Parameters
none
Returns
dataSize i32
Copies the current return data buffer to memory. This contains the return data
from last executed call, callCode, callDelegate, callStatic or create.
Note: create only fills the return data buffer in case of a failure.
Parameters
resultOffseti32ptr the memory offset to load data into (bytes)dataOffseti32 the offset in the return datalengthi32 the length of data to copy
Returns
nothing
Trap conditions
- load
lengthnumber of bytes from input data buffer atdataOffsetresults in out of bounds access, - store
lengthnumber of bytes to memory atresultOffsetresults in out of bounds access.
Mark account for later deletion and give the remaining balance to the specified beneficiary address. This will cause a trap and the execution will be aborted immediately.
Parameters
addressOffseti32ptr the memory offset to load the address from (address)
Returns
doesn't return
Trap conditions
- load
addressfrom memory ataddressOffsetresults in out of bounds access.
Get the block’s timestamp.
Parameters
none
Returns
blockTimestamp i64