From 27eaf1be25d89934f64ebfc69e8589aa2e9d2184 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 4 Aug 2016 09:45:21 +0100 Subject: [PATCH] Add eWASM Contract Interface specification --- README.md | 3 ++- contract_interface.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 contract_interface.md diff --git a/README.md b/README.md index ec47a879..aeeee191 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ A few key points: eWASM is a restricted subset of WASM to be used for contracts in Ethereum. eWASM: -* specifies the semantics for an *eWASM contract* +* specifies the [semantics for an *eWASM contract*](./contract_interface.md) * specifies an [Ethereum environment interface](./eth_interface.md) to facilitate interaction with the Ethereum environment from an *eWASM contract* * specifies [metering](./metering.md) for instructions * and aims to restrict [non-deterministic behavior](https://github.com/WebAssembly/design/blob/master/Nondeterminism.md) @@ -49,6 +49,7 @@ eWASM: * [FAQ](./faq.md) * [Rationale](./rationale.md) * [Ethereum environment interface](./eth_interface.md) +* [eWASM Contract Interface](./contract_interface.md) * [Original Proposal](https://github.com/ethereum/EIPs/issues/48) (EIP#48) * [WebAssembly design documents](https://github.com/WebAssembly/design) diff --git a/contract_interface.md b/contract_interface.md new file mode 100644 index 00000000..8105e4ce --- /dev/null +++ b/contract_interface.md @@ -0,0 +1,30 @@ +# eWASM Contract Interface (ECI) Specification; Version 0 + +The eWASM Contract Interface (ECI) specifies the structure of a contract module. + +### Wire format + +Every contract must be stored in the [WebAssembly Binary Encoding](https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md) format (in short, WASM bytecode). + +### Imports + +A contract can only import symbols specified in the [Ethereum Environment Interface](./eth_interface.md). + +### Exports + +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. + +### Entry point + +The method exported as `main` will be executed by the VM. + +### Debug-mode + +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 `debug` namespace: +- `print(i32 offset, i32 length)`: print a string as pointed by `offset` +- `printHex(i32 offset, i32 length)`: print a hex representation of the memory pointed to by `offset`