Add PVM heap-size and stack-size configuration parameters for resolc (#226)

* Update revive compiler dependencies

* Inject polkavm settings into resolc standard JSON input

* Add PVM heap-size and stack-size configuration for resolc
This commit is contained in:
Marian Radu
2026-01-19 12:05:37 +02:00
committed by GitHub
parent 9d1c71756f
commit 9491263857
4 changed files with 1144 additions and 1102 deletions
Generated
+1065 -1076
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -74,9 +74,9 @@ indexmap = { version = "2.10.0", default-features = false }
itertools = { version = "0.14.0" }
# revive compiler
revive-solc-json-interface = { git = "https://github.com/paritytech/revive", rev = "3389865af7c3ff6f29a586d82157e8bc573c1a8e" }
revive-common = { git = "https://github.com/paritytech/revive", rev = "3389865af7c3ff6f29a586d82157e8bc573c1a8e" }
revive-differential = { git = "https://github.com/paritytech/revive", rev = "3389865af7c3ff6f29a586d82157e8bc573c1a8e" }
revive-solc-json-interface = { version = "0.5.0" }
revive-common = { version = "0.3.0" }
revive-differential = { version = "0.3.0" }
zombienet-sdk = { git = "https://github.com/paritytech/zombienet-sdk.git", rev = "891f6554354ce466abd496366dbf8b4f82141241" }
+65 -23
View File
@@ -12,9 +12,13 @@ use dashmap::DashMap;
use revive_dt_common::types::VersionOrRequirement;
use revive_dt_config::{ResolcConfiguration, SolcConfiguration, WorkingDirectoryConfiguration};
use revive_solc_json_interface::{
SolcStandardJsonInput, SolcStandardJsonInputLanguage, SolcStandardJsonInputSettings,
SolcStandardJsonInputSettingsOptimizer, SolcStandardJsonInputSettingsSelection,
SolcStandardJsonOutput,
PolkaVMDefaultHeapMemorySize, PolkaVMDefaultStackMemorySize, SolcStandardJsonInput,
SolcStandardJsonInputLanguage, SolcStandardJsonInputSettings,
SolcStandardJsonInputSettingsLibraries, SolcStandardJsonInputSettingsMetadata,
SolcStandardJsonInputSettingsOptimizer, SolcStandardJsonInputSettingsPolkaVM,
SolcStandardJsonInputSettingsPolkaVMMemory, SolcStandardJsonInputSettingsSelection,
SolcStandardJsonOutput, standard_json::input::settings::optimizer::Optimizer,
standard_json::input::settings::optimizer::details::Details,
};
use tracing::{Span, field::display};
@@ -25,6 +29,7 @@ use crate::{
use alloy::json_abi::JsonAbi;
use anyhow::{Context as _, Result};
use semver::Version;
use std::collections::BTreeSet;
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
/// A wrapper around the `resolc` binary, emitting PVM-compatible bytecode.
@@ -37,6 +42,10 @@ struct ResolcInner {
solc: Solc,
/// Path to the `resolc` executable
resolc_path: PathBuf,
/// The PVM heap size in bytes.
pvm_heap_size: u32,
/// The PVM stack size in bytes.
pvm_stack_size: u32,
}
impl Resolc {
@@ -63,10 +72,35 @@ impl Resolc {
Self(Arc::new(ResolcInner {
solc,
resolc_path: resolc_configuration.path.clone(),
pvm_heap_size: resolc_configuration
.heap_size
.unwrap_or(PolkaVMDefaultHeapMemorySize),
pvm_stack_size: resolc_configuration
.stack_size
.unwrap_or(PolkaVMDefaultStackMemorySize),
}))
})
.clone())
}
fn polkavm_settings(&self) -> SolcStandardJsonInputSettingsPolkaVM {
SolcStandardJsonInputSettingsPolkaVM::new(
Some(SolcStandardJsonInputSettingsPolkaVMMemory::new(
Some(self.0.pvm_heap_size),
Some(self.0.pvm_stack_size),
)),
false,
)
}
fn inject_polkavm_settings(&self, input: &SolcStandardJsonInput) -> Result<serde_json::Value> {
let mut input_value = serde_json::to_value(input)
.context("Failed to serialize Standard JSON input for resolc")?;
if let Some(settings) = input_value.get_mut("settings") {
settings["polkavm"] = serde_json::to_value(self.polkavm_settings()).unwrap();
}
Ok(input_value)
}
}
impl SolidityCompiler for Resolc {
@@ -121,8 +155,8 @@ impl SolidityCompiler for Resolc {
.collect(),
settings: SolcStandardJsonInputSettings {
evm_version,
libraries: Some(
libraries
libraries: SolcStandardJsonInputSettingsLibraries {
inner: libraries
.into_iter()
.map(|(source_code, libraries_map)| {
(
@@ -136,23 +170,29 @@ impl SolidityCompiler for Resolc {
)
})
.collect(),
),
remappings: None,
output_selection: Some(SolcStandardJsonInputSettingsSelection::new_required()),
},
remappings: BTreeSet::<String>::new(),
output_selection: SolcStandardJsonInputSettingsSelection::new_required(),
via_ir: Some(true),
optimizer: SolcStandardJsonInputSettingsOptimizer::new(
optimization
.unwrap_or(ModeOptimizerSetting::M0)
.optimizations_enabled(),
None,
&Version::new(0, 0, 0),
false,
Optimizer::default_mode(),
Details::disabled(&Version::new(0, 0, 0)),
),
metadata: None,
polkavm: None,
polkavm: self.polkavm_settings(),
metadata: SolcStandardJsonInputSettingsMetadata::default(),
detect_missing_libraries: false,
},
};
Span::current().record("json_in", display(serde_json::to_string(&input).unwrap()));
// Manually inject polkavm settings since it's marked skip_serializing in the upstream crate
let std_input_json = self.inject_polkavm_settings(&input)?;
Span::current().record(
"json_in",
display(serde_json::to_string(&std_input_json).unwrap()),
);
let path = &self.0.resolc_path;
let mut command = AsyncCommand::new(path);
@@ -181,8 +221,9 @@ impl SolidityCompiler for Resolc {
.with_context(|| format!("Failed to spawn resolc at {}", path.display()))?;
let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped");
let serialized_input = serde_json::to_vec(&input)
let serialized_input = serde_json::to_vec(&std_input_json)
.context("Failed to serialize Standard JSON input for resolc")?;
stdin_pipe
.write_all(&serialized_input)
.await
@@ -228,7 +269,7 @@ impl SolidityCompiler for Resolc {
// Detecting if the compiler output contained errors and reporting them through logs and
// errors instead of returning the compiler output that might contain errors.
for error in parsed.errors.iter().flatten() {
for error in parsed.errors.iter() {
if error.severity == "error" {
tracing::error!(
?error,
@@ -240,12 +281,12 @@ impl SolidityCompiler for Resolc {
}
}
let Some(contracts) = parsed.contracts else {
if parsed.contracts.is_empty() {
anyhow::bail!("Unexpected error - resolc output doesn't have a contracts section");
};
}
let mut compiler_output = CompilerOutput::default();
for (source_path, contracts) in contracts.into_iter() {
for (source_path, contracts) in parsed.contracts.into_iter() {
let src_for_msg = source_path.clone();
let source_path = PathBuf::from(source_path)
.canonicalize()
@@ -258,10 +299,11 @@ impl SolidityCompiler for Resolc {
.and_then(|evm| evm.bytecode.clone())
.context("Unexpected - Contract compiled with resolc has no bytecode")?;
let abi = {
let metadata = contract_information
.metadata
.as_ref()
.context("No metadata found for the contract")?;
let metadata = &contract_information.metadata;
if metadata.is_null() {
anyhow::bail!("No metadata found for the contract");
}
let solc_metadata_str = match metadata {
serde_json::Value::String(solc_metadata_str) => {
solc_metadata_str.as_str()
+11
View File
@@ -800,6 +800,17 @@ pub struct ResolcConfiguration {
/// provided in the user's $PATH.
#[clap(id = "resolc.path", long = "resolc.path", default_value = "resolc")]
pub path: PathBuf,
/// Specifies the PVM heap size in bytes.
///
/// If unspecified, the revive compiler default is used
#[clap(id = "resolc.heap-size", long = "resolc.heap-size")]
pub heap_size: Option<u32>,
/// Specifies the PVM stack size in bytes.
///
/// If unspecified, the revive compiler default is used
#[clap(id = "resolc.stack-size", long = "resolc.stack-size")]
pub stack_size: Option<u32>,
}
/// A set of configuration parameters for Polkadot Parachain.