Skip to content

Commit 55d8f92

Browse files
davidk-ptDavidK
authored andcommitted
pallet-revive: disable host functions not in revive recompiler (paritytech#6844)
Resolves paritytech#6720 List of used host functions in PolkaVM recompiler is here https://github.com/paritytech/revive/blob/main/crates/runtime-api/src/polkavm_imports.c#L65 --------- Co-authored-by: DavidK <[email protected]>
1 parent f2c078b commit 55d8f92

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

prdoc/pr_6844.prdoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: 'pallet-revive: disable host functions unused in solidity PolkaVM compiler'
2+
doc:
3+
- audience: Runtime Dev
4+
description: Disables host functions in contracts that are not enabled
5+
in solidity PolkaVM compiler to reduce surface of possible attack vectors.
6+
crates:
7+
- name: pallet-revive
8+
bump: major

substrate/frame/revive/src/wasm/runtime.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ pub mod env {
11481148

11491149
/// Clear the value at the given key in the contract storage.
11501150
/// See [`pallet_revive_uapi::HostFn::clear_storage`]
1151-
#[stable]
11521151
#[mutating]
11531152
fn clear_storage(
11541153
&mut self,
@@ -1177,7 +1176,6 @@ pub mod env {
11771176

11781177
/// Checks whether there is a value stored under the given key.
11791178
/// See [`pallet_revive_uapi::HostFn::contains_storage`]
1180-
#[stable]
11811179
fn contains_storage(
11821180
&mut self,
11831181
memory: &mut M,
@@ -1190,7 +1188,6 @@ pub mod env {
11901188

11911189
/// Retrieve and remove the value under the given key from storage.
11921190
/// See [`pallet_revive_uapi::HostFn::take_storage`]
1193-
#[stable]
11941191
#[mutating]
11951192
fn take_storage(
11961193
&mut self,
@@ -1301,7 +1298,6 @@ pub mod env {
13011298

13021299
/// Remove the calling account and transfer remaining **free** balance.
13031300
/// See [`pallet_revive_uapi::HostFn::terminate`].
1304-
#[stable]
13051301
#[mutating]
13061302
fn terminate(&mut self, memory: &mut M, beneficiary_ptr: u32) -> Result<(), TrapReason> {
13071303
self.terminate(memory, beneficiary_ptr)
@@ -1399,7 +1395,6 @@ pub mod env {
13991395

14001396
/// Checks whether a specified address belongs to a contract.
14011397
/// See [`pallet_revive_uapi::HostFn::is_contract`].
1402-
#[stable]
14031398
fn is_contract(&mut self, memory: &mut M, account_ptr: u32) -> Result<u32, TrapReason> {
14041399
self.charge_gas(RuntimeCosts::IsContract)?;
14051400
let address = memory.read_h160(account_ptr)?;
@@ -1438,7 +1433,6 @@ pub mod env {
14381433

14391434
/// Retrieve the code hash of the currently executing contract.
14401435
/// See [`pallet_revive_uapi::HostFn::own_code_hash`].
1441-
#[stable]
14421436
fn own_code_hash(&mut self, memory: &mut M, out_ptr: u32) -> Result<(), TrapReason> {
14431437
self.charge_gas(RuntimeCosts::OwnCodeHash)?;
14441438
let code_hash = *self.ext.own_code_hash();
@@ -1453,15 +1447,13 @@ pub mod env {
14531447

14541448
/// Checks whether the caller of the current contract is the origin of the whole call stack.
14551449
/// See [`pallet_revive_uapi::HostFn::caller_is_origin`].
1456-
#[stable]
14571450
fn caller_is_origin(&mut self, _memory: &mut M) -> Result<u32, TrapReason> {
14581451
self.charge_gas(RuntimeCosts::CallerIsOrigin)?;
14591452
Ok(self.ext.caller_is_origin() as u32)
14601453
}
14611454

14621455
/// Checks whether the caller of the current contract is root.
14631456
/// See [`pallet_revive_uapi::HostFn::caller_is_root`].
1464-
#[stable]
14651457
fn caller_is_root(&mut self, _memory: &mut M) -> Result<u32, TrapReason> {
14661458
self.charge_gas(RuntimeCosts::CallerIsRoot)?;
14671459
Ok(self.ext.caller_is_root() as u32)
@@ -1505,7 +1497,6 @@ pub mod env {
15051497

15061498
/// Stores the amount of weight left into the supplied buffer.
15071499
/// See [`pallet_revive_uapi::HostFn::weight_left`].
1508-
#[stable]
15091500
fn weight_left(
15101501
&mut self,
15111502
memory: &mut M,
@@ -1631,7 +1622,6 @@ pub mod env {
16311622

16321623
/// Stores the minimum balance (a.k.a. existential deposit) into the supplied buffer.
16331624
/// See [`pallet_revive_uapi::HostFn::minimum_balance`].
1634-
#[stable]
16351625
fn minimum_balance(&mut self, memory: &mut M, out_ptr: u32) -> Result<(), TrapReason> {
16361626
self.charge_gas(RuntimeCosts::MinimumBalance)?;
16371627
Ok(self.write_fixed_sandbox_output(
@@ -1720,7 +1710,6 @@ pub mod env {
17201710

17211711
/// Computes the SHA2 256-bit hash on the given input buffer.
17221712
/// See [`pallet_revive_uapi::HostFn::hash_sha2_256`].
1723-
#[stable]
17241713
fn hash_sha2_256(
17251714
&mut self,
17261715
memory: &mut M,
@@ -1752,7 +1741,6 @@ pub mod env {
17521741

17531742
/// Computes the BLAKE2 256-bit hash on the given input buffer.
17541743
/// See [`pallet_revive_uapi::HostFn::hash_blake2_256`].
1755-
#[stable]
17561744
fn hash_blake2_256(
17571745
&mut self,
17581746
memory: &mut M,
@@ -1768,7 +1756,6 @@ pub mod env {
17681756

17691757
/// Computes the BLAKE2 128-bit hash on the given input buffer.
17701758
/// See [`pallet_revive_uapi::HostFn::hash_blake2_128`].
1771-
#[stable]
17721759
fn hash_blake2_128(
17731760
&mut self,
17741761
memory: &mut M,
@@ -1814,7 +1801,6 @@ pub mod env {
18141801

18151802
/// Emit a custom debug message.
18161803
/// See [`pallet_revive_uapi::HostFn::debug_message`].
1817-
#[stable]
18181804
fn debug_message(
18191805
&mut self,
18201806
memory: &mut M,
@@ -1932,7 +1918,6 @@ pub mod env {
19321918

19331919
/// Recovers the ECDSA public key from the given message hash and signature.
19341920
/// See [`pallet_revive_uapi::HostFn::ecdsa_recover`].
1935-
#[stable]
19361921
fn ecdsa_recover(
19371922
&mut self,
19381923
memory: &mut M,
@@ -1963,7 +1948,6 @@ pub mod env {
19631948

19641949
/// Verify a sr25519 signature
19651950
/// See [`pallet_revive_uapi::HostFn::sr25519_verify`].
1966-
#[stable]
19671951
fn sr25519_verify(
19681952
&mut self,
19691953
memory: &mut M,
@@ -2004,7 +1988,6 @@ pub mod env {
20041988

20051989
/// Calculates Ethereum address from the ECDSA compressed public key and stores
20061990
/// See [`pallet_revive_uapi::HostFn::ecdsa_to_eth_address`].
2007-
#[stable]
20081991
fn ecdsa_to_eth_address(
20091992
&mut self,
20101993
memory: &mut M,
@@ -2026,7 +2009,6 @@ pub mod env {
20262009

20272010
/// Adds a new delegate dependency to the contract.
20282011
/// See [`pallet_revive_uapi::HostFn::lock_delegate_dependency`].
2029-
#[stable]
20302012
#[mutating]
20312013
fn lock_delegate_dependency(
20322014
&mut self,
@@ -2041,7 +2023,6 @@ pub mod env {
20412023

20422024
/// Removes the delegate dependency from the contract.
20432025
/// see [`pallet_revive_uapi::HostFn::unlock_delegate_dependency`].
2044-
#[stable]
20452026
#[mutating]
20462027
fn unlock_delegate_dependency(
20472028
&mut self,

0 commit comments

Comments
 (0)