Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a8214fd
Add logic, test, broken benchmark
yarikbratashchuk May 18, 2022
143c158
Merge branch 'master' into seal_reentrant_count
yarikbratashchuk May 20, 2022
219eb84
Merge branch 'master' into seal_reentrant_count
yarikbratashchuk May 22, 2022
fccd751
account_entrance_count
yarikbratashchuk May 23, 2022
0a70239
Addressing comments
yarikbratashchuk May 29, 2022
6f3655a
Address @agryaznov's comments
yarikbratashchuk Jun 1, 2022
f29884b
Add test for account_entrance_count, fix ci
yarikbratashchuk Jun 2, 2022
72c8f83
Cargo fmt
yarikbratashchuk Jun 2, 2022
0f6f894
Fix tests
yarikbratashchuk Jun 2, 2022
949c438
Fix tests
yarikbratashchuk Jun 5, 2022
f34b6da
Remove delegated call from test, address comments
yarikbratashchuk Jun 16, 2022
a036585
Minor fixes and indentation in wat files
yarikbratashchuk Jun 21, 2022
3be772e
Update test for account_entrance_count
yarikbratashchuk Jun 21, 2022
5fdc100
Update reentrant_count_call test
yarikbratashchuk Jun 21, 2022
b656c88
Delegate call test
yarikbratashchuk Jun 23, 2022
17bb81f
Cargo +nightly fmt
yarikbratashchuk Jun 24, 2022
2f7f405
Address comments
yarikbratashchuk Jun 24, 2022
5f01797
Update reentrant_count_works test
yarikbratashchuk Jun 24, 2022
013e3bf
Merge branch 'master' into master
yarikbratashchuk Jun 24, 2022
3948142
Apply weights diff
yarikbratashchuk Jul 3, 2022
9c0c06f
Add fixture descriptions
yarikbratashchuk Jul 3, 2022
9c5bb47
Update comments as suggested
yarikbratashchuk Jul 3, 2022
35c0349
Update reentrant_count_call test to use seal_address
yarikbratashchuk Jul 3, 2022
3400632
Merge branch 'paritytech:master' into master
RustNinja Aug 2, 2022
ebde8e1
Merge branch 'paritytech:master' into master
Artemka374 Aug 10, 2022
321a828
change account_entrance_count_call fixture to use seal_caller
Artemka374 Sep 11, 2022
ee63f37
Merge remote-tracking branch 'paritytech/master'
Artemka374 Nov 2, 2022
3463795
fix compilation errors and apply some suggestions
Artemka374 Nov 4, 2022
1649d37
apply suggestions
Artemka374 Nov 5, 2022
8d94425
cargo fmt
Artemka374 Nov 7, 2022
0e48a2d
apply suggestions
Artemka374 Nov 10, 2022
7db2660
Merge remote-tracking branch 'paritytech/master'
Artemka374 Nov 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove delegated call from test, address comments
  • Loading branch information
yarikbratashchuk committed Jun 16, 2022
commit f34b6da3d19bf0184082beb39092fca0e4a52ff3
22 changes: 2 additions & 20 deletions frame/contracts/fixtures/reentrant_count_call.wat
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(module
(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)))
(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)))
(import "env" "memory" (memory 1 1))

Expand Down Expand Up @@ -33,23 +32,6 @@
(call $assert
(i32.eq (get_local $reentrant_count) (i32.const 1))
)

;; Delegated call to itself
(set_local $exit_code
(call $seal_delegate_call
(i32.const 0) ;; Set no call flags (reentrance is forbidden)
(i32.const 0) ;; Pointer to "callee" code_hash.
(i32.const 0) ;; Input is ignored
(i32.const 0) ;; Length of the input
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
)
)

;; Second reentrance is forbidden
(call $assert
(i32.eq (get_local $exit_code) (i32.const 1))
)
)
(else
;; Reading "callee" contract address (which is the address of the caller)
Expand All @@ -70,9 +52,9 @@
)
)

;; Check for status code 1, due to reentrance in delegated call.
;; assert reentrant_count == 0
(call $assert
(i32.eq (get_local $exit_code) (i32.const 1)) ;; ReturnCode::ContractTrapped
(i32.eq (get_local $reentrant_count) (i32.const 0))
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ where

fn reentrant_count(&self) -> u32 {
let id: &AccountIdOf<Self::T> = &self.top_frame().account_id;
self.account_entrance_count(id) - 1u32
self.account_entrance_count(id).checked_sub(1).unwrap_or(0)
}

fn account_entrance_count(&self, account_id: &AccountIdOf<Self::T>) -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,7 @@ fn set_code_hash() {

#[test]
#[cfg(feature = "unstable-interface")]
fn reentrant_count_works() {
fn reentrant_count_works_with_call() {
let (wasm1, code_hash1) = compile_module::<Test>("reentrant_count_call").unwrap();
let contract_addr1 = Contracts::contract_address(&ALICE, &code_hash1, &[]);

Expand Down
41 changes: 37 additions & 4 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ mod tests {
12
}
fn account_entrance_count(&self, _account_id: &AccountIdOf<Self::T>) -> u32 {
unimplemented!()
12
}
}

Expand Down Expand Up @@ -2617,12 +2617,45 @@ mod tests {
)
)
(func (export "call")
(local $exit_code i32)
(set_local $exit_code
(local $return_val i32)
(set_local $return_val
(call $seal_reentrant_count)
)
(call $assert
(i32.eq (get_local $exit_code) (i32.const 12))
(i32.eq (get_local $return_val) (i32.const 12))
)
)

(func (export "deploy"))
)
"#;

let mut mock_ext = MockExt::default();
execute(CODE, vec![], &mut mock_ext).unwrap();
}

#[test]
#[cfg(feature = "unstable-interface")]
fn account_entrance_count_works() {
const CODE: &str = r#"
(module
(import "__unstable__" "seal_account_entrance_count" (func $seal_account_entrance_count (param i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func $assert (param i32)
(block $ok
(br_if $ok
(get_local 0)
)
(unreachable)
)
)
(func (export "call")
(local $return_val i32)
(set_local $return_val
(call $seal_account_entrance_count (i32.const 0))
)
(call $assert
(i32.eq (get_local $return_val) (i32.const 12))
)
)

Expand Down