Skip to content

Commit

Permalink
Final sync with the private repo
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Apr 4, 2024
1 parent 076a46c commit 42d07b5
Show file tree
Hide file tree
Showing 34 changed files with 780 additions and 120 deletions.
199 changes: 122 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ members = [
"solidity_adapter",
"coverage_watcher",
"benchmark_analyzer",
"fuzz"
]
resolver = "2"
4 changes: 4 additions & 0 deletions LLVM.lock
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
url = "https://github.com/matter-labs/era-compiler-llvm"
<<<<<<< HEAD
branch = "v1.4.1"
=======
branch = "main"
>>>>>>> d020375 (Final sync with the private repo)
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ Use:
- Yul optimizations enabled (`+`)
- level 3 optimizations in LLVM middle-end (`M3`)
- level 3 optimizations in LLVM back-end (`B3`)
<<<<<<< HEAD
- Solidity compiler version (`0.8.24`)
=======
- Solidity compiler version (`0.8.23`)
>>>>>>> d020375 (Final sync with the private repo)
Output:
Expand All @@ -140,7 +144,11 @@ Output:
```bash
cargo run --release --bin compiler-tester -- -DT \
--path='tests/solidity/simple/default.sol' \
<<<<<<< HEAD
--mode='Y+M3B3 0.8.24' \
=======
--mode='Y+M3B3 0.8.23' \
>>>>>>> d020375 (Final sync with the private repo)
--zksolc '../era-compiler-solidity/target/release/zksolc'
```
Expand Down Expand Up @@ -191,7 +199,11 @@ zkevm-llvm checkout && zkevm-llvm build
```
./target/release/compiler-tester \
--path='tests/solidity/simple/default.sol' \
<<<<<<< HEAD
--mode='Y+M^B3 0.8.24' \
=======
--mode='Y+M^B3 0.8.23' \
>>>>>>> d020375 (Final sync with the private repo)
--benchmark='reference.json'
```
Expand All @@ -204,7 +216,11 @@ zkevm-llvm checkout && zkevm-llvm build
```
./target/release/compiler-tester \
--path='tests/solidity/simple/default.sol' \
<<<<<<< HEAD
--mode='Y+M^B3 0.8.24' \
=======
--mode='Y+M^B3 0.8.23' \
>>>>>>> d020375 (Final sync with the private repo)
--benchmark='candidate.json'
```
Expand Down
5 changes: 5 additions & 0 deletions compiler_tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler
era-compiler-solidity = { git = "https://github.com/matter-labs/era-compiler-solidity", branch = "main" }
era-compiler-vyper = { git = "https://github.com/matter-labs/era-compiler-vyper", branch = "main" }

# era-compiler-common = { path = "../../era-compiler-common" }
# era-compiler-llvm-context = { path = "../../era-compiler-llvm-context" }
# era-compiler-solidity = { path = "../../era-compiler-solidity" }
# era-compiler-vyper = { path = "../../era-compiler-vyper" }

solidity-adapter = { path = "../solidity_adapter" }
benchmark-analyzer = { path = "../benchmark_analyzer" }

Expand Down
9 changes: 9 additions & 0 deletions compiler_tester/src/compilers/eravm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ use crate::vm::evm::input::Input as EVMInput;
#[allow(non_camel_case_types)]
pub struct EraVMCompiler;

impl EraVMCompiler {
///
/// A shortcut constructor.
///
pub fn new() -> Self {
Self::default()
}
}

