Skip to content

Commit

Permalink
ZIR-235: build rules to run bigint2c, emit blobs, and package into …
Browse files Browse the repository at this point in the history
…zip file (#72)

* build rules to run `bigint2c`, emit blobs, and package into zip file

* new `cargo bootsrap bigint2` target copies bigint2 blobs

* cargo fmt
  • Loading branch information
mars-risc0 authored Nov 14, 2024
1 parent 238fb9d commit f9ae96e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions zirgen/bootstrap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ enum Circuit {
Verify,
#[clap(name("bigint"))]
BigInt,
#[clap(name("bigint2"))]
BigInt2,
}

#[derive(Parser)]
Expand Down Expand Up @@ -232,6 +234,7 @@ impl Args {
Circuit::Calculator => self.calculator(),
Circuit::Verify => self.stark_verify(),
Circuit::BigInt => self.bigint(),
Circuit::BigInt2 => self.bigint2(),
}
}

Expand Down Expand Up @@ -405,6 +408,22 @@ impl Args {

cargo_fmt_circuit(circuit, &Some(bigint_crate_root), &None);
}

fn bigint2(&self) {
let risc0_root = self.output.as_ref().expect("--output is required");
let risc0_root = risc0_root.join("risc0");
let bazel_bin = get_bazel_bin();
let src_path = bazel_bin.join("zirgen/circuit/bigint");
let rsa_path = risc0_root.join("bigint2/src/rsa");
let ec_path = risc0_root.join("bigint2/src/ec");

copy_file(&src_path, &rsa_path, "modpow_65537.blob");
copy(
&src_path.join("ec_double.blob"),
&ec_path.join("double.blob"),
);
copy(&src_path.join("ec_add.blob"), &ec_path.join("add.blob"));
}
}

fn main() {
Expand Down
32 changes: 32 additions & 0 deletions zirgen/circuit/bigint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,35 @@ cc_binary(
],
)

BLOBS = [
"modpow_65537",
"ec_double",
"ec_add",
]

genrule(
name = "modpow_65537",
outs = ["modpow_65537.blob"],
exec_tools = [":bigint2c"],
cmd = "$(location //zirgen/circuit/bigint:bigint2c) --program=modpow_65537 > $(OUTS)"
)

genrule(
name = "ec_double",
outs = ["ec_double.blob"],
exec_tools = [":bigint2c"],
cmd = "$(location //zirgen/circuit/bigint:bigint2c) --program=ec_double > $(OUTS)"
)

genrule(
name = "ec_add",
outs = ["ec_add.blob"],
exec_tools = [":bigint2c"],
cmd = "$(location //zirgen/circuit/bigint:bigint2c) --program=ec_add > $(OUTS)"
)

pkg_zip(
name = "bigint_blob",
srcs = [x + ".blob" for x in BLOBS],
)

0 comments on commit f9ae96e

Please sign in to comment.