From 44192144036cbdeaf61986cd06761b8078661aa0 Mon Sep 17 00:00:00 2001 From: Cyrill Leutwiler Date: Fri, 11 Oct 2024 15:18:47 +0200 Subject: [PATCH 1/3] remove system mode and request memoization Signed-off-by: Cyrill Leutwiler --- .../src/optimizer/settings/mod.rs | 14 ----- .../src/polkavm/context/function/mod.rs | 6 -- .../context/function/runtime/deploy_code.rs | 3 +- .../polkavm/context/function/runtime/entry.rs | 2 +- .../context/function/runtime/runtime_code.rs | 3 +- .../llvm-context/src/polkavm/context/mod.rs | 59 +------------------ .../src/polkavm/context/yul_data.rs | 16 ----- crates/llvm-context/src/polkavm/mod.rs | 2 - .../src/evmla/ethereal_ir/function/mod.rs | 2 - crates/solidity/src/lib.rs | 48 +++------------ crates/solidity/src/process/input.rs | 4 -- crates/solidity/src/process/mod.rs | 1 - crates/solidity/src/project/contract/mod.rs | 4 +- crates/solidity/src/project/mod.rs | 4 -- crates/solidity/src/resolc/arguments.rs | 22 ------- crates/solidity/src/resolc/main.rs | 8 --- .../input/settings/optimizer/mod.rs | 8 --- crates/solidity/src/test_utils.rs | 22 ++----- .../statement/expression/function_call/mod.rs | 2 +- .../parser/statement/function_definition.rs | 8 +-- 20 files changed, 20 insertions(+), 218 deletions(-) diff --git a/crates/llvm-context/src/optimizer/settings/mod.rs b/crates/llvm-context/src/optimizer/settings/mod.rs index 8d8df1ba..ac312ffa 100644 --- a/crates/llvm-context/src/optimizer/settings/mod.rs +++ b/crates/llvm-context/src/optimizer/settings/mod.rs @@ -21,8 +21,6 @@ pub struct Settings { /// Fallback to optimizing for size if the bytecode is too large. pub is_fallback_to_size_enabled: bool, - /// Whether the system request memoization is disabled. - pub is_system_request_memoization_disabled: bool, /// Whether the LLVM `verify each` option is enabled. pub is_verify_each_enabled: bool, @@ -43,7 +41,6 @@ impl Settings { level_back_end, is_fallback_to_size_enabled: false, - is_system_request_memoization_disabled: false, is_verify_each_enabled: false, is_debug_logging_enabled: false, @@ -65,7 +62,6 @@ impl Settings { level_back_end, is_fallback_to_size_enabled: false, - is_system_request_memoization_disabled: false, is_verify_each_enabled, is_debug_logging_enabled, @@ -206,20 +202,10 @@ impl Settings { self.is_fallback_to_size_enabled = true; } - /// Disables the system request memoization. - pub fn disable_system_request_memoization(&mut self) { - self.is_system_request_memoization_disabled = true; - } - /// Whether the fallback to optimizing for size is enabled. pub fn is_fallback_to_size_enabled(&self) -> bool { self.is_fallback_to_size_enabled } - - /// Whether the system request memoization is disabled. - pub fn is_system_request_memoization_disabled(&self) -> bool { - self.is_system_request_memoization_disabled - } } impl PartialEq for Settings { diff --git a/crates/llvm-context/src/polkavm/context/function/mod.rs b/crates/llvm-context/src/polkavm/context/function/mod.rs index d7091419..5c801b8f 100644 --- a/crates/llvm-context/src/polkavm/context/function/mod.rs +++ b/crates/llvm-context/src/polkavm/context/function/mod.rs @@ -95,12 +95,6 @@ impl<'ctx> Function<'ctx> { && name != self::runtime::FUNCTION_LOAD_IMMUTABLE_DATA) } - /// Checks whether the function is related to the near call ABI. - pub fn is_near_call_abi(name: &str) -> bool { - name.starts_with(Self::ZKSYNC_NEAR_CALL_ABI_PREFIX) - || name == Self::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER - } - /// Returns the LLVM function declaration. pub fn declaration(&self) -> Declaration<'ctx> { self.declaration diff --git a/crates/llvm-context/src/polkavm/context/function/runtime/deploy_code.rs b/crates/llvm-context/src/polkavm/context/function/runtime/deploy_code.rs index 9e6a6272..8649da37 100644 --- a/crates/llvm-context/src/polkavm/context/function/runtime/deploy_code.rs +++ b/crates/llvm-context/src/polkavm/context/function/runtime/deploy_code.rs @@ -42,8 +42,7 @@ where D: Dependency + Clone, { fn declare(&mut self, context: &mut Context) -> anyhow::Result<()> { - let function_type = - context.function_type::(vec![], 0, false); + let function_type = context.function_type::(vec![], 0); context.add_function( runtime::FUNCTION_DEPLOY_CODE, function_type, diff --git a/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs b/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs index f45709e9..5fa3cc47 100644 --- a/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs +++ b/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs @@ -188,7 +188,7 @@ where { fn declare(&mut self, context: &mut Context) -> anyhow::Result<()> { let entry_arguments = vec![context.bool_type().as_basic_type_enum()]; - let entry_function_type = context.function_type(entry_arguments, 0, false); + let entry_function_type = context.function_type(entry_arguments, 0); context.add_function( runtime::FUNCTION_ENTRY, entry_function_type, diff --git a/crates/llvm-context/src/polkavm/context/function/runtime/runtime_code.rs b/crates/llvm-context/src/polkavm/context/function/runtime/runtime_code.rs index 5b9c05d4..439340c5 100644 --- a/crates/llvm-context/src/polkavm/context/function/runtime/runtime_code.rs +++ b/crates/llvm-context/src/polkavm/context/function/runtime/runtime_code.rs @@ -42,8 +42,7 @@ where D: Dependency + Clone, { fn declare(&mut self, context: &mut Context) -> anyhow::Result<()> { - let function_type = - context.function_type::(vec![], 0, false); + let function_type = context.function_type::(vec![], 0); context.add_function( runtime::FUNCTION_RUNTIME_CODE, function_type, diff --git a/crates/llvm-context/src/polkavm/context/mod.rs b/crates/llvm-context/src/polkavm/context/mod.rs index 46795483..0d501ad2 100644 --- a/crates/llvm-context/src/polkavm/context/mod.rs +++ b/crates/llvm-context/src/polkavm/context/mod.rs @@ -413,47 +413,14 @@ where &self.llvm_runtime } - /// Declare a function already existing in the module. - pub fn declare_extern_function( - &mut self, - name: &str, - ) -> anyhow::Result>>> { - let function = self.module().get_function(name).ok_or_else(|| { - anyhow::anyhow!("Failed to activate an undeclared function `{}`", name) - })?; - - let basic_block = self.llvm.append_basic_block(function, name); - let declaration = FunctionDeclaration::new( - self.function_type::(vec![], 0, false), - function, - ); - let function = Function::new( - name.to_owned(), - declaration, - FunctionReturn::None, - basic_block, - basic_block, - ); - Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer); - - let function = Rc::new(RefCell::new(function)); - self.functions.insert(name.to_string(), function.clone()); - - Ok(function) - } - /// Appends a function to the current module. pub fn add_function( &mut self, name: &str, r#type: inkwell::types::FunctionType<'ctx>, return_values_length: usize, - mut linkage: Option, + linkage: Option, ) -> anyhow::Result>>> { - if Function::is_near_call_abi(name) && self.is_system_mode() { - linkage = Some(inkwell::module::Linkage::External); - } - let value = self.module().add_function(name, r#type, linkage); let entry_block = self.llvm.append_basic_block(value, "entry"); @@ -492,10 +459,6 @@ where return_block, ); Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer); - if Function::is_near_call_abi(function.name()) && self.is_system_mode() { - Function::set_exception_handler_attributes(self.llvm, function.declaration()); - } - let function = Rc::new(RefCell::new(function)); self.functions.insert(name.to_string(), function.clone()); @@ -556,10 +519,6 @@ where manager, name, self.optimizer.settings().to_owned(), - self.yul_data - .as_ref() - .map(|data| data.is_system_mode()) - .unwrap_or_default(), self.include_metadata_hash, self.debug_config.clone(), ) @@ -1330,12 +1289,11 @@ where &self, argument_types: Vec, return_values_size: usize, - is_near_call_abi: bool, ) -> inkwell::types::FunctionType<'ctx> where T: BasicType<'ctx>, { - let mut argument_types: Vec = argument_types + let argument_types: Vec = argument_types .as_slice() .iter() .map(T::as_basic_type_enum) @@ -1347,11 +1305,6 @@ where .void_type() .fn_type(argument_types.as_slice(), false), 1 => self.word_type().fn_type(argument_types.as_slice(), false), - _size if is_near_call_abi && self.is_system_mode() => { - let return_type = self.llvm().ptr_type(AddressSpace::Stack.into()); - argument_types.insert(0, return_type.as_basic_type_enum().into()); - return_type.fn_type(argument_types.as_slice(), false) - } size => self .structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice()) .fn_type(argument_types.as_slice(), false), @@ -1544,12 +1497,4 @@ where anyhow::bail!("The immutable size data is not available"); } } - - /// Whether the system mode is enabled. - pub fn is_system_mode(&self) -> bool { - self.yul_data - .as_ref() - .map(|data| data.is_system_mode()) - .unwrap_or_default() - } } diff --git a/crates/llvm-context/src/polkavm/context/yul_data.rs b/crates/llvm-context/src/polkavm/context/yul_data.rs index 41cc13b9..74da6498 100644 --- a/crates/llvm-context/src/polkavm/context/yul_data.rs +++ b/crates/llvm-context/src/polkavm/context/yul_data.rs @@ -8,28 +8,12 @@ use num::Zero; /// Describes some data that is only relevant to Yul. #[derive(Debug, Default)] pub struct YulData { - /// The system mode flag. - /// The call simulations only work if this mode is enabled. - is_system_mode: bool, /// The list of constant arrays in the code section. /// It is a temporary storage used until the finalization method is called. const_arrays: BTreeMap>, } impl YulData { - /// A shortcut constructor. - pub fn new(is_system_mode: bool) -> Self { - Self { - is_system_mode, - const_arrays: BTreeMap::new(), - } - } - - /// Whether the system mode is enabled. - pub fn is_system_mode(&self) -> bool { - self.is_system_mode - } - /// Declares a temporary constant array representation. pub fn const_array_declare(&mut self, index: u8, size: u16) -> anyhow::Result<()> { if self.const_arrays.contains_key(&index) { diff --git a/crates/llvm-context/src/polkavm/mod.rs b/crates/llvm-context/src/polkavm/mod.rs index c5549fb9..5c887133 100644 --- a/crates/llvm-context/src/polkavm/mod.rs +++ b/crates/llvm-context/src/polkavm/mod.rs @@ -97,7 +97,6 @@ pub trait Dependency { dependency: Self, path: &str, optimizer_settings: OptimizerSettings, - is_system_mode: bool, include_metadata_hash: bool, debug_config: Option, ) -> anyhow::Result; @@ -118,7 +117,6 @@ impl Dependency for DummyDependency { _dependency: Self, _path: &str, _optimizer_settings: OptimizerSettings, - _is_system_mode: bool, _include_metadata_hash: bool, _debug_config: Option, ) -> anyhow::Result { diff --git a/crates/solidity/src/evmla/ethereal_ir/function/mod.rs b/crates/solidity/src/evmla/ethereal_ir/function/mod.rs index 28780e9d..52547cd5 100644 --- a/crates/solidity/src/evmla/ethereal_ir/function/mod.rs +++ b/crates/solidity/src/evmla/ethereal_ir/function/mod.rs @@ -1139,7 +1139,6 @@ where .integer_type(revive_common::BIT_LENGTH_BOOLEAN) .as_basic_type_enum()], output_size, - false, ); (r#type, output_size) } @@ -1156,7 +1155,6 @@ where input_size ], output_size, - false, ); (r#type, output_size) } diff --git a/crates/solidity/src/lib.rs b/crates/solidity/src/lib.rs index 3f0a8973..e093816a 100644 --- a/crates/solidity/src/lib.rs +++ b/crates/solidity/src/lib.rs @@ -51,7 +51,6 @@ pub fn yul( input_files: &[PathBuf], solc: &mut SolcCompiler, optimizer_settings: revive_llvm_context::OptimizerSettings, - is_system_mode: bool, include_metadata_hash: bool, debug_config: Option, ) -> anyhow::Result { @@ -64,27 +63,17 @@ pub fn yul( ), }; - let solc_validator = if is_system_mode { - None - } else { - if solc.version()?.default != SolcCompiler::LAST_SUPPORTED_VERSION { - anyhow::bail!( + if solc.version()?.default != SolcCompiler::LAST_SUPPORTED_VERSION { + anyhow::bail!( "The Yul mode is only supported with the most recent version of the Solidity compiler: {}", SolcCompiler::LAST_SUPPORTED_VERSION, ); - } - - Some(&*solc) - }; + } + let solc_validator = Some(&*solc); let project = Project::try_from_yul_path(path, solc_validator)?; - let build = project.compile( - optimizer_settings, - is_system_mode, - include_metadata_hash, - debug_config, - )?; + let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?; Ok(build) } @@ -93,7 +82,6 @@ pub fn yul( pub fn llvm_ir( input_files: &[PathBuf], optimizer_settings: revive_llvm_context::OptimizerSettings, - is_system_mode: bool, include_metadata_hash: bool, debug_config: Option, ) -> anyhow::Result { @@ -108,12 +96,7 @@ pub fn llvm_ir( let project = Project::try_from_llvm_ir_path(path)?; - let build = project.compile( - optimizer_settings, - is_system_mode, - include_metadata_hash, - debug_config, - )?; + let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?; Ok(build) } @@ -128,7 +111,6 @@ pub fn standard_output( solc_optimizer_enabled: bool, optimizer_settings: revive_llvm_context::OptimizerSettings, force_evmla: bool, - is_system_mode: bool, include_metadata_hash: bool, base_path: Option, include_paths: Vec, @@ -152,7 +134,6 @@ pub fn standard_output( None, &solc_version.default, optimizer_settings.is_fallback_to_size_enabled(), - optimizer_settings.is_system_request_memoization_disabled(), ), None, solc_pipeline == SolcPipeline::Yul, @@ -198,12 +179,7 @@ pub fn standard_output( debug_config.as_ref(), )?; - let build = project.compile( - optimizer_settings, - is_system_mode, - include_metadata_hash, - debug_config, - )?; + let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?; Ok(build) } @@ -214,7 +190,6 @@ pub fn standard_json( solc: &mut SolcCompiler, detect_missing_libraries: bool, force_evmla: bool, - is_system_mode: bool, base_path: Option, include_paths: Vec, allow_paths: Option, @@ -275,12 +250,7 @@ pub fn standard_json( &resolc_version, )?; } else { - let build = project.compile( - optimizer_settings, - is_system_mode, - include_metadata_hash, - debug_config, - )?; + let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?; build.write_to_standard_json(&mut solc_output, &solc_version, &resolc_version)?; } serde_json::to_writer(std::io::stdout(), &solc_output)?; @@ -298,7 +268,6 @@ pub fn combined_json( solc_optimizer_enabled: bool, optimizer_settings: revive_llvm_context::OptimizerSettings, force_evmla: bool, - is_system_mode: bool, include_metadata_hash: bool, base_path: Option, include_paths: Vec, @@ -319,7 +288,6 @@ pub fn combined_json( solc_optimizer_enabled, optimizer_settings, force_evmla, - is_system_mode, include_metadata_hash, base_path, include_paths, diff --git a/crates/solidity/src/process/input.rs b/crates/solidity/src/process/input.rs index 9f746d9c..203ea66d 100644 --- a/crates/solidity/src/process/input.rs +++ b/crates/solidity/src/process/input.rs @@ -14,8 +14,6 @@ pub struct Input { pub contract: Contract, /// The project representation. pub project: Project, - /// The system mode flag. - pub is_system_mode: bool, /// Whether to append the metadata hash. pub include_metadata_hash: bool, /// The optimizer settings. @@ -29,7 +27,6 @@ impl Input { pub fn new( contract: Contract, project: Project, - is_system_mode: bool, include_metadata_hash: bool, optimizer_settings: revive_llvm_context::OptimizerSettings, debug_config: Option, @@ -37,7 +34,6 @@ impl Input { Self { contract, project, - is_system_mode, include_metadata_hash, optimizer_settings, debug_config, diff --git a/crates/solidity/src/process/mod.rs b/crates/solidity/src/process/mod.rs index 3f168166..3d882aeb 100644 --- a/crates/solidity/src/process/mod.rs +++ b/crates/solidity/src/process/mod.rs @@ -43,7 +43,6 @@ pub fn run(input_file: Option<&mut std::fs::File>) -> anyhow::Result<()> { let result = input.contract.compile( input.project, input.optimizer_settings, - input.is_system_mode, input.include_metadata_hash, input.debug_config, ); diff --git a/crates/solidity/src/project/contract/mod.rs b/crates/solidity/src/project/contract/mod.rs index c59f98b4..1721484e 100644 --- a/crates/solidity/src/project/contract/mod.rs +++ b/crates/solidity/src/project/contract/mod.rs @@ -78,7 +78,6 @@ impl Contract { mut self, project: Project, optimizer_settings: revive_llvm_context::OptimizerSettings, - is_system_mode: bool, include_metadata_hash: bool, debug_config: Option, ) -> anyhow::Result { @@ -127,8 +126,7 @@ impl Contract { context.set_solidity_data(revive_llvm_context::PolkaVMContextSolidityData::default()); match self.ir { IR::Yul(_) => { - let yul_data = revive_llvm_context::PolkaVMContextYulData::new(is_system_mode); - context.set_yul_data(yul_data); + context.set_yul_data(Default::default()); } IR::EVMLA(_) => { let evmla_data = revive_llvm_context::PolkaVMContextEVMLAData::new(version.default); diff --git a/crates/solidity/src/project/mod.rs b/crates/solidity/src/project/mod.rs index d99afd75..c6fc5dfd 100644 --- a/crates/solidity/src/project/mod.rs +++ b/crates/solidity/src/project/mod.rs @@ -62,7 +62,6 @@ impl Project { pub fn compile( self, optimizer_settings: revive_llvm_context::OptimizerSettings, - is_system_mode: bool, include_metadata_hash: bool, debug_config: Option, ) -> anyhow::Result { @@ -74,7 +73,6 @@ impl Project { let process_output = crate::process::call(ProcessInput::new( contract, project.clone(), - is_system_mode, include_metadata_hash, optimizer_settings.clone(), debug_config.clone(), @@ -239,7 +237,6 @@ impl revive_llvm_context::PolkaVMDependency for Project { project: Self, identifier: &str, optimizer_settings: revive_llvm_context::OptimizerSettings, - is_system_mode: bool, include_metadata_hash: bool, debug_config: Option, ) -> anyhow::Result { @@ -259,7 +256,6 @@ impl revive_llvm_context::PolkaVMDependency for Project { .compile( project, optimizer_settings, - is_system_mode, include_metadata_hash, debug_config, ) diff --git a/crates/solidity/src/resolc/arguments.rs b/crates/solidity/src/resolc/arguments.rs index 4bc5dd86..bb877a91 100644 --- a/crates/solidity/src/resolc/arguments.rs +++ b/crates/solidity/src/resolc/arguments.rs @@ -62,10 +62,6 @@ pub struct Arguments { #[structopt(long = "fallback-Oz")] pub fallback_to_optimizing_for_size: bool, - /// Disable the system request memoization. - #[structopt(long = "disable-system-request-memoization")] - pub disable_system_request_memoization: bool, - /// Disable the `solc` optimizer. /// Use it if your project uses the `MSIZE` instruction, or in other cases. /// Beware that it will prevent libraries from being inlined. @@ -123,13 +119,6 @@ pub struct Arguments { #[structopt(long = "force-evmla")] pub force_evmla: bool, - /// Enable system contract compilation mode. - /// In this mode PolkaVM extensions are enabled. For example, calls to addresses `0xFFFF` and below - /// are substituted by special PolkaVM instructions. - /// In the Yul mode, the `verbatim_*` instruction family is available. - #[structopt(long = "system-mode")] - pub is_system_mode: bool, - /// Set metadata hash mode. /// The only supported value is `none` that disables appending the metadata hash. /// Is enabled by default. @@ -267,12 +256,6 @@ impl Arguments { if self.solc.is_some() { anyhow::bail!("`solc` is not used in LLVM IR and PolkaVM assembly modes."); } - - if self.is_system_mode { - anyhow::bail!( - "System contract mode is not supported in LLVM IR and PolkaVM assembly modes." - ); - } } if self.combined_json.is_some() { @@ -319,11 +302,6 @@ impl Arguments { "Falling back to -Oz must specified in standard JSON input settings." ); } - if self.disable_system_request_memoization { - anyhow::bail!( - "Disabling the system request memoization must specified in standard JSON input settings." - ); - } if self.metadata_hash.is_some() { anyhow::bail!("Metadata hash mode must specified in standard JSON input settings."); } diff --git a/crates/solidity/src/resolc/main.rs b/crates/solidity/src/resolc/main.rs index 20c808b0..52ca7642 100644 --- a/crates/solidity/src/resolc/main.rs +++ b/crates/solidity/src/resolc/main.rs @@ -101,9 +101,6 @@ fn main_inner() -> anyhow::Result<()> { if arguments.fallback_to_optimizing_for_size { optimizer_settings.enable_fallback_to_size(); } - if arguments.disable_system_request_memoization { - optimizer_settings.disable_system_request_memoization(); - } optimizer_settings.is_verify_each_enabled = arguments.llvm_verify_each; optimizer_settings.is_debug_logging_enabled = arguments.llvm_debug_logging; @@ -121,7 +118,6 @@ fn main_inner() -> anyhow::Result<()> { input_files.as_slice(), &mut solc, optimizer_settings, - arguments.is_system_mode, include_metadata_hash, debug_config, ) @@ -129,7 +125,6 @@ fn main_inner() -> anyhow::Result<()> { revive_solidity::llvm_ir( input_files.as_slice(), optimizer_settings, - arguments.is_system_mode, include_metadata_hash, debug_config, ) @@ -138,7 +133,6 @@ fn main_inner() -> anyhow::Result<()> { &mut solc, arguments.detect_missing_libraries, arguments.force_evmla, - arguments.is_system_mode, arguments.base_path, arguments.include_paths, arguments.allow_paths, @@ -155,7 +149,6 @@ fn main_inner() -> anyhow::Result<()> { !arguments.disable_solc_optimizer, optimizer_settings, arguments.force_evmla, - arguments.is_system_mode, include_metadata_hash, arguments.base_path, arguments.include_paths, @@ -176,7 +169,6 @@ fn main_inner() -> anyhow::Result<()> { !arguments.disable_solc_optimizer, optimizer_settings, arguments.force_evmla, - arguments.is_system_mode, include_metadata_hash, arguments.base_path, arguments.include_paths, diff --git a/crates/solidity/src/solc/standard_json/input/settings/optimizer/mod.rs b/crates/solidity/src/solc/standard_json/input/settings/optimizer/mod.rs index 4e7fb62e..62b2391a 100644 --- a/crates/solidity/src/solc/standard_json/input/settings/optimizer/mod.rs +++ b/crates/solidity/src/solc/standard_json/input/settings/optimizer/mod.rs @@ -22,9 +22,6 @@ pub struct Optimizer { /// Whether to try to recompile with -Oz if the bytecode is too large. #[serde(skip_serializing)] pub fallback_to_optimizing_for_size: Option, - /// Whether to disable the system request memoization. - #[serde(skip_serializing)] - pub disable_system_request_memoization: Option, } impl Optimizer { @@ -34,14 +31,12 @@ impl Optimizer { mode: Option, version: &semver::Version, fallback_to_optimizing_for_size: bool, - disable_system_request_memoization: bool, ) -> Self { Self { enabled, mode, details: Some(Details::disabled(version)), fallback_to_optimizing_for_size: Some(fallback_to_optimizing_for_size), - disable_system_request_memoization: Some(disable_system_request_memoization), } } @@ -66,9 +61,6 @@ impl TryFrom<&Optimizer> for revive_llvm_context::OptimizerSettings { if value.fallback_to_optimizing_for_size.unwrap_or_default() { result.enable_fallback_to_size(); } - if value.disable_system_request_memoization.unwrap_or_default() { - result.disable_system_request_memoization(); - } Ok(result) } } diff --git a/crates/solidity/src/test_utils.rs b/crates/solidity/src/test_utils.rs index 3c72b070..b88eeb5c 100644 --- a/crates/solidity/src/test_utils.rs +++ b/crates/solidity/src/test_utils.rs @@ -95,7 +95,6 @@ pub fn build_solidity_with_options( None, &solc_version.default, false, - false, ), None, pipeline == SolcPipeline::Yul, @@ -106,7 +105,7 @@ pub fn build_solidity_with_options( let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?; - let build: crate::Build = project.compile(optimizer_settings, false, false, None)?; + let build: crate::Build = project.compile(optimizer_settings, false, None)?; build.write_to_standard_json( &mut output, &solc_version, @@ -144,7 +143,6 @@ pub fn build_solidity_with_options_evm( None, &solc_version.default, false, - false, ), None, pipeline == SolcPipeline::Yul, @@ -193,13 +191,7 @@ pub fn build_solidity_and_detect_missing_libraries( libraries.clone(), None, SolcStandardJsonInputSettingsSelection::new_required(pipeline), - SolcStandardJsonInputSettingsOptimizer::new( - true, - None, - &solc_version.default, - false, - false, - ), + SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false), None, pipeline == SolcPipeline::Yul, None, @@ -229,7 +221,7 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> { let project = Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?; - let _build = project.compile(optimizer_settings, false, false, None)?; + let _build = project.compile(optimizer_settings, false, None)?; Ok(()) } @@ -259,13 +251,7 @@ pub fn check_solidity_warning( libraries, None, SolcStandardJsonInputSettingsSelection::new_required(pipeline), - SolcStandardJsonInputSettingsOptimizer::new( - true, - None, - &solc_version.default, - false, - false, - ), + SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false), None, pipeline == SolcPipeline::Yul, suppressed_warnings, diff --git a/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs b/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs index c5212ec9..58ad5fa3 100644 --- a/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs +++ b/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs @@ -128,7 +128,7 @@ impl FunctionCall { Name::UserDefined(name) if name.starts_with( revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX, - ) && context.is_system_mode() => + ) => { unimplemented!(); } diff --git a/crates/solidity/src/yul/parser/statement/function_definition.rs b/crates/solidity/src/yul/parser/statement/function_definition.rs index ee167b57..e69efd85 100644 --- a/crates/solidity/src/yul/parser/statement/function_definition.rs +++ b/crates/solidity/src/yul/parser/statement/function_definition.rs @@ -234,12 +234,7 @@ where }) .collect(); - let function_type = context.function_type( - argument_types, - self.result.len(), - self.identifier - .starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX), - ); + let function_type = context.function_type(argument_types, self.result.len()); let function = context.add_function( self.identifier.as_str(), @@ -323,7 +318,6 @@ where context.current_function().borrow().r#return(), revive_llvm_context::PolkaVMFunctionReturn::Compound { .. } ) - && context.is_system_mode() { index += 1; } From 8c9d3d155be43c31e84f52898e4a1769bfc09ae0 Mon Sep 17 00:00:00 2001 From: Cyrill Leutwiler Date: Fri, 11 Oct 2024 15:23:27 +0200 Subject: [PATCH 2/3] remove near calls Signed-off-by: Cyrill Leutwiler --- .../src/polkavm/context/function/mod.rs | 6 - .../llvm-context/src/polkavm/context/mod.rs | 6 - .../statement/expression/function_call/mod.rs | 7 - .../parser/statement/function_definition.rs | 125 +----------------- 4 files changed, 2 insertions(+), 142 deletions(-) diff --git a/crates/llvm-context/src/polkavm/context/function/mod.rs b/crates/llvm-context/src/polkavm/context/function/mod.rs index 5c801b8f..1a636312 100644 --- a/crates/llvm-context/src/polkavm/context/function/mod.rs +++ b/crates/llvm-context/src/polkavm/context/function/mod.rs @@ -48,12 +48,6 @@ pub struct Function<'ctx> { } impl<'ctx> Function<'ctx> { - /// The near call ABI function prefix. - pub const ZKSYNC_NEAR_CALL_ABI_PREFIX: &'static str = "ZKSYNC_NEAR_CALL"; - - /// The near call ABI exception handler name. - pub const ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER: &'static str = "ZKSYNC_CATCH_NEAR_CALL"; - /// The stack hashmap default capacity. const STACK_HASHMAP_INITIAL_CAPACITY: usize = 64; diff --git a/crates/llvm-context/src/polkavm/context/mod.rs b/crates/llvm-context/src/polkavm/context/mod.rs index 0d501ad2..411d41fa 100644 --- a/crates/llvm-context/src/polkavm/context/mod.rs +++ b/crates/llvm-context/src/polkavm/context/mod.rs @@ -433,12 +433,6 @@ where let pointer = self.build_alloca(self.word_type(), "return_pointer"); FunctionReturn::primitive(pointer) } - size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => { - let first_argument = value.get_first_param().expect("Always exists"); - let r#type = self.structure_type(vec![self.word_type(); size].as_slice()); - let pointer = first_argument.into_pointer_value(); - FunctionReturn::compound(Pointer::new(r#type, AddressSpace::Stack, pointer), size) - } size => { self.set_basic_block(entry_block); let pointer = self.build_alloca( diff --git a/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs b/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs index 58ad5fa3..8a16a488 100644 --- a/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs +++ b/crates/solidity/src/yul/parser/statement/expression/function_call/mod.rs @@ -125,13 +125,6 @@ impl FunctionCall { let location = self.location; match self.name { - Name::UserDefined(name) - if name.starts_with( - revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX, - ) => - { - unimplemented!(); - } Name::UserDefined(name) => { let mut values = Vec::with_capacity(self.arguments.len()); for argument in self.arguments.into_iter().rev() { diff --git a/crates/solidity/src/yul/parser/statement/function_definition.rs b/crates/solidity/src/yul/parser/statement/function_definition.rs index e69efd85..7ff9775a 100644 --- a/crates/solidity/src/yul/parser/statement/function_definition.rs +++ b/crates/solidity/src/yul/parser/statement/function_definition.rs @@ -92,37 +92,7 @@ impl FunctionDefinition { } } - let (mut arguments, next) = Identifier::parse_typed_list(lexer, None)?; - if identifier - .inner - .contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX) - { - if arguments.is_empty() { - return Err(ParserError::InvalidNumberOfArguments { - location, - identifier: identifier.inner, - expected: 1, - found: arguments.len(), - } - .into()); - } - - arguments.remove(0); - } - if identifier - .inner - .contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER) - && !arguments.is_empty() - { - return Err(ParserError::InvalidNumberOfArguments { - location, - identifier: identifier.inner, - expected: 0, - found: arguments.len(), - } - .into()); - } - + let (arguments, next) = Identifier::parse_typed_list(lexer, None)?; match crate::yul::parser::take_or_next(next, lexer)? { Token { lexeme: Lexeme::Symbol(Symbol::ParenthesisRight), @@ -305,22 +275,12 @@ where yul_type.into_llvm(context) }) .collect(); - for (mut index, argument) in self.arguments.iter().enumerate() { + for (index, argument) in self.arguments.iter().enumerate() { let pointer = context.build_alloca(argument_types[index], argument.inner.as_str()); context .current_function() .borrow_mut() .insert_stack_pointer(argument.inner.clone(), pointer); - if self - .identifier - .starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX) - && matches!( - context.current_function().borrow().r#return(), - revive_llvm_context::PolkaVMFunctionReturn::Compound { .. } - ) - { - index += 1; - } context.build_store( pointer, context.current_function().borrow().get_nth_param(index), @@ -348,13 +308,6 @@ where let return_value = context.build_load(pointer, "return_value")?; context.build_return(Some(&return_value)); } - revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } - if context.current_function().borrow().name().starts_with( - revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX, - ) => - { - context.build_return(Some(&pointer.value)); - } revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } => { let return_value = context.build_load(pointer, "return_value")?; context.build_return(Some(&return_value)); @@ -518,80 +471,6 @@ object "Test" { ); } - #[test] - fn error_invalid_number_of_arguments_near_call_abi() { - let input = r#" -object "Test" { - code { - { - return(0, 0) - } - } - object "Test_deployed" { - code { - { - return(0, 0) - } - - function ZKSYNC_NEAR_CALL_test() -> result { - result := 42 - } - } - } -} - "#; - - let mut lexer = Lexer::new(input.to_owned()); - let result = Object::parse(&mut lexer, None); - assert_eq!( - result, - Err(Error::InvalidNumberOfArguments { - location: Location::new(14, 22), - identifier: "ZKSYNC_NEAR_CALL_test".to_owned(), - expected: 1, - found: 0, - } - .into()) - ); - } - - #[test] - fn error_invalid_number_of_arguments_near_call_abi_catch() { - let input = r#" -object "Test" { - code { - { - return(0, 0) - } - } - object "Test_deployed" { - code { - { - return(0, 0) - } - - function ZKSYNC_CATCH_NEAR_CALL(length) { - revert(0, length) - } - } - } -} - "#; - - let mut lexer = Lexer::new(input.to_owned()); - let result = Object::parse(&mut lexer, None); - assert_eq!( - result, - Err(Error::InvalidNumberOfArguments { - location: Location::new(14, 22), - identifier: "ZKSYNC_CATCH_NEAR_CALL".to_owned(), - expected: 0, - found: 1, - } - .into()) - ); - } - #[test] fn error_reserved_identifier() { let input = r#" From c4ca724fc34303f842d72fb3c03ed90d54beba6e Mon Sep 17 00:00:00 2001 From: Cyrill Leutwiler Date: Fri, 11 Oct 2024 15:31:58 +0200 Subject: [PATCH 3/3] remove obsolete runtime builtins Signed-off-by: Cyrill Leutwiler --- .../polkavm/context/function/llvm_runtime.rs | 182 ------------------ 1 file changed, 182 deletions(-) diff --git a/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs b/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs index 8f26288b..fc5c05ea 100644 --- a/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs +++ b/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs @@ -11,15 +11,6 @@ use crate::polkavm::context::function::Function; /// The functions are automatically linked to the LLVM implementations if the signatures match. #[derive(Debug)] pub struct LLVMRuntime<'ctx> { - /// The corresponding LLVM runtime function. - pub shl: FunctionDeclaration<'ctx>, - /// The corresponding LLVM runtime function. - pub shr: FunctionDeclaration<'ctx>, - /// The corresponding LLVM runtime function. - pub sar: FunctionDeclaration<'ctx>, - /// The corresponding LLVM runtime function. - pub byte: FunctionDeclaration<'ctx>, - /// The corresponding LLVM runtime function. pub add_mod: FunctionDeclaration<'ctx>, /// The corresponding LLVM runtime function. @@ -31,32 +22,9 @@ pub struct LLVMRuntime<'ctx> { /// The corresponding LLVM runtime function. pub sha3: FunctionDeclaration<'ctx>, - - /// The corresponding LLVM runtime function. - pub r#return: FunctionDeclaration<'ctx>, - /// The corresponding LLVM runtime function. - pub revert: FunctionDeclaration<'ctx>, } impl<'ctx> LLVMRuntime<'ctx> { - /// The LLVM personality function name. - pub const FUNCTION_PERSONALITY: &'static str = "__personality"; - - /// The LLVM exception throwing function name. - pub const FUNCTION_CXA_THROW: &'static str = "__cxa_throw"; - - /// The corresponding runtime function name. - pub const FUNCTION_SHL: &'static str = "__shl"; - - /// The corresponding runtime function name. - pub const FUNCTION_SHR: &'static str = "__shr"; - - /// The corresponding runtime function name. - pub const FUNCTION_SAR: &'static str = "__sar"; - - /// The corresponding runtime function name. - pub const FUNCTION_BYTE: &'static str = "__byte"; - /// The corresponding runtime function name. pub const FUNCTION_ADDMOD: &'static str = "__addmod"; @@ -72,121 +40,12 @@ impl<'ctx> LLVMRuntime<'ctx> { /// The corresponding runtime function name. pub const FUNCTION_SHA3: &'static str = "__sha3"; - /// The corresponding runtime function name. - pub const FUNCTION_SYSTEM_REQUEST: &'static str = "__system_request"; - - /// The corresponding runtime function name. - pub const FUNCTION_FARCALL: &'static str = "__farcall"; - - /// The corresponding runtime function name. - pub const FUNCTION_STATICCALL: &'static str = "__staticcall"; - - /// The corresponding runtime function name. - pub const FUNCTION_DELEGATECALL: &'static str = "__delegatecall"; - - /// The corresponding runtime function name. - pub const FUNCTION_MIMICCALL: &'static str = "__mimiccall"; - - /// The corresponding runtime function name. - pub const FUNCTION_FARCALL_BYREF: &'static str = "__farcall_byref"; - - /// The corresponding runtime function name. - pub const FUNCTION_STATICCALL_BYREF: &'static str = "__staticcall_byref"; - - /// The corresponding runtime function name. - pub const FUNCTION_DELEGATECALL_BYREF: &'static str = "__delegatecall_byref"; - - /// The corresponding runtime function name. - pub const FUNCTION_MIMICCALL_BYREF: &'static str = "__mimiccall_byref"; - - /// The corresponding runtime function name. - pub const FUNCTION_RETURN: &'static str = "__return"; - - /// The corresponding runtime function name. - pub const FUNCTION_REVERT: &'static str = "__revert"; - /// A shortcut constructor. pub fn new( llvm: &'ctx inkwell::context::Context, module: &inkwell::module::Module<'ctx>, optimizer: &Optimizer, ) -> Self { - let shl = Self::declare( - module, - Self::FUNCTION_SHL, - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .fn_type( - vec![ - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .as_basic_type_enum() - .into(); - 2 - ] - .as_slice(), - false, - ), - Some(inkwell::module::Linkage::External), - ); - Function::set_default_attributes(llvm, shl, optimizer); - Function::set_pure_function_attributes(llvm, shl); - - let shr = Self::declare( - module, - Self::FUNCTION_SHR, - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .fn_type( - vec![ - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .as_basic_type_enum() - .into(); - 2 - ] - .as_slice(), - false, - ), - Some(inkwell::module::Linkage::External), - ); - Function::set_default_attributes(llvm, shr, optimizer); - Function::set_pure_function_attributes(llvm, shr); - - let sar = Self::declare( - module, - Self::FUNCTION_SAR, - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .fn_type( - vec![ - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .as_basic_type_enum() - .into(); - 2 - ] - .as_slice(), - false, - ), - Some(inkwell::module::Linkage::External), - ); - Function::set_default_attributes(llvm, sar, optimizer); - Function::set_pure_function_attributes(llvm, sar); - - let byte = Self::declare( - module, - Self::FUNCTION_BYTE, - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .fn_type( - vec![ - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .as_basic_type_enum() - .into(); - 2 - ] - .as_slice(), - false, - ), - Some(inkwell::module::Linkage::External), - ); - Function::set_default_attributes(llvm, byte, optimizer); - Function::set_pure_function_attributes(llvm, byte); - let add_mod = Self::define(module, Self::FUNCTION_ADDMOD).expect("should be declared in stdlib"); Function::set_default_attributes(llvm, add_mod, optimizer); @@ -236,54 +95,13 @@ impl<'ctx> LLVMRuntime<'ctx> { false, ); - let r#return = Self::declare( - module, - Self::FUNCTION_RETURN, - llvm.void_type().fn_type( - vec![ - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .as_basic_type_enum() - .into(); - 3 - ] - .as_slice(), - false, - ), - Some(inkwell::module::Linkage::External), - ); - Function::set_default_attributes(llvm, r#return, optimizer); - let revert = Self::declare( - module, - Self::FUNCTION_REVERT, - llvm.void_type().fn_type( - vec![ - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .as_basic_type_enum() - .into(); - 3 - ] - .as_slice(), - false, - ), - Some(inkwell::module::Linkage::External), - ); - Function::set_default_attributes(llvm, revert, optimizer); - Self { - shl, - shr, - sar, - byte, - add_mod, mul_mod, exp, sign_extend, sha3, - - r#return, - revert, } }