Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resolc): integrate revive compiler for evm to resolc compilation #1

Draft
wants to merge 55 commits into
base: main
Choose a base branch
from

Conversation

Brianspha
Copy link
Owner

@Brianspha Brianspha commented Nov 29, 2024

Description

This PR adds the initial integration of Revive compiler with foundry-compilers to compile EVM contracts to Resolc bytecode.

Changes

  • Add Revive compiler integration with foundry abstractions
  • Implement foundry-compiler trait for Revive
  • Add bytecode conversion utilities
  • Configure Revive compiler settings
  • Add error handling for Revive compilation

Testing

  • Unit tests for Revive compiler integration
  • Integration tests

Impact

  • Enables foundry-compilers to use Revive for EVM contract compilation
  • Maintains compatibility with existing foundry interfaces

Checklist

  • Code follows project style guide
  • Code is tested

@Brianspha Brianspha changed the title feat(resolc): Add resolc compiler feat(resolc): integrate revive compiler for evm to resolc compilation Nov 29, 2024
Copy link

@pkhry pkhry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collection of nits

pub use foundry_compilers_artifacts_solc as solc;
pub use foundry_compilers_artifacts_vyper as vyper;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidental?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 6? If yes nope just following integration similar to solc and vyper

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9, the new newline

pub missing_libraries: Option<HashSet<String>>,
}

impl Default for ResolcContract {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can't find where it's used?

Self { abi: c.abi.as_ref(), bin, bin_runtime }
}
}
fn create_compact_bytecode(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn create_compact_bytecode(
impl ResolcContract {
fn json_abi(&self) -> Option<JsonAbi> {
self.abi.clone()
}
fn compact_bytecode(&self) -> Option<CompactBytecode> {
self.resolc_evm.as_ref().and_then(|resolc_evm| resolc_evm.bytecode.as_ref()).map(
|bytecode| CompactBytecode {
object: bytecode.object.clone(),
source_map: None,
link_references: BTreeMap::default(),
},
)
}
fn compact_deployed_bytecode(&self) -> Option<CompactDeployedBytecode> {
self.resolc_evm
.as_ref()
.and_then(|resolc_evm| resolc_evm.deployed_bytecode.as_ref())
.and_then(|item| item.bytecode.as_ref())
.map(|deployed_bytecode| {
let compact_bytecode_deployed = CompactBytecode {
object: deployed_bytecode.object.clone(),
source_map: None,
link_references: BTreeMap::default(),
};
CompactDeployedBytecode {
bytecode: Some(compact_bytecode_deployed),
immutable_references: BTreeMap::default(),
}
})
.to_owned()
}
}

}
}

impl<'a> From<&'a ResolcContract> for CompactContractRef<'a> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impl<'a> From<&'a ResolcContract> for CompactContractRef<'a> {
impl<'a> From<&'a ResolcContract> for CompactContractRef<'a> {
fn from(c: &'a ResolcContract) -> Self {
let (bin, bin_runtime) = match &c.resolc_evm {
Some(evm) => {
let bin = evm.bytecode.as_ref().map(|code| &code.object);
let bin_runtime = evm
.deployed_bytecode
.as_ref()
.and_then(|deployed| deployed.bytecode.as_ref().map(|code| &code.object));
(bin, bin_runtime)
}
_ => (None, None),
};
Self { abi: c.abi.as_ref(), bin, bin_runtime }
}
}

}
}

impl From<ResolcContract> for CompactContractBytecode {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impl From<ResolcContract> for CompactContractBytecode {
impl From<ResolcContract> for CompactContractBytecode {
fn from(value: ResolcContract) -> Self {
Self {
abi: value.json_abi(),
bytecode: value.compact_bytecode(),
deployed_bytecode: value.compact_deployed_bytecode(),
}
}
}

or it's intended to always return every field to None if at least one of them is None?

"aarch64" => Ok(ResolcOS::LinuxARM64),
_ => Ok(ResolcOS::LinuxAMD64),
},
"macos" | "darwin" => match std::env::consts::ARCH {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"macos" | "darwin" => match std::env::consts::ARCH {
"macos" => match std::env::consts::ARCH {

.filter(|v| uniques.insert((v.major, v.minor, v.patch)))
.map(CompilerVersion::Remote),
);
all_versions.sort_unstable();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why unstable sort here?

Ok(Self::compilers_dir()?.join(format!("{}v{}", os.get_resolc_prefix(), version)))
}

pub fn find_installed_version(version: &Version) -> Result<Option<PathBuf>> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn find_installed_version(version: &Version) -> Result<Option<PathBuf>> {
pub fn find_installed_version(version: &Version) -> Result<Option<PathBuf>> {
Self::compiler_path(version)
.map(|resolc| if !resolc.is_file() { None } else { Some(resolc) })
}

})
}

#[cfg(feature = "async")]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's marked as feature async if the api used is non async? shouldn't it be possible to use tokio API?

"aarch64" => assert!(matches!(os, ResolcOS::LinuxARM64)),
_ => assert!(matches!(os, ResolcOS::LinuxAMD64)),
},
"macos" | "darwin" => match std::env::consts::ARCH {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"macos" | "darwin" => match std::env::consts::ARCH {
"macos" => match std::env::consts::ARCH {

This commit removes some omissions i made related to github releases and downloading from Github aswell as fixing tests that had flawed logic
This commit fixes the issue with mac based systems seems like resolc doesnt work but wasm does
@Brianspha Brianspha marked this pull request as draft December 17, 2024 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants