Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet-revive: disable host functions not in revive recompiler #6844

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions prdoc/pr_6844.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: 'pallet-revive: disable host functions unused in solidity PolkaVM compiler'
doc:
- audience: Runtime Dev
description: Disables host functions in contracts that are not enabled
in solidity PolkaVM compiler to reduce surface of possible attack vectors.
crates:
- name: pallet-revive
bump: major
19 changes: 0 additions & 19 deletions substrate/frame/revive/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,6 @@ pub mod env {

/// Clear the value at the given key in the contract storage.
/// See [`pallet_revive_uapi::HostFn::clear_storage`]
#[stable]
#[mutating]
fn clear_storage(
&mut self,
Expand Down Expand Up @@ -1174,7 +1173,6 @@ pub mod env {

/// Checks whether there is a value stored under the given key.
/// See [`pallet_revive_uapi::HostFn::contains_storage`]
#[stable]
fn contains_storage(
&mut self,
memory: &mut M,
Expand All @@ -1187,7 +1185,6 @@ pub mod env {

/// Retrieve and remove the value under the given key from storage.
/// See [`pallet_revive_uapi::HostFn::take_storage`]
#[stable]
#[mutating]
fn take_storage(
&mut self,
Expand Down Expand Up @@ -1298,7 +1295,6 @@ pub mod env {

/// Remove the calling account and transfer remaining **free** balance.
/// See [`pallet_revive_uapi::HostFn::terminate`].
#[stable]
#[mutating]
fn terminate(&mut self, memory: &mut M, beneficiary_ptr: u32) -> Result<(), TrapReason> {
self.terminate(memory, beneficiary_ptr)
Expand Down Expand Up @@ -1365,7 +1361,6 @@ pub mod env {

/// Checks whether a specified address belongs to a contract.
/// See [`pallet_revive_uapi::HostFn::is_contract`].
#[stable]
fn is_contract(&mut self, memory: &mut M, account_ptr: u32) -> Result<u32, TrapReason> {
self.charge_gas(RuntimeCosts::IsContract)?;
let address = memory.read_h160(account_ptr)?;
Expand Down Expand Up @@ -1404,7 +1399,6 @@ pub mod env {

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

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

/// Checks whether the caller of the current contract is root.
/// See [`pallet_revive_uapi::HostFn::caller_is_root`].
#[stable]
fn caller_is_root(&mut self, _memory: &mut M) -> Result<u32, TrapReason> {
self.charge_gas(RuntimeCosts::CallerIsRoot)?;
Ok(self.ext.caller_is_root() as u32)
Expand Down Expand Up @@ -1471,7 +1463,6 @@ pub mod env {

/// Stores the amount of weight left into the supplied buffer.
/// See [`pallet_revive_uapi::HostFn::weight_left`].
#[stable]
fn weight_left(
&mut self,
memory: &mut M,
Expand Down Expand Up @@ -1597,7 +1588,6 @@ pub mod env {

/// Stores the minimum balance (a.k.a. existential deposit) into the supplied buffer.
/// See [`pallet_revive_uapi::HostFn::minimum_balance`].
#[stable]
fn minimum_balance(&mut self, memory: &mut M, out_ptr: u32) -> Result<(), TrapReason> {
self.charge_gas(RuntimeCosts::MinimumBalance)?;
Ok(self.write_fixed_sandbox_output(
Expand Down Expand Up @@ -1686,7 +1676,6 @@ pub mod env {

/// Computes the SHA2 256-bit hash on the given input buffer.
/// See [`pallet_revive_uapi::HostFn::hash_sha2_256`].
#[stable]
fn hash_sha2_256(
&mut self,
memory: &mut M,
Expand Down Expand Up @@ -1718,7 +1707,6 @@ pub mod env {

/// Computes the BLAKE2 256-bit hash on the given input buffer.
/// See [`pallet_revive_uapi::HostFn::hash_blake2_256`].
#[stable]
fn hash_blake2_256(
&mut self,
memory: &mut M,
Expand All @@ -1734,7 +1722,6 @@ pub mod env {

/// Computes the BLAKE2 128-bit hash on the given input buffer.
/// See [`pallet_revive_uapi::HostFn::hash_blake2_128`].
#[stable]
fn hash_blake2_128(
&mut self,
memory: &mut M,
Expand Down Expand Up @@ -1780,7 +1767,6 @@ pub mod env {

/// Emit a custom debug message.
/// See [`pallet_revive_uapi::HostFn::debug_message`].
#[stable]
fn debug_message(
&mut self,
memory: &mut M,
Expand Down Expand Up @@ -1898,7 +1884,6 @@ pub mod env {

/// Recovers the ECDSA public key from the given message hash and signature.
/// See [`pallet_revive_uapi::HostFn::ecdsa_recover`].
#[stable]
fn ecdsa_recover(
&mut self,
memory: &mut M,
Expand Down Expand Up @@ -1929,7 +1914,6 @@ pub mod env {

/// Verify a sr25519 signature
/// See [`pallet_revive_uapi::HostFn::sr25519_verify`].
#[stable]
fn sr25519_verify(
&mut self,
memory: &mut M,
Expand Down Expand Up @@ -1970,7 +1954,6 @@ pub mod env {

/// Calculates Ethereum address from the ECDSA compressed public key and stores
/// See [`pallet_revive_uapi::HostFn::ecdsa_to_eth_address`].
#[stable]
fn ecdsa_to_eth_address(
&mut self,
memory: &mut M,
Expand All @@ -1992,7 +1975,6 @@ pub mod env {

/// Adds a new delegate dependency to the contract.
/// See [`pallet_revive_uapi::HostFn::lock_delegate_dependency`].
#[stable]
#[mutating]
fn lock_delegate_dependency(
&mut self,
Expand All @@ -2007,7 +1989,6 @@ pub mod env {

/// Removes the delegate dependency from the contract.
/// see [`pallet_revive_uapi::HostFn::unlock_delegate_dependency`].
#[stable]
#[mutating]
fn unlock_delegate_dependency(
&mut self,
Expand Down
Loading