diff --git a/frame/contracts/fixtures/reentrant_count_call.wat b/frame/contracts/fixtures/reentrant_count_call.wat index 56e386c4f7e8a..eb7bad4cd5d95 100644 --- a/frame/contracts/fixtures/reentrant_count_call.wat +++ b/frame/contracts/fixtures/reentrant_count_call.wat @@ -1,6 +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 "seal1" "seal_input" (func $seal_input (param i32 i32))) + (import "seal1" "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)) @@ -41,7 +41,7 @@ (i32.const 0) ;; Pointer to "callee" code_hash. (i32.const 0) ;; Input is ignored (i32.const 0) ;; Length of the input - (i32.const 4294967295) ;; u32 max sentinel value: do not copy output + (i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output (i32.const 0) ;; Length is ignored in this case ) ) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 29bf8ace30247..57630753cb275 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -1243,7 +1243,7 @@ where } fn account_entrance_count(&self, account_id: &AccountIdOf) -> u32 { - self.frames().filter_map(|f| Some(f.delegate_caller.is_none() && &f.account_id == account_id)).count() as u32 + self.frames().filter_map(|f| (f.delegate_caller.is_none() && &f.account_id == account_id).then(|| true)).count() as u32 } } diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 33241150289b7..d709d755675e6 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -3231,7 +3231,7 @@ fn set_code_hash() { #[test] #[cfg(feature = "unstable-interface")] -fn reentrant_count() { +fn reentrant_count_works() { let (wasm1, code_hash1) = compile_module::("reentrant_count_call").unwrap(); let contract_addr1 = Contracts::contract_address(&ALICE, &code_hash1, &[]); diff --git a/frame/contracts/src/wasm/mod.rs b/frame/contracts/src/wasm/mod.rs index f07700c3b0a47..cfc2a9272af4f 100644 --- a/frame/contracts/src/wasm/mod.rs +++ b/frame/contracts/src/wasm/mod.rs @@ -2599,7 +2599,7 @@ mod tests { #[test] #[cfg(feature = "unstable-interface")] - fn reentrant_count() { + fn reentrant_count_works() { const CODE: &str = r#" (module (import "__unstable__" "seal_reentrant_count" (func $seal_reentrant_count (result i32))) diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index bd8b8435791bc..25dc85cfbc3af 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -2088,7 +2088,11 @@ define_env!(Env, , }, // Returns then number of times currently executing contract exists on the call stack in addition - // to the calling instance. A value of 0 means no reentrancy. + // to the calling instance. + // + // # Return Value + // + // Returns 0 when there is no reentrancy [__unstable__] seal_reentrant_count(ctx) -> u32 => { ctx.charge_gas(RuntimeCosts::ReentrantCount)?; Ok(ctx.ext.reentrant_count() as u32) @@ -2096,7 +2100,14 @@ define_env!(Env, , // Returns the number of times specified contract exists on the call stack. Delegated calls are // not calculated as separate calls. - // A value of 0 means it does not exist on the stack. + // + // # Parameters + // + // - `account_ptr`: a pointer to the contract address. + // + // # Return Value + // + // Returns 0 when the contract does not exist on the call stack. [__unstable__] seal_account_entrance_count(ctx, account_ptr: u32) -> u32 => { ctx.charge_gas(RuntimeCosts::AccountEntranceCount)?; let account_id: <::T as frame_system::Config>::AccountId = ctx.read_sandbox_memory_as(account_ptr)?;