Skip to content

Commit 2dff829

Browse files
committed
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 <[email protected]>
1 parent 38eeded commit 2dff829

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

Diff for: eth_interface.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,13 @@ value.
207207

208208
## storageStore
209209

210-
Store 256-bit a value in memory to persistent storage
210+
Store bytes value in memory to persistent storage
211211

212212
**Parameters**
213213

214214
- `pathOffset` **i32ptr** the memory offset to load the path from (`bytes32`)
215-
- `valueOffset` **i32ptr** the memory offset to load the value from (`bytes32`)
215+
- `valueOffset` **i32ptr** the memory offset to load the value from (`bytes`)
216+
- `valueLen` **i32** the length of the value
216217

217218
**Returns**
218219

@@ -225,22 +226,44 @@ Store 256-bit a value in memory to persistent storage
225226

226227
## storageLoad
227228

228-
Loads a 256-bit a value to memory from persistent storage
229+
Loads bytes value to memory from persistent storage. No more than
230+
`resultMaxLength` is loaded. Returns the actual number of bytes loaded.
231+
Returns 0 if there is nothing stored at the path.
229232

230233
**Parameters**
231234

232235
- `pathOffset` **i32ptr** the memory offset to load the path from (`bytes32`)
233-
- `resultOffset` **i32ptr** the memory offset to store the result at (`bytes32`)
236+
- `resultOffset` **i32ptr** the memory offset to store the result at (`bytes`)
237+
- `resultMaxLength` **i32** the maximum length to load
234238

235239
**Returns**
236240

237-
*nothing*
241+
- `lengthLoaded` **i32** Actual number of bytes loaded from storage
242+
243+
**Trap conditions**
244+
245+
- load `bytes32` from memory at `pathOffset` results in out of bounds access,
246+
- store `bytes32` to memory at `resultOffset` results in out of bounds access.
247+
248+
## storageSize
249+
250+
Returns the length of the storage at the path.
251+
Returns 0 if there is nothing stored at the path.
252+
253+
**Parameters**
254+
255+
- `pathOffset` **i32ptr** the memory offset to load the path from (`bytes32`)
256+
257+
**Returns**
258+
259+
- `size` **i32** Number of bytes at the path
238260

239261
**Trap conditions**
240262

241263
- load `bytes32` from memory at `pathOffset` results in out of bounds access,
242264
- store `bytes32` to memory at `resultOffset` results in out of bounds access.
243265

266+
244267
## getCaller
245268

246269
Gets caller address and loads it into memory at the given offset. This is

0 commit comments

Comments
 (0)