Skip to content

Commit

Permalink
[pallet-revive] Fix caller_is_root return value (#7086)
Browse files Browse the repository at this point in the history
Closes #6767.

The return type of the host function `caller_is_root` was denoted as
`u32` in `pallet_revive_uapi`. This PR fixes the return type to `bool`.

As a drive-by, the PR re-exports `pallet_revive::exec::Origin` to extend
what can be tested externally.

---------

Co-authored-by: Cyrill Leutwiler <[email protected]>
  • Loading branch information
cmichi and xermicus authored Jan 15, 2025
1 parent ef064a3 commit 88f898e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
11 changes: 11 additions & 0 deletions prdoc/pr_7086.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: '[pallet-revive] Fix `caller_is_root` return value'
doc:
- audience: Runtime Dev
description: The return type of the host function `caller_is_root` was denoted as `u32`
in `pallet_revive_uapi`. This PR fixes the return type to `bool`. As a drive-by, the
PR re-exports `pallet_revive::exec::Origin` to extend what can be tested externally.
crates:
- name: pallet-revive
bump: minor
- name: pallet-revive-uapi
bump: major
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub trait Ext: sealing::Sealed {
/// Returns `Err(InvalidImmutableAccess)` if called from a constructor.
fn get_immutable_data(&mut self) -> Result<ImmutableData, DispatchError>;

/// Set the the immutable data of the current contract.
/// Set the immutable data of the current contract.
///
/// Returns `Err(InvalidImmutableAccess)` if not called from a constructor.
///
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct RefTimeLeft(u64);

/// Resource that needs to be synced to the executor.
///
/// Wrapped to make sure that the resource will be synced back the the executor.
/// Wrapped to make sure that the resource will be synced back to the executor.
#[must_use]
pub struct Syncable(polkavm::Gas);

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::{
runtime::{gas_from_fee, GAS_PRICE},
GasEncoder, GenericTransaction,
},
exec::{AccountIdOf, ExecError, Executable, Ext, Key, Origin, Stack as ExecStack},
exec::{AccountIdOf, ExecError, Executable, Ext, Key, Stack as ExecStack},
gas::GasMeter,
storage::{meter::Meter as StorageMeter, ContractInfo, DeletionQueueManager},
wasm::{CodeInfo, RuntimeCosts, WasmBlob},
Expand Down Expand Up @@ -84,7 +84,7 @@ use sp_runtime::{
pub use crate::{
address::{create1, create2, AccountId32Mapper, AddressMapper},
debug::Tracing,
exec::MomentOf,
exec::{MomentOf, Origin},
pallet::*,
};
pub use primitives::*;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/uapi/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ pub trait HostFn: private::Sealed {
/// A return value of `true` indicates that this contract is being called by a root origin,
/// and `false` indicates that the caller is a signed origin.
#[unstable_hostfn]
fn caller_is_root() -> u32;
fn caller_is_root() -> bool;

/// Clear the value at the given key in the contract storage.
///
Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/revive/uapi/src/host/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,9 @@ impl HostFn for HostFnImpl {
}

#[unstable_hostfn]
fn caller_is_root() -> u32 {
unsafe { sys::caller_is_root() }.into_u32()
fn caller_is_root() -> bool {
let ret_val = unsafe { sys::caller_is_root() };
ret_val.into_bool()
}

#[unstable_hostfn]
Expand Down

0 comments on commit 88f898e

Please sign in to comment.