Skip to content

Commit

Permalink
Allow different type lengths to be stored and loaded
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
seanyoung committed Jun 21, 2019
1 parent 38eeded commit 2dff829
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions eth_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -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
Expand Down

0 comments on commit 2dff829

Please sign in to comment.