From 2dff829c1eadecf4aa2d78e008c0babeae53b9a0 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Fri, 21 Jun 2019 10:58:37 +0100 Subject: [PATCH] Allow different type lengths to be stored and loaded In a wasm context not all types are 256 bit like in evm. This would make easier to store smaller primitives (e.g. i32), since they would not require padding. The bigger win is when storing/retrieving dynamically sized arrays. Strings can be stored under a single key and do not require splitting up into smaller 32 byte chunks, and arrays do not need to store a size parameter. Signed-off-by: Sean Young --- eth_interface.md | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/eth_interface.md b/eth_interface.md index dcaef381..59341531 100644 --- a/eth_interface.md +++ b/eth_interface.md @@ -207,12 +207,13 @@ value. ## storageStore -Store 256-bit a value in memory to persistent storage +Store bytes value in memory to persistent storage **Parameters** - `pathOffset` **i32ptr** the memory offset to load the path from (`bytes32`) -- `valueOffset` **i32ptr** the memory offset to load the value from (`bytes32`) +- `valueOffset` **i32ptr** the memory offset to load the value from (`bytes`) +- `valueLen` **i32** the length of the value **Returns** @@ -225,22 +226,44 @@ Store 256-bit a value in memory to persistent storage ## storageLoad -Loads a 256-bit a value to memory from persistent storage +Loads bytes value to memory from persistent storage. No more than +`resultMaxLength` is loaded. Returns the actual number of bytes loaded. +Returns 0 if there is nothing stored at the path. **Parameters** - `pathOffset` **i32ptr** the memory offset to load the path from (`bytes32`) -- `resultOffset` **i32ptr** the memory offset to store the result at (`bytes32`) +- `resultOffset` **i32ptr** the memory offset to store the result at (`bytes`) +- `resultMaxLength` **i32** the maximum length to load **Returns** -*nothing* +- `lengthLoaded` **i32** Actual number of bytes loaded from storage + +**Trap conditions** + +- load `bytes32` from memory at `pathOffset` results in out of bounds access, +- store `bytes32` to memory at `resultOffset` results in out of bounds access. + +## storageSize + +Returns the length of the storage at the path. +Returns 0 if there is nothing stored at the path. + +**Parameters** + +- `pathOffset` **i32ptr** the memory offset to load the path from (`bytes32`) + +**Returns** + +- `size` **i32** Number of bytes at the path **Trap conditions** - load `bytes32` from memory at `pathOffset` results in out of bounds access, - store `bytes32` to memory at `resultOffset` results in out of bounds access. + ## getCaller Gets caller address and loads it into memory at the given offset. This is