impl Compiler for EraVMCompiler {
fn compile_for_eravm(
&self,
Expand Down
9 changes: 9 additions & 0 deletions compiler_tester/src/compilers/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ lazy_static::lazy_static! {
};
}

impl LLVMCompiler {
///
/// A shortcut constructor.
///
pub fn new() -> Self {
Self::default()
}
}

impl Compiler for LLVMCompiler {
fn compile_for_eravm(
&self,
Expand Down
1 change: 1 addition & 0 deletions compiler_tester/src/compilers/solidity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl SolidityCompiler {
&mode.solc_version,
false,
false,
None,
);

let evm_version = if mode.solc_version == semver::Version::new(0, 8, 24) {
Expand Down
9 changes: 9 additions & 0 deletions compiler_tester/src/compilers/yul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ lazy_static::lazy_static! {
};
}

impl YulCompiler {
///
/// A shortcut constructor.
///
pub fn new() -> Self {
Self::default()
}
}

impl Compiler for YulCompiler {
fn compile_for_eravm(
&self,
Expand Down
4 changes: 2 additions & 2 deletions compiler_tester/src/directories/ethereum/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use crate::vm::AddressPredictorIterator;
///
pub struct EthereumTest {
/// The index test entity.
index_entity: solidity_adapter::EnabledTest,
pub index_entity: solidity_adapter::EnabledTest,
/// The test data.
test: solidity_adapter::Test,
pub test: solidity_adapter::Test,
}

impl EthereumTest {
Expand Down
38 changes: 20 additions & 18 deletions compiler_tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ use itertools::Itertools;
use rayon::iter::IntoParallelIterator;
use rayon::iter::ParallelIterator;

use crate::compilers::eravm::EraVMCompiler;
use crate::compilers::llvm::LLVMCompiler;
use crate::compilers::mode::Mode;
use crate::compilers::solidity::SolidityCompiler;
use crate::compilers::vyper::VyperCompiler;
use crate::compilers::yul::YulCompiler;
use crate::compilers::Compiler;
use crate::directories::ethereum::EthereumDirectory;
use crate::directories::matter_labs::MatterLabsDirectory;
use crate::directories::Buildable;
use crate::directories::TestsDirectory;
use crate::vm::eravm::deployers::Deployer as EraVMDeployer;
pub use crate::compilers::eravm::EraVMCompiler;
pub use crate::compilers::llvm::LLVMCompiler;
pub use crate::compilers::mode::solidity::Mode as SolidityMode;
pub use crate::compilers::mode::Mode;
pub use crate::compilers::solidity::SolidityCompiler;
pub use crate::compilers::vyper::VyperCompiler;
pub use crate::compilers::yul::YulCompiler;
pub use crate::compilers::Compiler;
pub use crate::directories::ethereum::test::EthereumTest;
pub use crate::directories::ethereum::EthereumDirectory;
pub use crate::directories::matter_labs::MatterLabsDirectory;
pub use crate::directories::Buildable;
pub use crate::directories::TestsDirectory;
pub use crate::vm::eravm::deployers::Deployer as EraVMDeployer;

/// The debug directory path.
pub const DEBUG_DIRECTORY: &str = "./debug/";
Expand All @@ -56,11 +58,11 @@ type Test = (Arc<dyn Buildable>, Arc<dyn Compiler>, Mode);
///
pub struct CompilerTester {
/// The summary.
summary: Arc<Mutex<Summary>>,
pub summary: Arc<Mutex<Summary>>,
/// The filters.
filters: Filters,
pub filters: Filters,
/// The debug config.
debug_config: Option<era_compiler_llvm_context::DebugConfig>,
pub debug_config: Option<era_compiler_llvm_context::DebugConfig>,
}

impl CompilerTester {
Expand Down Expand Up @@ -190,9 +192,9 @@ impl CompilerTester {
fn all_tests(&self) -> anyhow::Result<Vec<Test>> {
let solidity_compiler = Arc::new(SolidityCompiler::new());
let vyper_compiler = Arc::new(VyperCompiler::new());
let yul_compiler = Arc::new(YulCompiler);
let llvm_compiler = Arc::new(LLVMCompiler);
let eravm_compiler = Arc::new(EraVMCompiler);
let yul_compiler = Arc::new(YulCompiler::new());
let llvm_compiler = Arc::new(LLVMCompiler::new());
let eravm_compiler = Arc::new(EraVMCompiler::new());

let mut tests = Vec::with_capacity(16384);

Expand Down
8 changes: 2 additions & 6 deletions compiler_tester/src/vm/eravm/system_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,8 @@ impl SystemContracts {
yul_file_paths.push(file_path.to_owned());
}
let yul_mode = YulMode::new(era_compiler_llvm_context::OptimizerSettings::cycles()).into();
let mut builds = Self::compile(
YulCompiler,
&yul_mode,
yul_file_paths,
debug_config.clone(),
)?;
let mut builds =
Self::compile(YulCompiler, &yul_mode, yul_file_paths, debug_config.clone())?;

let mut solidity_file_paths = Vec::with_capacity(solidity_system_contracts.len() + 1);
for (_, path) in solidity_system_contracts.iter() {
Expand Down
6 changes: 6 additions & 0 deletions configs/solc-bin-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@
"destination": "./solc-bin/solc-${VERSION}"
},
"0.8.24": {
"is_enabled": false,
"protocol": "https",
"source": "https://github.com/matter-labs/era-solidity/releases/download/${VERSION}-1.0.0/solc-${PLATFORM}-${VERSION}-1.0.0",
"destination": "./solc-bin/solc-${VERSION}"
},
"0.8.25": {
"is_enabled": true,
"protocol": "https",
"source": "https://github.com/matter-labs/era-solidity/releases/download/${VERSION}-1.0.0/solc-${PLATFORM}-${VERSION}-1.0.0",
Expand Down
16 changes: 16 additions & 0 deletions configs/solc-bin-zkevm-candidate-0.8.25.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"binaries": {
"0.8.25": {
"is_enabled": true,
"protocol": "file",
"source": "./solc-bin/solc-${VERSION}",
"destination": "./solc-bin/solc-${VERSION}"
}
},
"platforms": {
"linux-amd64": "linux-amd64",
"linux-arm64": "linux-arm64",
"macos-amd64": "macosx-amd64",
"macos-arm64": "macosx-arm64"
}
}
16 changes: 16 additions & 0 deletions configs/solc-bin-zkevm-reference-0.8.25.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"binaries": {
"0.8.25": {
"is_enabled": true,
"protocol": "https",
"source": "https://github.com/matter-labs/era-solidity/releases/download/${VERSION}-1.0.0/solc-${PLATFORM}-${VERSION}-1.0.0",
"destination": "./solc-bin/solc-${VERSION}"
}
},
"platforms": {
"linux-amd64": "linux-amd64",
"linux-arm64": "linux-arm64",
"macos-amd64": "macosx-amd64",
"macos-arm64": "macosx-arm64"
}
}
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
38 changes: 38 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "compiler-tester-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "main" }
era-compiler-solidity = { git = "https://github.com/matter-labs/era-compiler-solidity", branch = "main" }
zkevm-assembly = { git = "https://github.com/matter-labs/era-zkEVM-assembly", branch = "v1.4.1" }
zkevm_tester = { git = "https://github.com/matter-labs/era-zkevm_tester", branch = "v1.4.1" }
anyhow = "1.0"
semver = { version = "1.0", features = ["serde"] }

[dependencies.compiler-tester]
path = "../compiler_tester"

[dependencies.solidity-adapter]
path = "../solidity_adapter"


[[bin]]
name = "demo"
path = "fuzz_targets/demo.rs"
test = false
doc = false
bench = false

[[bin]]
name = "optimizer_bug"
path = "fuzz_targets/optimizer_bug.rs"
test = false
doc = false
bench = false
52 changes: 52 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Solidity Contracts Fuzzing

This is the skeleton for Solidity smart contracts fuzzing based on the [Rust fuzz](https://rust-fuzz.github.io/book/introduction.html) engine.

## Project structure

The project consists of the following directories:

- `fuzz_contracts` - Solidity smart contracts to be fuzzed.
- `fuzz_targets` - fuzzing targets definitions.

### Fuzzing targets

Each fuzzing target is a separate Rust binary crate and defined in the `fuzz_targets` directory. The `Cargo.toml` file in the root directory contains the dependencies and the configuration for the fuzzing engine.

For example, the `simple` fuzzing target is defined in the `fuzz_targets/simple.rs` file. The `Cargo.toml` file contains the following section:

```properties
[[bin]]
name = "simple"
path = "fuzz_targets/simple.rs"
...
```

`cargo fuzz add <target_name>` command can be used to add a new empty fuzzing target.

## Running fuzzing

To run the fuzzing, execute the following command:

```bash
cargo fuzz run <target_name>
```

## Supported targets

- [`demo`](./fuzz_contracts/demo/demo.md) - demonstrates the basic fuzzing setup.
- `optimizer_bug` - demonstrates fuzzer finding a bug in the optimizer.

## Current limitations

- The current setup uses the fixed hardcoded version of optimization settings (`Y+M3B3`) and `solc` compiler version (`0.8.24`).
- The current targets are using the simplest contracts and fuzzing strategy that mutates only the function arguments.
- The current setup uses only EraVM as the execution engine as well as `EthereumTest` as the test type.

## Roadmap

- [ ] Add the ability to specify the optimization settings and compiler versions.
- [ ] Support for more complex contracts (real-life use cases).
- [ ] Support on-the-fly fuzzing function generation.
- [ ] Support mutating of the contract source code with Solidity vocabulary.
- [ ] Support CI execution in OSS Fuzz infrastructure.
Loading

0 comments on commit 42d07b5

Please sign in to comment.