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_reentrant_count returns contract reentrant count
#11539
Closed
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a8214fd
Add logic, test, broken benchmark
yarikbratashchuk 143c158
Merge branch 'master' into seal_reentrant_count
yarikbratashchuk 219eb84
Merge branch 'master' into seal_reentrant_count
yarikbratashchuk fccd751
account_entrance_count
yarikbratashchuk 0a70239
Addressing comments
yarikbratashchuk 6f3655a
Address @agryaznov's comments
yarikbratashchuk f29884b
Add test for account_entrance_count, fix ci
yarikbratashchuk 72c8f83
Cargo fmt
yarikbratashchuk 0f6f894
Fix tests
yarikbratashchuk 949c438
Fix tests
yarikbratashchuk f34b6da
Remove delegated call from test, address comments
yarikbratashchuk a036585
Minor fixes and indentation in wat files
yarikbratashchuk 3be772e
Update test for account_entrance_count
yarikbratashchuk 5fdc100
Update reentrant_count_call test
yarikbratashchuk b656c88
Delegate call test
yarikbratashchuk 17bb81f
Cargo +nightly fmt
yarikbratashchuk 2f7f405
Address comments
yarikbratashchuk 5f01797
Update reentrant_count_works test
yarikbratashchuk 013e3bf
Merge branch 'master' into master
yarikbratashchuk 3948142
Apply weights diff
yarikbratashchuk 9c0c06f
Add fixture descriptions
yarikbratashchuk 9c5bb47
Update comments as suggested
yarikbratashchuk 35c0349
Update reentrant_count_call test to use seal_address
yarikbratashchuk 3400632
Merge branch 'paritytech:master' into master
RustNinja ebde8e1
Merge branch 'paritytech:master' into master
Artemka374 321a828
change account_entrance_count_call fixture to use seal_caller
Artemka374 ee63f37
Merge remote-tracking branch 'paritytech/master'
Artemka374 3463795
fix compilation errors and apply some suggestions
Artemka374 1649d37
apply suggestions
Artemka374 8d94425
cargo fmt
Artemka374 0e48a2d
apply suggestions
Artemka374 7db2660
Merge remote-tracking branch 'paritytech/master'
Artemka374 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,37 @@ | ||
| ;; This fixture tests if account_entrance_count works as expected | ||
| ;; testing it with 2 different addresses | ||
| (module | ||
| (import "seal0" "seal_input" (func $seal_input (param i32 i32))) | ||
| (import "seal0" "seal_caller" (func $seal_caller (param i32 i32))) | ||
| (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) | ||
| (import "__unstable__" "account_entrance_count" (func $account_entrance_count (param i32) (result i32))) | ||
| (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") | ||
| ;; Reading "callee" input address | ||
| (call $seal_input (i32.const 0) (i32.const 32)) | ||
|
|
||
| (i32.store | ||
| (i32.const 36) | ||
| (call $account_entrance_count (i32.const 0)) | ||
| ) | ||
|
|
||
| (call $seal_return (i32.const 0) (i32.const 36) (i32.const 4)) | ||
| ) | ||
|
|
||
| (func (export "deploy")) | ||
|
|
||
| ) | ||
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,76 @@ | ||
| ;; This fixture recursively tests if reentrant_count returns correct reentrant count value when | ||
| ;; using seal_call to make caller contract call to itself | ||
| (module | ||
yarikbratashchuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (import "seal0" "seal_input" (func $seal_input (param i32 i32))) | ||
| (import "seal0" "seal_address" (func $seal_address (param i32 i32))) | ||
| (import "seal1" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32) (result i32))) | ||
| (import "__unstable__" "reentrant_count" (func $reentrant_count (result i32))) | ||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 32) reserved for $seal_address output | ||
|
|
||
| ;; [32, 36) buffer for the call stack height | ||
|
|
||
| ;; [36, 40) size of the input buffer | ||
| (data (i32.const 36) "\04") | ||
|
|
||
| ;; [40, 44) length of the buffer for $seal_address | ||
| (data (i32.const 40) "\20") | ||
|
|
||
| (func $assert (param i32) | ||
| (block $ok | ||
| (br_if $ok | ||
| (get_local 0) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
| ) | ||
| (func (export "call") | ||
| (local $expected_reentrant_count i32) | ||
| (local $seal_call_exit_code i32) | ||
|
|
||
| ;; reading current contract address | ||
| (call $seal_address (i32.const 0) (i32.const 40)) | ||
|
|
||
| ;; reading passed input | ||
| (call $seal_input (i32.const 32) (i32.const 36)) | ||
|
|
||
| ;; reading manually passed reentrant count | ||
| (set_local $expected_reentrant_count (i32.load (i32.const 32))) | ||
|
|
||
| ;; reentrance count is calculated correctly | ||
| (call $assert | ||
| (i32.eq (call $reentrant_count) (get_local $expected_reentrant_count)) | ||
| ) | ||
|
|
||
yarikbratashchuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ;; re-enter 5 times in a row and assert that the reentrant counter works as expected | ||
| (i32.eq (call $reentrant_count) (i32.const 5)) | ||
| (if | ||
| (then) ;; recursion exit case | ||
| (else | ||
| ;; incrementing $expected_reentrant_count passed to the contract | ||
| (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 8) ;; Allow reentrancy flag set | ||
| (i32.const 0) ;; Pointer to "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 32) ;; Pointer to input data buffer address | ||
| (i32.const 4) ;; 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")) | ||
| ) | ||
71 changes: 71 additions & 0 deletions
71
frame/contracts/fixtures/reentrant_count_delegated_call.wat
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,71 @@ | ||
| ;; This fixture recursively tests if reentrant_count returns correct reentrant count value when | ||
| ;; using seal_delegate_call to make caller contract delegate call to itself | ||
| (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__" "reentrant_count" (func $reentrant_count (result i32))) | ||
| (import "env" "memory" (memory 1 1)) | ||
|
|
||
| ;; [0, 32) buffer where code hash is copied | ||
|
|
||
| ;; [32, 36) buffer for the call stack height | ||
|
|
||
| ;; [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_height i32) | ||
| (local $delegate_call_exit_code i32) | ||
|
|
||
| ;; Reading input | ||
| (call $seal_input (i32.const 0) (i32.const 36)) | ||
|
|
||
| ;; reading passed callstack height | ||
| (set_local $callstack_height (i32.load (i32.const 32))) | ||
|
|
||
| ;; incrementing callstack height | ||
| (i32.store (i32.const 32) (i32.add (i32.load (i32.const 32)) (i32.const 1))) | ||
|
|
||
| ;; reentrance count stays 0 | ||
| (call $assert | ||
| (i32.eq (call $reentrant_count) (i32.const 0)) | ||
| ) | ||
|
|
||
| (i32.eq (get_local $callstack_height) (i32.const 5)) | ||
| (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) ;; Pointer to the input data | ||
| (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_height) (i32.const 5)) | ||
| ) | ||
| ) | ||
|
|
||
| (func (export "deploy")) | ||
| ) |
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
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.