diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index 2c06df5a5092..b5866e0ce414 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -73,7 +73,7 @@ jobs: - name: install parity-publish # Set the target dir to cache the build. - run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.8.0 -q + run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.8.0 --locked -q - name: check semver run: | diff --git a/.github/workflows/cmd.yml b/.github/workflows/cmd.yml index 645b5444aa0f..5498beb50ccb 100644 --- a/.github/workflows/cmd.yml +++ b/.github/workflows/cmd.yml @@ -146,8 +146,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - name: Get command uses: actions-ecosystem/action-regex-match@v2 @@ -333,7 +331,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.head.sha }} + repository: ${{ needs.get-pr-branch.outputs.repo }} + ref: ${{ needs.get-pr-branch.outputs.pr-branch }} - name: Install dependencies for bench if: startsWith(steps.get-pr-comment.outputs.group2, 'bench') @@ -360,10 +359,12 @@ jobs: git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git pull --rebase origin ${{ needs.get-pr-branch.outputs.pr-branch }} git add . git restore --staged Cargo.lock # ignore changes in Cargo.lock git commit -m "Update from ${{ github.actor }} running command '${{ steps.get-pr-comment.outputs.group2 }}'" || true + + git pull --rebase origin ${{ needs.get-pr-branch.outputs.pr-branch }} + git push origin ${{ needs.get-pr-branch.outputs.pr-branch }} else echo "Nothing to commit"; diff --git a/.github/workflows/publish-check-crates.yml b/.github/workflows/publish-check-crates.yml index cffa9a230c47..a5af04118572 100644 --- a/.github/workflows/publish-check-crates.yml +++ b/.github/workflows/publish-check-crates.yml @@ -24,7 +24,7 @@ jobs: cache-on-failure: true - name: install parity-publish - run: cargo install parity-publish@0.8.0 + run: cargo install parity-publish@0.8.0 --locked -q - name: parity-publish check run: parity-publish --color always check --allow-unpublished diff --git a/.github/workflows/publish-claim-crates.yml b/.github/workflows/publish-claim-crates.yml index 77f04861bfff..f9bc6ce4daea 100644 --- a/.github/workflows/publish-claim-crates.yml +++ b/.github/workflows/publish-claim-crates.yml @@ -18,7 +18,7 @@ jobs: cache-on-failure: true - name: install parity-publish - run: cargo install parity-publish@0.8.0 + run: cargo install parity-publish@0.8.0 --locked -q - name: parity-publish claim env: diff --git a/Cargo.lock b/Cargo.lock index 8abecaf5e9ba..35dc61928178 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10363,7 +10363,6 @@ dependencies = [ "anyhow", "frame-system", "parity-wasm", - "polkavm-linker 0.9.2", "sp-runtime", "tempfile", "toml 0.8.12", @@ -10423,7 +10422,6 @@ dependencies = [ "bitflags 1.3.2", "parity-scale-codec", "paste", - "polkavm-derive 0.9.1", "scale-info", ] diff --git a/prdoc/pr_5665.prdoc b/prdoc/pr_5665.prdoc new file mode 100644 index 000000000000..2b2f0547dc01 --- /dev/null +++ b/prdoc/pr_5665.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "[pallet-contracts] remove riscv support" + +doc: + - audience: Runtime Dev + description: | + RISC-V support is now being built inside the new fork pallet-revive + +crates: + - name: pallet-contracts + bump: patch + - name: pallet-contracts-fixtures + bump: patch + - name: pallet-contracts-uapi + bump: patch diff --git a/substrate/frame/contracts/fixtures/Cargo.toml b/substrate/frame/contracts/fixtures/Cargo.toml index 6cb6447d8fd7..4c01c1f061b7 100644 --- a/substrate/frame/contracts/fixtures/Cargo.toml +++ b/substrate/frame/contracts/fixtures/Cargo.toml @@ -20,8 +20,4 @@ parity-wasm = { workspace = true } tempfile = { workspace = true } toml = { workspace = true } twox-hash = { workspace = true, default-features = true } -polkavm-linker = { workspace = true, optional = true } anyhow = { workspace = true, default-features = true } - -[features] -riscv = ["polkavm-linker"] diff --git a/substrate/frame/contracts/fixtures/build.rs b/substrate/frame/contracts/fixtures/build.rs index baaeaf034203..7af733c536d0 100644 --- a/substrate/frame/contracts/fixtures/build.rs +++ b/substrate/frame/contracts/fixtures/build.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Compile contracts to wasm and RISC-V binaries. +//! Compile contracts to wasm. use anyhow::{bail, Context, Result}; use parity_wasm::elements::{deserialize_file, serialize_to_file, Internal}; use std::{ @@ -89,12 +89,6 @@ impl Entry { fn out_wasm_filename(&self) -> String { format!("{}.wasm", self.name()) } - - /// Return the name of the RISC-V polkavm file. - #[cfg(feature = "riscv")] - fn out_riscv_filename(&self) -> String { - format!("{}.polkavm", self.name()) - } } /// Collect all contract entries from the given source directory. @@ -236,53 +230,6 @@ fn post_process_wasm(input_path: &Path, output_path: &Path) -> Result<()> { serialize_to_file(output_path, module).map_err(Into::into) } -/// Build contracts for RISC-V. -#[cfg(feature = "riscv")] -fn invoke_riscv_build(current_dir: &Path) -> Result<()> { - let encoded_rustflags = [ - "-Crelocation-model=pie", - "-Clink-arg=--emit-relocs", - "-Clink-arg=--export-dynamic-symbol=__polkavm_symbol_export_hack__*", - ] - .join("\x1f"); - - let build_res = Command::new(env::var("CARGO")?) - .current_dir(current_dir) - .env_clear() - .env("PATH", env::var("PATH").unwrap_or_default()) - .env("CARGO_ENCODED_RUSTFLAGS", encoded_rustflags) - .env("RUSTUP_TOOLCHAIN", "rve-nightly") - .env("RUSTUP_HOME", env::var("RUSTUP_HOME").unwrap_or_default()) - .args(["build", "--release", "--target=riscv32ema-unknown-none-elf"]) - .output() - .expect("failed to execute process"); - - if build_res.status.success() { - return Ok(()) - } - - let stderr = String::from_utf8_lossy(&build_res.stderr); - - if stderr.contains("'rve-nightly' is not installed") { - eprintln!("RISC-V toolchain is not installed.\nDownload and install toolchain from https://github.com/paritytech/rustc-rv32e-toolchain."); - eprintln!("{}", stderr); - } else { - eprintln!("{}", stderr); - } - - bail!("Failed to build contracts"); -} -/// Post-process the compiled wasm contracts. -#[cfg(feature = "riscv")] -fn post_process_riscv(input_path: &Path, output_path: &Path) -> Result<()> { - let mut config = polkavm_linker::Config::default(); - config.set_strip(true); - let orig = fs::read(input_path).with_context(|| format!("Failed to read {:?}", input_path))?; - let linked = polkavm_linker::program_from_elf(config, orig.as_ref()) - .map_err(|err| anyhow::format_err!("Failed to link polkavm program: {}", err))?; - fs::write(output_path, linked.as_bytes()).map_err(Into::into) -} - /// Write the compiled contracts to the given output directory. fn write_output(build_dir: &Path, out_dir: &Path, entries: Vec) -> Result<()> { for entry in entries { @@ -292,12 +239,6 @@ fn write_output(build_dir: &Path, out_dir: &Path, entries: Vec) -> Result &out_dir.join(&wasm_output), )?; - #[cfg(feature = "riscv")] - post_process_riscv( - &build_dir.join("target/riscv32ema-unknown-none-elf/release").join(entry.name()), - &out_dir.join(entry.out_riscv_filename()), - )?; - entry.update_cache(out_dir)?; } @@ -347,9 +288,6 @@ fn main() -> Result<()> { invoke_wasm_build(tmp_dir_path)?; - #[cfg(feature = "riscv")] - invoke_riscv_build(tmp_dir_path)?; - write_output(tmp_dir_path, &out_dir, entries)?; Ok(()) } diff --git a/substrate/frame/contracts/fixtures/contracts/common/src/lib.rs b/substrate/frame/contracts/fixtures/contracts/common/src/lib.rs index 80e1f543a7b5..504fa7f9e81d 100644 --- a/substrate/frame/contracts/fixtures/contracts/common/src/lib.rs +++ b/substrate/frame/contracts/fixtures/contracts/common/src/lib.rs @@ -22,13 +22,6 @@ pub use uapi::{HostFn, HostFnImpl as api}; fn panic(_info: &core::panic::PanicInfo) -> ! { #[cfg(target_arch = "wasm32")] core::arch::wasm32::unreachable(); - - #[cfg(target_arch = "riscv32")] - // Safety: The unimp instruction is guaranteed to trap - unsafe { - core::arch::asm!("unimp"); - core::hint::unreachable_unchecked(); - } } /// Utility macro to read input passed to a contract. diff --git a/substrate/frame/contracts/fixtures/src/lib.rs b/substrate/frame/contracts/fixtures/src/lib.rs index 56a8e2321c5c..f9272a32ad61 100644 --- a/substrate/frame/contracts/fixtures/src/lib.rs +++ b/substrate/frame/contracts/fixtures/src/lib.rs @@ -39,7 +39,5 @@ mod test { fn out_dir_should_have_compiled_mocks() { let out_dir: std::path::PathBuf = env!("OUT_DIR").into(); assert!(out_dir.join("dummy.wasm").exists()); - #[cfg(feature = "riscv")] - assert!(out_dir.join("dummy.polkavm").exists()); } } diff --git a/substrate/frame/contracts/uapi/Cargo.toml b/substrate/frame/contracts/uapi/Cargo.toml index ccd86ba7890c..09c70c287899 100644 --- a/substrate/frame/contracts/uapi/Cargo.toml +++ b/substrate/frame/contracts/uapi/Cargo.toml @@ -20,9 +20,6 @@ codec = { features = [ "max-encoded-len", ], optional = true, workspace = true } -[target.'cfg(target_arch = "riscv32")'.dependencies] -polkavm-derive = { workspace = true } - [package.metadata.docs.rs] default-target = ["wasm32-unknown-unknown"] diff --git a/substrate/frame/contracts/uapi/src/host.rs b/substrate/frame/contracts/uapi/src/host.rs index 51f0cd7eb2dc..52c9ea387e1c 100644 --- a/substrate/frame/contracts/uapi/src/host.rs +++ b/substrate/frame/contracts/uapi/src/host.rs @@ -17,9 +17,6 @@ use paste::paste; #[cfg(target_arch = "wasm32")] mod wasm32; -#[cfg(target_arch = "riscv32")] -mod riscv32; - macro_rules! hash_fn { ( $name:ident, $bytes:literal ) => { paste! { @@ -66,7 +63,7 @@ fn ptr_or_sentinel(data: &Option<&[u8]>) -> *const u8 { /// Implements [`HostFn`] for each supported target architecture. pub enum HostFnImpl {} -/// Defines all the host apis implemented by both wasm and RISC-V vms. +/// Defines all the host apis implemented by the wasm vm. pub trait HostFn: private::Sealed { /// Returns the number of times specified contract exists on the call stack. Delegated calls are /// not counted as separate calls. diff --git a/substrate/frame/contracts/uapi/src/host/riscv32.rs b/substrate/frame/contracts/uapi/src/host/riscv32.rs deleted file mode 100644 index 355520233212..000000000000 --- a/substrate/frame/contracts/uapi/src/host/riscv32.rs +++ /dev/null @@ -1,327 +0,0 @@ -#![allow(unused_variables, unused_mut)] -// Copyright (C) Parity Technologies (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// TODO: bring up to date with wasm32.rs - -use super::{CallFlags, HostFn, HostFnImpl, Result}; -use crate::ReturnFlags; - -/// A macro to implement all Host functions with a signature of `fn(&mut &mut [u8])`. -/// -/// Example: -/// ```nocompile -// impl_wrapper_for! { -// () => [gas_left], -// (v1) => [gas_left], -// } -// ``` -// -// Expands to: -// ```nocompile -// fn gas_left(output: &mut &mut [u8]) { -// unsafe { sys::gas_left(...); } -// } -// fn gas_left_v1(output: &mut &mut [u8]) { -// unsafe { sys::v1::gas_left(...); } -// } -// ``` -macro_rules! impl_wrapper_for { - (@impl_fn $( $mod:ident )::*, $suffix_sep: literal, $suffix:tt, $name:ident) => { - paste::paste! { - fn [<$name $suffix_sep $suffix>](output: &mut &mut [u8]) { - todo!() - } - } - }; - - () => {}; - - (($mod:ident) => [$( $name:ident),*], $($tail:tt)*) => { - $(impl_wrapper_for!(@impl_fn sys::$mod, "_", $mod, $name);)* - impl_wrapper_for!($($tail)*); - }; - - (() => [$( $name:ident),*], $($tail:tt)*) => { - $(impl_wrapper_for!(@impl_fn sys, "", "", $name);)* - impl_wrapper_for!($($tail)*); - }; -} - -/// A macro to implement all the hash functions Apis. -macro_rules! impl_hash_fn { - ( $name:ident, $bytes_result:literal ) => { - paste::item! { - fn [](input: &[u8], output: &mut [u8; $bytes_result]) { - todo!() - } - } - }; -} - -/// A macro to implement the get_storage functions. -macro_rules! impl_get_storage { - ($fn_name:ident, $sys_get_storage:path) => { - fn $fn_name(key: &[u8], output: &mut &mut [u8]) -> Result { - todo!() - } - }; -} - -impl HostFn for HostFnImpl { - fn instantiate_v1( - code_hash: &[u8], - gas: u64, - value: &[u8], - input: &[u8], - mut address: Option<&mut &mut [u8]>, - mut output: Option<&mut &mut [u8]>, - salt: &[u8], - ) -> Result { - todo!() - } - - fn instantiate_v2( - code_hash: &[u8], - ref_time_limit: u64, - proof_size_limit: u64, - deposit: Option<&[u8]>, - value: &[u8], - input: &[u8], - mut address: Option<&mut &mut [u8]>, - mut output: Option<&mut &mut [u8]>, - salt: &[u8], - ) -> Result { - todo!() - } - - fn call( - callee: &[u8], - gas: u64, - value: &[u8], - input_data: &[u8], - mut output: Option<&mut &mut [u8]>, - ) -> Result { - todo!() - } - - fn call_v1( - flags: CallFlags, - callee: &[u8], - gas: u64, - value: &[u8], - input_data: &[u8], - mut output: Option<&mut &mut [u8]>, - ) -> Result { - todo!() - } - - fn call_v2( - flags: CallFlags, - callee: &[u8], - ref_time_limit: u64, - proof_size_limit: u64, - deposit: Option<&[u8]>, - value: &[u8], - input_data: &[u8], - mut output: Option<&mut &mut [u8]>, - ) -> Result { - todo!() - } - - fn caller_is_root() -> u32 { - todo!() - } - - fn delegate_call( - flags: CallFlags, - code_hash: &[u8], - input: &[u8], - mut output: Option<&mut &mut [u8]>, - ) -> Result { - todo!() - } - - fn transfer(account_id: &[u8], value: &[u8]) -> Result { - todo!() - } - - fn deposit_event(topics: &[u8], data: &[u8]) { - todo!() - } - - fn set_storage(key: &[u8], value: &[u8]) { - todo!() - } - - fn set_storage_v1(key: &[u8], encoded_value: &[u8]) -> Option { - todo!() - } - - fn set_storage_v2(key: &[u8], encoded_value: &[u8]) -> Option { - todo!() - } - - fn set_transient_storage(key: &[u8], encoded_value: &[u8]) -> Option { - todo!() - } - - fn clear_storage(key: &[u8]) { - todo!() - } - - fn clear_storage_v1(key: &[u8]) -> Option { - todo!() - } - - fn clear_transient_storage(key: &[u8]) -> Option { - todo!() - } - - impl_get_storage!(get_storage, sys::get_storage); - impl_get_storage!(get_storage_v1, sys::v1::get_storage); - - fn get_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result { - todo!() - } - - fn take_storage(key: &[u8], output: &mut &mut [u8]) -> Result { - todo!() - } - - fn take_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result { - todo!() - } - - fn contains_storage(key: &[u8]) -> Option { - todo!() - } - - fn contains_storage_v1(key: &[u8]) -> Option { - todo!() - } - - fn contains_transient_storage(key: &[u8]) -> Option { - todo!() - } - - fn terminate(beneficiary: &[u8]) -> ! { - todo!() - } - - fn terminate_v1(beneficiary: &[u8]) -> ! { - todo!() - } - - fn call_chain_extension(func_id: u32, input: &[u8], output: Option<&mut &mut [u8]>) -> u32 { - todo!() - } - - fn input(output: &mut &mut [u8]) { - todo!() - } - - fn return_value(flags: ReturnFlags, return_value: &[u8]) -> ! { - todo!() - } - - fn call_runtime(call: &[u8]) -> Result { - todo!() - } - - fn debug_message(str: &[u8]) -> Result { - todo!() - } - - impl_wrapper_for! { - () => [caller, block_number, address, balance, gas_left, value_transferred, now, minimum_balance], - (v1) => [gas_left], - } - - fn weight_to_fee(gas: u64, output: &mut &mut [u8]) { - todo!() - } - - fn weight_to_fee_v1(ref_time_limit: u64, proof_size_limit: u64, output: &mut &mut [u8]) { - todo!() - } - - impl_hash_fn!(sha2_256, 32); - impl_hash_fn!(keccak_256, 32); - impl_hash_fn!(blake2_256, 32); - impl_hash_fn!(blake2_128, 16); - - fn ecdsa_recover( - signature: &[u8; 65], - message_hash: &[u8; 32], - output: &mut [u8; 33], - ) -> Result { - todo!() - } - - fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result { - todo!() - } - - fn sr25519_verify(signature: &[u8; 64], message: &[u8], pub_key: &[u8; 32]) -> Result { - todo!() - } - - fn is_contract(account_id: &[u8]) -> bool { - todo!() - } - - fn caller_is_origin() -> bool { - todo!() - } - - fn set_code_hash(code_hash: &[u8]) -> Result { - todo!() - } - - fn code_hash(account_id: &[u8], output: &mut [u8]) -> Result { - todo!() - } - - fn own_code_hash(output: &mut [u8]) { - todo!() - } - - fn account_reentrance_count(account: &[u8]) -> u32 { - todo!() - } - - fn lock_delegate_dependency(code_hash: &[u8]) { - todo!() - } - - fn unlock_delegate_dependency(code_hash: &[u8]) { - todo!() - } - - fn instantiation_nonce() -> u64 { - todo!() - } - - fn reentrance_count() -> u32 { - todo!() - } - - fn xcm_execute(msg: &[u8]) -> Result { - todo!() - } - - fn xcm_send(dest: &[u8], msg: &[u8], output: &mut [u8; 32]) -> Result { - todo!() - } -} diff --git a/substrate/frame/contracts/uapi/src/lib.rs b/substrate/frame/contracts/uapi/src/lib.rs index 83877c6efd40..7e30c811ee07 100644 --- a/substrate/frame/contracts/uapi/src/lib.rs +++ b/substrate/frame/contracts/uapi/src/lib.rs @@ -21,10 +21,10 @@ mod flags; pub use flags::*; -#[cfg(any(target_arch = "wasm32", target_arch = "riscv32"))] +#[cfg(target_arch = "wasm32")] mod host; -#[cfg(any(target_arch = "wasm32", target_arch = "riscv32"))] +#[cfg(target_arch = "wasm32")] pub use host::*; macro_rules! define_error_codes {