-
Notifications
You must be signed in to change notification settings - Fork 16
zksolc compiler integration (MVP) #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
8f9b388
Add clippy lints
ilitteri 1f7f38e
Re-export `ethers-rs`
ilitteri d58321a
Add simple CLI for improving development
ilitteri 94a8753
Update imports
ilitteri 8a6c44c
Remove `unwrap`s
ilitteri d727e45
Add Makefile
ilitteri 1c8ce09
Fix `README.md`
ilitteri 51f4edc
Add serde_json as dependency
IAvecilla 0c5bbc8
Add solc and zksolc compiler binaries
IAvecilla e895186
Add new compile module to use zkSolc as compiler
IAvecilla 88e95b6
Delete compiler binaries from repo
IAvecilla 7819dfe
Add compilation output struct for serialization
IAvecilla e94969b
Add solc and zksolc compiler binaries
IAvecilla 0e898e2
Update Makefile
ilitteri c12b6de
Add `compile` command
ilitteri 16845eb
cargo fmt
ilitteri eda717e
Refactor `ZKProject::compile_zk`
ilitteri bb6ef73
`solc` bin is no longer needed
ilitteri 6430b34
Rename
ilitteri d7f8e35
`compile` cmd now returns the compilation output
ilitteri fc996c0
Refactor `compile` cmd
ilitteri 0524036
cargo fmt
ilitteri d03d455
Add documentation for `compile` cmd
ilitteri 5902125
Revert "`solc` bin is no longer needed"
IAvecilla c23c6e9
Update deps
ilitteri e15f4eb
Change solc compiler path
IAvecilla 8f50862
Add test
ilitteri 3061e63
cargo fmt
ilitteri 2bdac0a
Add struct to serialize abi and bytecodes output compilation
IAvecilla 85d051e
Add test for compiling with files
ilitteri 5064b55
Merge branch 'zksolc_compiler_integration' of github.com:lambdaclass/…
ilitteri ecc1618
Get both abi and bin when compiling
ilitteri c0cd01c
Finish `ContractOuput`
ilitteri 6b9a6a6
cargo fmt
ilitteri 8b16cce
Change type of factory_deps field in to serialize
IAvecilla 6693270
Fix typo in serde-json version dependency
IAvecilla 9163902
Fix abi compilation output serialization
IAvecilla d210f8f
Add support for multiple combined-json arguments in CLI
IAvecilla acffa58
Remove empty file
ilitteri 9e5db76
Update `compile`'s `mod.rs`
ilitteri 4af7226
Handle errors
ilitteri e11592a
Wrap ethers project in ZKProject
IAvecilla b9d0a12
Merge branch 'main' into zksolc_compiler_integration
IAvecilla b7dfe2d
Fix fmt
IAvecilla c5e0eef
Add solc and zksolc path as constants
IAvecilla b311876
`ZKSProvider` trait + `zks_estimateFee` & `zks_getTestnetPaymaster` m…
ilitteri 8a9ff99
Update `Cargo.lock`
ilitteri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
cli: | ||
cargo install --path . | ||
|
||
format: | ||
cargo fmt --all | ||
|
||
clippy: | ||
cargo clippy --all-targets --all-features -- -D warnings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use clap::Parser; | ||
use std::path::PathBuf; | ||
|
||
use crate::compile::{constants, output::ZKCompilationOutput}; | ||
|
||
#[derive(Parser)] | ||
pub struct CompileArgs { | ||
#[clap(long, name = "PATH_TO_SOLC")] | ||
pub solc: Option<PathBuf>, | ||
#[clap(long, name = "COMBINED_JSON")] | ||
pub combined_json: Option<String>, | ||
#[clap(long, action)] | ||
pub standard_json: bool, | ||
} | ||
|
||
pub(crate) fn run(args: CompileArgs) -> eyre::Result<ZKCompilationOutput> { | ||
let mut command = &mut std::process::Command::new(constants::ZK_SOLC_PATH); | ||
if let Some(solc) = args.solc { | ||
command = command.arg("--solc").arg(solc); | ||
} else if let Ok(solc) = std::env::var("SOLC_PATH") { | ||
command = command.arg("--solc").arg(solc); | ||
} else { | ||
eyre::bail!("no solc path provided"); | ||
} | ||
|
||
const VALID_COMBINED_JSON_ARGS: [&str; 10] = [ | ||
"abi", | ||
"hashes", | ||
"metadata", | ||
"devdoc", | ||
"userdoc", | ||
"storage-layout", | ||
"ast", | ||
"asm", | ||
"bin", | ||
"bin-runtime", | ||
]; | ||
|
||
if let Some(combined_json_arg) = args.combined_json { | ||
let valid_args = combined_json_arg | ||
.split(',') | ||
.all(|arg| VALID_COMBINED_JSON_ARGS.contains(&arg)); | ||
if !valid_args { | ||
eyre::bail!("Invalid combined-json argument: {combined_json_arg}"); | ||
} | ||
command = command.arg("--combined-json").arg(combined_json_arg); | ||
} | ||
|
||
if args.standard_json { | ||
command = command.arg("--standard-json"); | ||
} | ||
|
||
command = command | ||
.arg("--") | ||
.arg("src/compile/test_contracts/test/src/Test.sol"); | ||
|
||
let command_output = command.output()?; | ||
let compilation_output: ZKCompilationOutput = serde_json::from_slice(&command_output.stdout)?; | ||
|
||
log::info!("{compilation_output:?}"); | ||
|
||
Ok(compilation_output) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub const SOLC_PATH: &str = "src/compile/solc-macos"; | ||
pub const ZK_SOLC_PATH: &str = "src/compile/zksolc"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum ZKCompilerError { | ||
#[error("Compilation error: {0}")] | ||
CompilationError(String), | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod constants; | ||
pub mod errors; | ||
pub mod output; | ||
pub mod project; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::collections::HashMap; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct ContractOutput { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
abi: Option<Vec<ContractFunctionOutput>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
bin: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
metadata: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
devdoc: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
userdoc: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none", rename = "kebab-case")] | ||
storage_layout: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
ast: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
asm: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none", rename = "kebab-case")] | ||
bin_runtime: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
hashes: Option<HashMap<String, String>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
factory_deps: Option<HashMap<String, String>>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct FunctionArgsTypesOutput { | ||
pub internal_type: String, | ||
pub name: String, | ||
#[serde(rename = "type")] | ||
pub sol_type: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ContractFunctionOutput { | ||
pub inputs: Vec<FunctionArgsTypesOutput>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub name: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub outputs: Option<Vec<FunctionArgsTypesOutput>>, | ||
pub state_mutability: String, | ||
#[serde(rename = "type")] | ||
pub sol_struct_type: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct ZKCompilationOutput { | ||
pub contracts: HashMap<String, ContractOutput>, | ||
pub version: String, | ||
pub zk_version: String, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.