mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-23 16:38:02 +00:00
Integrate benchmarks and differential tests against an EVM interpreter (#7)
This commit is contained in:
@@ -41,6 +41,8 @@ pub enum Flag {
|
||||
/// The EVM legacy assembly JSON.
|
||||
#[serde(rename = "evm.legacyAssembly")]
|
||||
EVMLA,
|
||||
#[serde(rename = "evm.deployedBytecode")]
|
||||
EVMDBC,
|
||||
}
|
||||
|
||||
impl From<SolcPipeline> for Flag {
|
||||
@@ -64,6 +66,7 @@ impl std::fmt::Display for Flag {
|
||||
Self::AST => write!(f, "ast"),
|
||||
Self::Yul => write!(f, "irOptimized"),
|
||||
Self::EVMLA => write!(f, "evm.legacyAssembly"),
|
||||
Self::EVMDBC => write!(f, "evm.deployedBytecode"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ impl File {
|
||||
Self {
|
||||
per_file: Some(HashSet::from_iter([SelectionFlag::AST])),
|
||||
per_contract: Some(HashSet::from_iter([
|
||||
SelectionFlag::EVMDBC,
|
||||
SelectionFlag::MethodIdentifiers,
|
||||
SelectionFlag::Metadata,
|
||||
SelectionFlag::from(pipeline),
|
||||
|
||||
@@ -23,3 +23,22 @@ impl Bytecode {
|
||||
Self { object }
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// The `solc --standard-json` output contract EVM deployed bytecode.
|
||||
///
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DeployedBytecode {
|
||||
/// The bytecode object.
|
||||
pub object: String,
|
||||
}
|
||||
|
||||
impl DeployedBytecode {
|
||||
///
|
||||
/// A shortcut constructor.
|
||||
///
|
||||
pub fn new(object: String) -> Self {
|
||||
Self { object }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use serde::Serialize;
|
||||
use crate::evmla::assembly::Assembly;
|
||||
|
||||
use self::bytecode::Bytecode;
|
||||
use self::bytecode::DeployedBytecode;
|
||||
use self::extra_metadata::ExtraMetadata;
|
||||
|
||||
///
|
||||
@@ -32,6 +33,8 @@ pub struct EVM {
|
||||
/// The contract bytecode.
|
||||
/// Is reset by that of EraVM before yielding the compiled project artifacts.
|
||||
pub bytecode: Option<Bytecode>,
|
||||
/// The contract deployed bytecode.
|
||||
pub deployed_bytecode: Option<DeployedBytecode>,
|
||||
/// The contract function signatures.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub method_identifiers: Option<BTreeMap<String, String>>,
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::solc::pipeline::Pipeline as SolcPipeline;
|
||||
use crate::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
use crate::solc::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||
use crate::solc::standard_json::input::Input as SolcStandardJsonInput;
|
||||
use crate::solc::standard_json::output::contract::evm::bytecode::DeployedBytecode;
|
||||
use crate::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
||||
use crate::solc::Compiler as SolcCompiler;
|
||||
use crate::warning::Warning;
|
||||
@@ -100,6 +101,59 @@ pub fn build_solidity_with_options(
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
/// Build a Solidity contract and get the EVM bin-runtime.
|
||||
pub fn build_solidity_with_options_evm(
|
||||
sources: BTreeMap<String, String>,
|
||||
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
||||
remappings: Option<BTreeSet<String>>,
|
||||
pipeline: SolcPipeline,
|
||||
solc_optimizer_enabled: bool,
|
||||
) -> anyhow::Result<BTreeMap<String, DeployedBytecode>> {
|
||||
check_dependencies();
|
||||
|
||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||
era_compiler_llvm_context::initialize_target(era_compiler_llvm_context::Target::PVM);
|
||||
let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||
|
||||
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
||||
let solc_version = solc.version()?;
|
||||
|
||||
let input = SolcStandardJsonInput::try_from_sources(
|
||||
None,
|
||||
sources.clone(),
|
||||
libraries.clone(),
|
||||
remappings,
|
||||
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
||||
SolcStandardJsonInputSettingsOptimizer::new(
|
||||
solc_optimizer_enabled,
|
||||
None,
|
||||
&solc_version.default,
|
||||
false,
|
||||
false,
|
||||
),
|
||||
None,
|
||||
pipeline == SolcPipeline::Yul,
|
||||
None,
|
||||
)?;
|
||||
|
||||
let mut output = solc.standard_json(input, pipeline, None, vec![], None)?;
|
||||
|
||||
let mut contracts = BTreeMap::new();
|
||||
if let Some(files) = output.contracts.as_mut() {
|
||||
for (_, file) in files.iter_mut() {
|
||||
for (name, contract) in file.iter_mut() {
|
||||
if let Some(evm) = contract.evm.as_mut() {
|
||||
if let Some(deployed_bytecode) = evm.deployed_bytecode.as_ref() {
|
||||
contracts.insert(name.clone(), deployed_bytecode.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(contracts)
|
||||
}
|
||||
|
||||
///
|
||||
/// Builds the Solidity project and returns the standard JSON output.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user