Merge pull request #8 from zkmopro/dylib

feat: link to dylib
This commit is contained in:
Ya-wen, Jeng 2025-03-07 11:34:01 +08:00 committed by GitHub
commit bc0e6fa351
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 5 deletions

View File

@ -15,6 +15,7 @@ env:
jobs:
clippy_check:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
env:
RUSTFLAGS: "-Dwarnings" # Make sure CI fails on all warnings, including Clippy lints
steps:

View File

@ -60,6 +60,15 @@ fn main() {
println!("cargo:rustc-link-lib=static=fq");
println!("cargo:rustc-link-lib=static=gmp");
if !(env::var("CARGO_CFG_TARGET_OS").unwrap().contains("ios")
|| env::var("CARGO_CFG_TARGET_OS").unwrap().contains("android"))
{
println!("cargo:rustc-link-lib=dylib=rapidsnark");
println!("cargo:rustc-link-lib=dylib=fr");
println!("cargo:rustc-link-lib=dylib=fq");
println!("cargo:rustc-link-lib=dylib=gmp");
}
// refer to https://github.com/bbqsrc/cargo-ndk to see how to link the libc++_shared.so file in Android
if env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
android();

View File

@ -116,6 +116,7 @@ pub fn groth16_prover_zkey_file_wrapper(
zkey_path: &str,
wtns_buffer: Vec<u8>,
) -> Result<ProofResult> {
let formatted_zkey_path = std::ffi::CString::new(zkey_path).unwrap();
let wtns_size = wtns_buffer.len() as u64;
let mut proof_buffer = vec![0u8; 4 * 1024 * 1024]; // Adjust size as needed
@ -131,7 +132,7 @@ pub fn groth16_prover_zkey_file_wrapper(
unsafe {
let result = groth16_prover_zkey_file(
zkey_path.as_ptr() as *const std::ffi::c_char,
formatted_zkey_path.as_ptr() as *const std::ffi::c_char,
wtns_buffer.as_ptr() as *const std::os::raw::c_void, // Witness buffer
wtns_size,
proof_ptr,

View File

@ -56,7 +56,7 @@ mod tests {
#[test]
fn test_prove_rapidsnark() -> Result<()> {
// Create a new MoproCircom instance
let zkey_path = "./test-vectors/multiplier2_final.zkey".to_string();
let zkey_path = "./test-vectors/multiplier2_final.zkey";
let mut inputs = HashMap::new();
let a = BigInt::from_str(
@ -72,7 +72,7 @@ mod tests {
// Generate Proof
let proof_result =
rust_rapidsnark::groth16_prover_zkey_file_wrapper(&zkey_path, wtns_buffer)?;
rust_rapidsnark::groth16_prover_zkey_file_wrapper(zkey_path, wtns_buffer)?;
let vkey = std::fs::read_to_string("./test-vectors/multiplier2.vkey.json")?;
let valid = rust_rapidsnark::groth16_verify_wrapper(
@ -87,7 +87,7 @@ mod tests {
#[test]
fn test_prove_rapidsnark_keccak() -> Result<()> {
// Create a new MoproCircom instance
let zkey_path = "./test-vectors/keccak256_256_test_final.zkey".to_string();
let zkey_path = "./test-vectors/keccak256_256_test_final.zkey";
// Prepare inputs
let input_vec = vec![
116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -103,7 +103,7 @@ mod tests {
// Generate Proof
let proof_result =
rust_rapidsnark::groth16_prover_zkey_file_wrapper(&zkey_path, wtns_buffer)?;
rust_rapidsnark::groth16_prover_zkey_file_wrapper(zkey_path, wtns_buffer)?;
let vkey = std::fs::read_to_string("./test-vectors/keccak256_256_test.vkey.json")?;
let valid = rust_rapidsnark::groth16_verify_wrapper(