-
Notifications
You must be signed in to change notification settings - Fork 2.7k
seal_reentrant_count returns contract reentrant count
#11539
Changes from 19 commits
a8214fd
143c158
219eb84
fccd751
0a70239
6f3655a
f29884b
72c8f83
0f6f894
949c438
f34b6da
a036585
3be772e
5fdc100
b656c88
17bb81f
2f7f405
5f01797
013e3bf
3948142
9c0c06f
9c5bb47
35c0349
3400632
ebde8e1
321a828
ee63f37
3463795
1649d37
8d94425
0e48a2d
7db2660
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| (module | ||
| (import "seal0" "seal_input" (func $seal_input (param i32 i32))) | ||
| (import "__unstable__" "seal_account_entrance_count" (func $seal_account_entrance_count (param i32) (result i32))) | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 32) buffer where input is copied | ||
|
|
||
| ;; [32, 36) size of the input buffer | ||
| (data (i32.const 32) "\20") | ||
|
|
||
| (func $assert (param i32) | ||
| (block $ok | ||
| (br_if $ok | ||
| (get_local 0) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
| ) | ||
| (func (export "call") | ||
| (local $account_entrance_count i32) | ||
|
|
||
| ;; Reading "callee" contract address (which is the address of the caller) | ||
|
||
| (call $seal_input (i32.const 0) (i32.const 32)) | ||
|
|
||
| ;; assert account_entrance_count == 1 | ||
| (call $assert | ||
| (i32.eq (call $seal_account_entrance_count (i32.const 0)) (i32.const 1)) | ||
| ) | ||
|
|
||
| ;; assert account_entrance_count == 0 for another account | ||
| (call $assert | ||
| (i32.eq (call $seal_account_entrance_count (i32.const 32)) (i32.const 0)) | ||
| ) | ||
| ) | ||
|
|
||
| (func (export "deploy")) | ||
|
|
||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| (module | ||
yarikbratashchuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (import "seal0" "seal_input" (func $seal_input (param i32 i32))) | ||
| (import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32))) | ||
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (import "__unstable__" "seal_reentrant_count" (func $seal_reentrant_count (result i32))) | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 32) buffer where code hash is copied | ||
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ;; [32, 36) buffer for the call stack high | ||
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ;; [36, 40) size of the input buffer | ||
| (data (i32.const 36) "\24") | ||
|
|
||
| (func $assert (param i32) | ||
| (block $ok | ||
| (br_if $ok | ||
| (get_local 0) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
| ) | ||
| (func (export "call") | ||
| (local $manual_reentrant_count i32) | ||
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (local $seal_call_exit_code i32) | ||
|
|
||
| ;; Reading input | ||
| (call $seal_input (i32.const 0) (i32.const 36)) | ||
|
|
||
| ;; reading manually passed reentrant count | ||
| (set_local $manual_reentrant_count (i32.load (i32.const 32))) | ||
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ;; reentrance count is calculated correctly | ||
| (call $assert | ||
| (i32.eq (call $seal_reentrant_count) (get_local $manual_reentrant_count)) | ||
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
yarikbratashchuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (i32.eq (call $seal_reentrant_count) (i32.const 5)) | ||
| (if | ||
| (then) ;; recursion exit case | ||
| (else | ||
| ;; incrementing manual reentrant count high | ||
yarikbratashchuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (i32.store (i32.const 32) (i32.add (i32.load (i32.const 32)) (i32.const 1))) | ||
|
|
||
| ;; Call to itself | ||
| (set_local $seal_call_exit_code | ||
| (call $seal_call | ||
| (i32.const 0) ;; Pointer to "callee" address. | ||
| (i32.const 32) ;; Length of "callee" address. | ||
| (i64.const 0) ;; How much gas to devote for the execution. 0 = all. | ||
| (i32.const 0) ;; Pointer to the buffer with value to transfer | ||
| (i32.const 0) ;; Length of the buffer with value to transfer. | ||
| (i32.const 0) ;; Pointer to input data buffer address | ||
| (i32.const 36) ;; Length of input data buffer | ||
| (i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output | ||
| (i32.const 0) ;; Ptr to output buffer len | ||
| ) | ||
| ) | ||
|
|
||
| (call $assert | ||
| (i32.eq (get_local $seal_call_exit_code) (i32.const 0)) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| (func (export "deploy")) | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| (module | ||
| (import "seal0" "seal_input" (func $seal_input (param i32 i32))) | ||
| (import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32))) | ||
| (import "seal0" "seal_delegate_call" (func $seal_delegate_call (param i32 i32 i32 i32 i32 i32) (result i32))) | ||
| (import "__unstable__" "seal_reentrant_count" (func $seal_reentrant_count (result i32))) | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 32) buffer where code hash is copied | ||
|
|
||
| ;; [32, 36) buffer for the call stack high | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ;; [36, 40) size of the input buffer | ||
| (data (i32.const 36) "\24") | ||
|
|
||
| (func $assert (param i32) | ||
| (block $ok | ||
| (br_if $ok | ||
| (get_local 0) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
| ) | ||
| (func (export "call") | ||
| (local $callstack_high i32) | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (local $delegate_call_exit_code i32) | ||
|
|
||
| ;; Reading input | ||
| (call $seal_input (i32.const 0) (i32.const 36)) | ||
|
|
||
| ;; reading passed callstack high | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (set_local $callstack_high (i32.load (i32.const 32))) | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ;; incrementing callstack high | ||
| (i32.store (i32.const 32) (i32.add (i32.load (i32.const 32)) (i32.const 1))) | ||
|
|
||
| ;; reentrance count stays 0 | ||
| (call $assert | ||
| (i32.eq (call $seal_reentrant_count) (i32.const 0)) | ||
| ) | ||
|
|
||
| (i32.eq (get_local $callstack_high) (i32.const 5)) | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (if | ||
| (then) ;; exit recursion case | ||
| (else | ||
| ;; Call to itself | ||
| (set_local $delegate_call_exit_code | ||
| (call $seal_delegate_call | ||
| (i32.const 0) ;; Set no call flags | ||
| (i32.const 0) ;; Pointer to "callee" code_hash. | ||
| (i32.const 0) ;; Input is ingored | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (i32.const 36) ;; Length of the input | ||
| (i32.const 4294967295) ;; u32 max sentinel value: do not copy output | ||
| (i32.const 0) ;; Length is ignored in this case | ||
| ) | ||
| ) | ||
|
|
||
| (call $assert | ||
| (i32.eq (get_local $delegate_call_exit_code) (i32.const 0)) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| (call $assert | ||
| (i32.le_s (get_local $callstack_high) (i32.const 5)) | ||
agryaznov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| ) | ||
|
|
||
| (func (export "deploy")) | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.