From 08399d699eb2323f040ea4d3f92480c2b5a68212 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 | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/eth_interface.md b/eth_interface.md index dcaef381..2dba5d0d 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,16 +226,37 @@ 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**