From b44dc3a5284d6882defb88903f048e0570181642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= <alex.theissen@me.com> Date: Fri, 14 Feb 2025 08:55:23 +0100 Subject: [PATCH] pallet-revive: Add env var to allow skipping of validation for testing (#7562) When trying to reproduce bugs we sometimes need to deploy code that wouldn't pass validation. This PR adds a new environment variable `REVIVE_SKIP_VALIDATION` that when set will skip all validation except the contract blob size limit. Please note that this only applies to when the pallet is compiled for `std` and hence will never be part of on-chain. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- prdoc/pr_7562.prdoc | 10 ++++++++++ substrate/frame/revive/src/limits.rs | 6 ++++++ substrate/frame/revive/src/wasm/mod.rs | 1 + 3 files changed, 17 insertions(+) create mode 100644 prdoc/pr_7562.prdoc diff --git a/prdoc/pr_7562.prdoc b/prdoc/pr_7562.prdoc new file mode 100644 index 00000000000..fa0ed68c1e9 --- /dev/null +++ b/prdoc/pr_7562.prdoc @@ -0,0 +1,10 @@ +title: 'pallet-revive: Add env var to allow skipping of validation for testing' +doc: +- audience: Runtime Dev + description: |- + When trying to reproduce bugs we sometimes need to deploy code that wouldn't pass validation. This PR adds a new environment variable `REVIVE_SKIP_VALIDATION` that when set will skip all validation except the contract blob size limit. + + Please note that this only applies to when the pallet is compiled for `std` and hence will never be part of on-chain. +crates: +- name: pallet-revive + bump: patch diff --git a/substrate/frame/revive/src/limits.rs b/substrate/frame/revive/src/limits.rs index a4060cf6cc9..96f8131a723 100644 --- a/substrate/frame/revive/src/limits.rs +++ b/substrate/frame/revive/src/limits.rs @@ -119,6 +119,12 @@ pub mod code { let blob: CodeVec = blob.try_into().map_err(|_| <Error<T>>::BlobTooLarge)?; + #[cfg(feature = "std")] + if std::env::var_os("REVIVE_SKIP_VALIDATION").is_some() { + log::warn!(target: LOG_TARGET, "Skipping validation because env var REVIVE_SKIP_VALIDATION is set"); + return Ok(blob) + } + let program = polkavm::ProgramBlob::parse(blob.as_slice().into()).map_err(|err| { log::debug!(target: LOG_TARGET, "failed to parse polkavm blob: {err:?}"); Error::<T>::CodeRejected diff --git a/substrate/frame/revive/src/wasm/mod.rs b/substrate/frame/revive/src/wasm/mod.rs index 30418cf84b2..34244735201 100644 --- a/substrate/frame/revive/src/wasm/mod.rs +++ b/substrate/frame/revive/src/wasm/mod.rs @@ -312,6 +312,7 @@ impl<T: Config> WasmBlob<T> { config.set_cache_enabled(false); #[cfg(feature = "std")] if std::env::var_os("REVIVE_USE_COMPILER").is_some() { + log::warn!(target: LOG_TARGET, "Using PolkaVM compiler backend because env var REVIVE_USE_COMPILER is set"); config.set_backend(Some(polkavm::BackendKind::Compiler)); } let engine = polkavm::Engine::new(&config).expect( -- GitLab