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: the EXTCODECOPY support #87

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- The support for compiling multiple files in Yul, LLVM IR, and EraVM assembly modes
- The support for Yul, LLVM IR, and EraVM assembly languages in standard JSON mode
- The support for `urls` to local files in standard JSON input
- The support for `EXTCODECOPY` instruction

## [1.4.1] - 2024-04-24

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ md5 = "0.7"
zkevm-assembly = { git = "https://github.com/matter-labs/era-zkEVM-assembly", branch = "v1.5.0" }

era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "main" }
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "main" }
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "az-cpr-1702-support-extcodecopy-codecopy" }

[dependencies.inkwell]
git = "https://github.com/matter-labs-forks/inkwell"
Expand Down
27 changes: 19 additions & 8 deletions src/evmla/ethereal_ir/function/block/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,17 @@ where
)
.map(Some)
}
InstructionName::EXTCODECOPY => {
let arguments = self.pop_arguments_llvm(context)?;
era_compiler_llvm_context::eravm_evm_ext_code::copy(
context,
arguments[0].into_int_value(),
arguments[1].into_int_value(),
arguments[2].into_int_value(),
arguments[3].into_int_value(),
)
.map(|_| None)
}

InstructionName::RETURN => {
let arguments = self.pop_arguments_llvm(context)?;
Expand Down Expand Up @@ -1272,10 +1283,6 @@ where
InstructionName::PC => {
anyhow::bail!("The `PC` instruction is not supported");
}
InstructionName::EXTCODECOPY => {
let _arguments = self.pop_arguments_llvm(context)?;
anyhow::bail!("The `EXTCODECOPY` instruction is not supported");
}
InstructionName::SELFDESTRUCT => {
let _arguments = self.pop_arguments_llvm(context)?;
anyhow::bail!("The `SELFDESTRUCT` instruction is not supported");
Expand Down Expand Up @@ -2108,6 +2115,14 @@ where
.map(Some)
}
InstructionName::EXTCODEHASH => {
let arguments = self.pop_arguments_llvm_evm(context)?;
era_compiler_llvm_context::evm_code::ext_hash(
context,
arguments[0].into_int_value(),
)
.map(|_| None)
}
InstructionName::EXTCODECOPY => {
let arguments = self.pop_arguments_llvm_evm(context)?;
era_compiler_llvm_context::evm_code::ext_copy(
context,
Expand Down Expand Up @@ -2378,10 +2393,6 @@ where
InstructionName::PC => {
anyhow::bail!("The `PC` instruction is not supported");
}
InstructionName::EXTCODECOPY => {
let _arguments = self.pop_arguments_llvm_evm(context)?;
anyhow::bail!("The `EXTCODECOPY` instruction is not supported");
}
InstructionName::SELFDESTRUCT => {
let _arguments = self.pop_arguments_llvm_evm(context)?;
anyhow::bail!("The `SELFDESTRUCT` instruction is not supported");
Expand Down
49 changes: 0 additions & 49 deletions src/tests/unsupported_opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,55 +124,6 @@ object "ProgramCounter" {
super::build_yul(sources).expect("Test failure");
}

pub const EXTCODECOPY_TEST_SOURCE: &str = r#"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ExternalCodeCopy {
function copyExternalCode(address target, uint256 codeSize) public view returns (bytes memory) {
bytes memory code = new bytes(codeSize);

assembly {
extcodecopy(target, add(code, 0x20), 0, codeSize)
}

return code;
}
}
"#;

#[test]
#[should_panic(expected = "The `EXTCODECOPY` instruction is not supported")]
fn extcodecopy_evmla() {
let mut sources = BTreeMap::new();
sources.insert("test.sol".to_owned(), EXTCODECOPY_TEST_SOURCE.to_owned());

super::build_solidity(
sources,
BTreeMap::new(),
None,
SolcPipeline::EVMLA,
era_compiler_llvm_context::OptimizerSettings::cycles(),
)
.expect("Test failure");
}

#[test]
#[should_panic(expected = "The `EXTCODECOPY` instruction is not supported")]
fn extcodecopy_yul() {
let mut sources = BTreeMap::new();
sources.insert("test.sol".to_owned(), EXTCODECOPY_TEST_SOURCE.to_owned());

super::build_solidity(
sources,
BTreeMap::new(),
None,
SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(),
)
.expect("Test failure");
}

pub const SELFDESTRUCT_TEST_SOURCE: &str = r#"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
Expand Down
18 changes: 11 additions & 7 deletions src/yul/parser/statement/expression/function_call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@ impl FunctionCall {
)
.map(Some)
}
Name::ExtCodeCopy => {
let arguments = self.pop_arguments_llvm::<D, 4>(context)?;
era_compiler_llvm_context::eravm_evm_ext_code::copy(
context,
arguments[0].into_int_value(),
arguments[1].into_int_value(),
arguments[2].into_int_value(),
arguments[3].into_int_value(),
)
.map(|_| None)
}

Name::Return => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
Expand Down Expand Up @@ -1093,13 +1104,6 @@ impl FunctionCall {
anyhow::bail!("{} The `CALLCODE` instruction is not supported", location)
}
Name::Pc => anyhow::bail!("{} The `PC` instruction is not supported", location),
Name::ExtCodeCopy => {
let _arguments = self.pop_arguments_llvm::<D, 4>(context)?;
anyhow::bail!(
"{} The `EXTCODECOPY` instruction is not supported",
location
)
}
Name::SelfDestruct => {
let _arguments = self.pop_arguments_llvm::<D, 1>(context)?;
anyhow::bail!(
Expand Down
Loading