This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
seal: Fix and improve error reporting #6773
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f8539a0
seal: Rework ext_transfer, ext_instantiate, ext_call error handling
athei 2a19ceb
seal: Improve error messages on memory access failures
athei 694dbc1
seal: Convert contract trapped to module error
athei 3039e5b
seal: Add additional tests for transfer, call, instantiate
athei 4c88bb8
Make it more pronounced that to_execution_result handles trap_reason
athei af38fe3
Improve ReturnCode docs
athei be22f99
Fix whitespace issues in wat files
athei c095acc
Improve ReturnCode doc
athei afc7e07
Improve ErrorOrigin doc and variant naming
athei 97ffa45
Improve docs on ExecResult and ExecError
athei f5e7127
Encode u32 sentinel value as hex
athei 36324ce
with_nested_context no longer accepts an Option for trie
athei 9d9ea7b
Fix successful typo
athei 12374eb
Rename InvalidContractCalled to NotCallable
athei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| ;; This calls Django (4) and transfers 100 balance during this call and copies the return code | ||
| ;; of this call to the output buffer. | ||
| ;; It also forwards its input to the callee. | ||
| (module | ||
| (import "env" "ext_input" (func $ext_input (param i32 i32))) | ||
| (import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32))) | ||
| (import "env" "ext_return" (func $ext_return (param i32 i32 i32))) | ||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 8) address of django | ||
| (data (i32.const 0) "\04\00\00\00\00\00\00\00") | ||
|
|
||
| ;; [8, 16) 100 balance | ||
| (data (i32.const 8) "\64\00\00\00\00\00\00\00") | ||
|
|
||
| ;; [16, 20) here we store the return code of the transfer | ||
|
|
||
| ;; [20, 24) here we store the input data | ||
|
|
||
| ;; [24, 28) size of the input data | ||
| (data (i32.const 24) "\04") | ||
|
|
||
| (func (export "deploy")) | ||
|
|
||
| (func (export "call") | ||
| (call $ext_input (i32.const 20) (i32.const 24)) | ||
| (i32.store | ||
| (i32.const 16) | ||
| (call $ext_call | ||
| (i32.const 0) ;; Pointer to "callee" address. | ||
| (i32.const 8) ;; Length of "callee" address. | ||
| (i64.const 0) ;; How much gas to devote for the execution. 0 = all. | ||
| (i32.const 8) ;; Pointer to the buffer with value to transfer | ||
| (i32.const 8) ;; Length of the buffer with value to transfer. | ||
| (i32.const 20) ;; Pointer to input data buffer address | ||
| (i32.load (i32.const 24)) ;; Length of input data buffer | ||
| (i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output | ||
| (i32.const 0) ;; Ptr to output buffer len | ||
| ) | ||
| ) | ||
| ;; exit with success and take transfer return code to the output buffer | ||
| (call $ext_return (i32.const 0) (i32.const 16) (i32.const 4)) | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| ;; This instantiats Charlie (3) and transfers 100 balance during this call and copies the return code | ||
| ;; of this call to the output buffer. | ||
| ;; The first 32 byte of input is the code hash to instantiate | ||
| ;; The rest of the input is forwarded to the constructor of the callee | ||
| (module | ||
| (import "env" "ext_input" (func $ext_input (param i32 i32))) | ||
| (import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32))) | ||
| (import "env" "ext_return" (func $ext_return (param i32 i32 i32))) | ||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 8) address of django | ||
| (data (i32.const 0) "\04\00\00\00\00\00\00\00") | ||
|
|
||
| ;; [8, 16) 100 balance | ||
| (data (i32.const 8) "\64\00\00\00\00\00\00\00") | ||
|
|
||
| ;; [16, 20) here we store the return code of the transfer | ||
|
|
||
| ;; [20, 24) size of the input buffer | ||
| (data (i32.const 20) "\FF") | ||
|
|
||
| ;; [24, inf) input buffer | ||
|
|
||
| (func (export "deploy")) | ||
|
|
||
| (func (export "call") | ||
| (call $ext_input (i32.const 24) (i32.const 20)) | ||
| (i32.store | ||
| (i32.const 16) | ||
| (call $ext_instantiate | ||
| (i32.const 24) ;; Pointer to the code hash. | ||
| (i32.const 32) ;; Length of the code hash. | ||
| (i64.const 0) ;; How much gas to devote for the execution. 0 = all. | ||
| (i32.const 8) ;; Pointer to the buffer with value to transfer | ||
| (i32.const 8) ;; Length of the buffer with value to transfer. | ||
| (i32.const 56) ;; Pointer to input data buffer address | ||
| (i32.sub (i32.load (i32.const 20)) (i32.const 32)) ;; Length of input data buffer | ||
| (i32.const 0xffffffff) ;; u32 max sentinel value: do not copy address | ||
| (i32.const 0) ;; Length is ignored in this case | ||
| (i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output | ||
| (i32.const 0) ;; Length is ignored in this case | ||
| ) | ||
| ) | ||
| ;; exit with success and take transfer return code to the output buffer | ||
| (call $ext_return (i32.const 0) (i32.const 16) (i32.const 4)) | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| (module | ||
| (import "env" "ext_input" (func $ext_input (param i32 i32))) | ||
| (import "env" "ext_return" (func $ext_return (param i32 i32 i32))) | ||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| (func (export "deploy") | ||
| (call $ok_trap_revert) | ||
| ) | ||
|
|
||
| (func (export "call") | ||
| (call $ok_trap_revert) | ||
| ) | ||
|
|
||
| (func $ok_trap_revert | ||
| (i32.store (i32.const 4) (i32.const 4)) | ||
| (call $ext_input (i32.const 0) (i32.const 4)) | ||
| (block $IF_2 | ||
| (block $IF_1 | ||
| (block $IF_0 | ||
| (br_table $IF_0 $IF_1 $IF_2 | ||
| (i32.load8_u (i32.const 0)) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
| ;; 0 = return with success | ||
| return | ||
| ) | ||
| ;; 1 = revert | ||
| (call $ext_return (i32.const 1) (i32.const 0) (i32.const 0)) | ||
| (unreachable) | ||
| ) | ||
| ;; 2 = trap | ||
| (unreachable) | ||
| ) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| ;; This transfers 100 balance to the zero account and copies the return code | ||
| ;; of this transfer to the output buffer. | ||
| (module | ||
| (import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32))) | ||
| (import "env" "ext_return" (func $ext_return (param i32 i32 i32))) | ||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 8) zero-adress | ||
| (data (i32.const 0) "\00\00\00\00\00\00\00\00") | ||
|
|
||
| ;; [8, 16) 100 balance | ||
| (data (i32.const 8) "\64\00\00\00\00\00\00\00") | ||
|
|
||
| ;; [16, 20) here we store the return code of the transfer | ||
|
|
||
| (func (export "deploy")) | ||
|
|
||
| (func (export "call") | ||
| (i32.store | ||
| (i32.const 16) | ||
| (call $ext_transfer | ||
| (i32.const 0) ;; ptr to destination address | ||
| (i32.const 8) ;; length of destination address | ||
| (i32.const 8) ;; ptr to value to transfer | ||
| (i32.const 8) ;; length of value to transfer | ||
| ) | ||
| ) | ||
| ;; exit with success and take transfer return code to the output buffer | ||
| (call $ext_return (i32.const 0) (i32.const 16) (i32.const 4)) | ||
| ) | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.