mirror of
https://github.com/logos-blockchain/logos-blockchain-circuits.git
synced 2026-06-10 02:30:05 +00:00
feat: Expose all circuit artifacts via macro. (#37)
This commit is contained in:
parent
c6cc320c52
commit
8eab6dce28
45
rust/logos-blockchain-circuits-common/src/artifacts.rs
Normal file
45
rust/logos-blockchain-circuits-common/src/artifacts.rs
Normal file
@ -0,0 +1,45 @@
|
||||
/// Generates a `pub mod artifacts` containing the circuit compilation
|
||||
/// artifacts.
|
||||
///
|
||||
/// The artifacts are loaded from the directory pointed to by
|
||||
/// `LBC_{CIRCUIT}_LIB_DIR`, set by the crate's build script.
|
||||
///
|
||||
/// # Generated items
|
||||
///
|
||||
/// | Item | Description |
|
||||
/// |-------------------------|-----------------------------------------|
|
||||
/// | `PROVING_KEY_PATH` | Path to the proving key (`.zkey`) |
|
||||
/// | `PROVING_KEY` | Proving key bytes |
|
||||
/// | `VERIFICATION_KEY_PATH` | Path to the verification key (`.json`) |
|
||||
/// | `VERIFICATION_KEY` | Verification key bytes |
|
||||
/// | `CIRCUIT_DAT_PATH` | Path to the witness generator data |
|
||||
/// | `CIRCUIT_DAT` | Witness generator data bytes |
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```ignore
|
||||
/// lbc_common::circuit_artifacts!("POQ"); // uses LBC_POQ_LIB_DIR
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! circuit_artifacts {
|
||||
($circuit_stem:literal) => {
|
||||
pub mod artifacts {
|
||||
macro_rules! __circuit_file {
|
||||
($file:literal) => {
|
||||
concat!(env!(concat!("LBC_", $circuit_stem, "_LIB_DIR")), "/", $file)
|
||||
};
|
||||
}
|
||||
|
||||
pub const PROVING_KEY_PATH: &str = __circuit_file!("proving_key.zkey");
|
||||
pub static PROVING_KEY: &[u8] = include_bytes!(__circuit_file!("proving_key.zkey"));
|
||||
|
||||
pub const VERIFICATION_KEY_PATH: &str = __circuit_file!("verification_key.json");
|
||||
pub static VERIFICATION_KEY: &[u8] =
|
||||
include_bytes!(__circuit_file!("verification_key.json"));
|
||||
|
||||
pub const CIRCUIT_DAT_PATH: &str = __circuit_file!("witness_generator.dat");
|
||||
pub static CIRCUIT_DAT: &[u8] =
|
||||
include_bytes!(__circuit_file!("witness_generator.dat"));
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
pub mod artifacts;
|
||||
pub mod string;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod ffi;
|
||||
pub mod native;
|
||||
|
||||
pub use native::{PocWitnessInput, generate_witness, generate_witness_from_files};
|
||||
pub use native::{PocWitnessInput, artifacts, generate_witness, generate_witness_from_files};
|
||||
|
||||
@ -8,12 +8,11 @@ use lbc_types::{
|
||||
|
||||
use crate::ffi::{poc_generate_witness, poc_generate_witness_from_files};
|
||||
|
||||
static RAW_CIRCUIT_DAT: &[u8] =
|
||||
include_bytes!(concat!(env!("LBC_POC_LIB_DIR"), "/witness_generator.dat"));
|
||||
lbc_common::circuit_artifacts!("POC");
|
||||
|
||||
pub struct PocDat;
|
||||
impl<'dat> lbc_types::CircuitDat<'dat> for PocDat {
|
||||
const DAT: &'dat [u8] = RAW_CIRCUIT_DAT;
|
||||
const DAT: &'dat [u8] = artifacts::CIRCUIT_DAT;
|
||||
}
|
||||
|
||||
pub type PocWitnessInput<'dat> = lbc_types::CircuitWitnessInput<'dat, PocDat>;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod ffi;
|
||||
pub mod native;
|
||||
|
||||
pub use native::{PolWitnessInput, generate_witness, generate_witness_from_files};
|
||||
pub use native::{PolWitnessInput, artifacts, generate_witness, generate_witness_from_files};
|
||||
|
||||
@ -8,12 +8,11 @@ use lbc_types::{
|
||||
|
||||
use crate::ffi::{pol_generate_witness, pol_generate_witness_from_files};
|
||||
|
||||
static RAW_CIRCUIT_DAT: &[u8] =
|
||||
include_bytes!(concat!(env!("LBC_POL_LIB_DIR"), "/witness_generator.dat"));
|
||||
lbc_common::circuit_artifacts!("POL");
|
||||
|
||||
pub struct PolDat;
|
||||
impl<'dat> lbc_types::CircuitDat<'dat> for PolDat {
|
||||
const DAT: &'dat [u8] = RAW_CIRCUIT_DAT;
|
||||
const DAT: &'dat [u8] = artifacts::CIRCUIT_DAT;
|
||||
}
|
||||
|
||||
pub type PolWitnessInput<'dat> = lbc_types::CircuitWitnessInput<'dat, PolDat>;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod ffi;
|
||||
pub mod native;
|
||||
|
||||
pub use native::{PoqWitnessInput, generate_witness, generate_witness_from_files};
|
||||
pub use native::{PoqWitnessInput, artifacts, generate_witness, generate_witness_from_files};
|
||||
|
||||
@ -8,12 +8,11 @@ use lbc_types::{
|
||||
|
||||
use crate::ffi::{poq_generate_witness, poq_generate_witness_from_files};
|
||||
|
||||
static RAW_CIRCUIT_DAT: &[u8] =
|
||||
include_bytes!(concat!(env!("LBC_POQ_LIB_DIR"), "/witness_generator.dat"));
|
||||
lbc_common::circuit_artifacts!("POQ");
|
||||
|
||||
pub struct PoqDat;
|
||||
impl<'dat> lbc_types::CircuitDat<'dat> for PoqDat {
|
||||
const DAT: &'dat [u8] = RAW_CIRCUIT_DAT;
|
||||
const DAT: &'dat [u8] = artifacts::CIRCUIT_DAT;
|
||||
}
|
||||
|
||||
pub type PoqWitnessInput<'dat> = lbc_types::CircuitWitnessInput<'dat, PoqDat>;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod ffi;
|
||||
pub mod native;
|
||||
|
||||
pub use native::{SignatureWitnessInput, generate_witness, generate_witness_from_files};
|
||||
pub use native::{SignatureWitnessInput, artifacts, generate_witness, generate_witness_from_files};
|
||||
|
||||
@ -8,14 +8,11 @@ use lbc_types::{
|
||||
|
||||
use crate::ffi::{signature_generate_witness, signature_generate_witness_from_files};
|
||||
|
||||
static RAW_CIRCUIT_DAT: &[u8] = include_bytes!(concat!(
|
||||
env!("LBC_SIGNATURE_LIB_DIR"),
|
||||
"/witness_generator.dat"
|
||||
));
|
||||
lbc_common::circuit_artifacts!("SIGNATURE");
|
||||
|
||||
pub struct SignatureDat;
|
||||
impl<'dat> lbc_types::CircuitDat<'dat> for SignatureDat {
|
||||
const DAT: &'dat [u8] = RAW_CIRCUIT_DAT;
|
||||
const DAT: &'dat [u8] = artifacts::CIRCUIT_DAT;
|
||||
}
|
||||
|
||||
pub type SignatureWitnessInput<'dat> = lbc_types::CircuitWitnessInput<'dat, SignatureDat>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user