Skip to content

Commit

Permalink
Merge pull request #5 from matter-labs/popzxc-fix-codegen
Browse files Browse the repository at this point in the history
Fix codegen crate
  • Loading branch information
popzxc authored Aug 14, 2024
2 parents bef4fbd + 6957e73 commit 7082689
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
3 changes: 0 additions & 3 deletions crates/codegen-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ zksync_solidity_vk_codegen = { path = "../codegen" }
structopt = "0.3"
dialoguer = "0.8"

[[bin]]
name = "generate"
path = "src/main.rs"
35 changes: 23 additions & 12 deletions crates/codegen-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ use zksync_solidity_vk_codegen::{generate, Encoding};

const DEFAULT_OUTPUT_FILE: &str = "./hardhat/contracts";

const PAIRING_BN_254_FILE_PATH: &str = "./codegen/template/PairingsBn254.sol";
const TRANSCRIPT_LIB_FILE_PATH: &str = "./codegen/template/TranscriptLib.sol";
const UNCHECKED_MATH_FILE_PATH: &str = "./codegen/template/UncheckedMath.sol";
const PLONK_4_VERIFIER_FILE_PATH: &str = "./codegen/template/Plonk4VerifierWithAccessToDNext.sol";
const VEERIFIER_TEMPLATE_FILE_PATH: &str = "./codegen/template/Verifier.sol";
const PAIRING_BN_254_FILE_PATH: &str = "PairingsBn254.sol";
const TRANSCRIPT_LIB_FILE_PATH: &str = "TranscriptLib.sol";
const UNCHECKED_MATH_FILE_PATH: &str = "UncheckedMath.sol";
const PLONK_4_VERIFIER_FILE_PATH: &str = "Plonk4VerifierWithAccessToDNext.sol";
const VEERIFIER_TEMPLATE_FILE_PATH: &str = "Verifier.sol";

#[derive(StructOpt, Debug)]
pub struct Opts {
/// Path to verification key(required)
/// Path to verification key (required)
#[structopt(long, parse(from_os_str))]
verification_key: PathBuf,
/// Path to the folder with templates (required)
/// Should point to the `codegen/template` directory
#[structopt(long, parse(from_os_str))]
templates_dir: PathBuf,
/// Output directory
#[structopt(long, parse(from_os_str), default_value = DEFAULT_OUTPUT_FILE)]
output: PathBuf,
Expand All @@ -27,7 +31,12 @@ fn main() {
let opts = Opts::from_args();
println!("{:#?}", opts);

let Opts { verification_key, output, encoding } = opts;
let Opts {
verification_key,
output,
templates_dir,
encoding,
} = opts;

let encoding = match encoding {
Some(encoding) => match encoding.as_str() {
Expand All @@ -37,16 +46,18 @@ fn main() {
None => Encoding::Default,
};

let template_path = |file_name: &str| templates_dir.join(file_name).to_string_lossy().into_owned();

generate(
verification_key,
output.clone(),
encoding,
vec![
VEERIFIER_TEMPLATE_FILE_PATH,
PLONK_4_VERIFIER_FILE_PATH,
TRANSCRIPT_LIB_FILE_PATH,
PAIRING_BN_254_FILE_PATH,
UNCHECKED_MATH_FILE_PATH,
template_path(VEERIFIER_TEMPLATE_FILE_PATH).as_ref(),
template_path(PLONK_4_VERIFIER_FILE_PATH).as_ref(),
template_path(TRANSCRIPT_LIB_FILE_PATH).as_ref(),
template_path(PAIRING_BN_254_FILE_PATH).as_ref(),
template_path(UNCHECKED_MATH_FILE_PATH).as_ref(),
],
);

Expand Down

0 comments on commit 7082689

Please sign in to comment.