Skip to content

Commit ab25058

Browse files
committed
refactor: separate ffis from code
refactor: rename libraries
1 parent d434ade commit ab25058

File tree

12 files changed

+63
-83
lines changed

12 files changed

+63
-83
lines changed

crates/batcher/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{env, path::PathBuf, process::Command};
22

3-
const GO_SRC: &str = "./verifiers_ffi/verifier.go";
3+
const GO_SRC: &str = "./go_verifiers_lib/verifier.go";
44
const GO_OUT: &str = "libverifier.a";
55
const GO_LIB: &str = "verifier";
66

File renamed without changes.
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
use aligned_sdk::common::types::ProvingSystemId;
2-
3-
#[derive(Copy, Clone, Debug)]
4-
#[repr(C)]
5-
pub struct ListRef {
6-
data: *const u8,
7-
len: usize,
8-
}
9-
10-
impl From<Vec<u8>> for ListRef {
11-
fn from(v: Vec<u8>) -> Self {
12-
Self::from(v.as_slice())
13-
}
14-
}
15-
16-
impl From<&Vec<u8>> for ListRef {
17-
fn from(v: &Vec<u8>) -> Self {
18-
Self::from(v.as_slice())
19-
}
20-
}
21-
22-
impl From<&[u8]> for ListRef {
23-
fn from(v: &[u8]) -> Self {
24-
let len = v.len();
25-
let data = v.as_ptr().cast();
26-
ListRef { data, len }
27-
}
28-
}
2+
use crate::ffi::circom_ffi::VerifyCircomGroth16ProofBN128;
293

304
pub fn verify_circom(
315
proving_system: &ProvingSystemId,
@@ -44,11 +18,3 @@ pub fn verify_circom(
4418
_ => false,
4519
}
4620
}
47-
48-
extern "C" {
49-
pub fn VerifyCircomGroth16ProofBN128(
50-
proof: ListRef,
51-
public_input: ListRef,
52-
verification_key: ListRef,
53-
) -> bool;
54-
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::ffi::list_ref::ListRef;
2+
3+
extern "C" {
4+
pub fn VerifyCircomGroth16ProofBN128(
5+
proof: ListRef,
6+
public_input: ListRef,
7+
verification_key: ListRef,
8+
) -> bool;
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::ffi::list_ref::ListRef;
2+
3+
extern "C" {
4+
pub fn VerifyPlonkProofBLS12_381(
5+
proof: ListRef,
6+
public_input: ListRef,
7+
verification_key: ListRef,
8+
) -> bool;
9+
pub fn VerifyPlonkProofBN254(
10+
proof: ListRef,
11+
public_input: ListRef,
12+
verification_key: ListRef,
13+
) -> bool;
14+
pub fn VerifyGroth16ProofBN254(
15+
proof: ListRef,
16+
public_input: ListRef,
17+
verification_key: ListRef,
18+
) -> bool;
19+
}

crates/batcher/src/ffi/list_ref.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#[derive(Copy, Clone, Debug)]
2+
#[repr(C)]
3+
pub struct ListRef {
4+
data: *const u8,
5+
len: usize,
6+
}
7+
8+
impl From<Vec<u8>> for ListRef {
9+
fn from(v: Vec<u8>) -> Self {
10+
Self::from(v.as_slice())
11+
}
12+
}
13+
14+
impl From<&Vec<u8>> for ListRef {
15+
fn from(v: &Vec<u8>) -> Self {
16+
Self::from(v.as_slice())
17+
}
18+
}
19+
20+
impl From<&[u8]> for ListRef {
21+
fn from(v: &[u8]) -> Self {
22+
let len = v.len();
23+
let data = v.as_ptr().cast();
24+
ListRef { data, len }
25+
}
26+
}

crates/batcher/src/ffi/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod list_ref;
2+
pub mod circom_ffi;
3+
pub mod gnark_ffi;

crates/batcher/src/gnark/mod.rs

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
use aligned_sdk::common::types::ProvingSystemId;
2-
3-
#[derive(Copy, Clone, Debug)]
4-
#[repr(C)]
5-
pub struct ListRef {
6-
data: *const u8,
7-
len: usize,
8-
}
9-
10-
impl From<Vec<u8>> for ListRef {
11-
fn from(v: Vec<u8>) -> Self {
12-
Self::from(v.as_slice())
13-
}
14-
}
15-
16-
impl From<&Vec<u8>> for ListRef {
17-
fn from(v: &Vec<u8>) -> Self {
18-
Self::from(v.as_slice())
19-
}
20-
}
21-
22-
impl From<&[u8]> for ListRef {
23-
fn from(v: &[u8]) -> Self {
24-
let len = v.len();
25-
let data = v.as_ptr().cast();
26-
ListRef { data, len }
27-
}
28-
}
2+
use crate::ffi::gnark_ffi::{VerifyGroth16ProofBN254, VerifyPlonkProofBLS12_381, VerifyPlonkProofBN254};
293

304
pub fn verify_gnark(
315
proving_system: &ProvingSystemId,
@@ -50,21 +24,3 @@ pub fn verify_gnark(
5024
_ => false,
5125
}
5226
}
53-
54-
extern "C" {
55-
pub fn VerifyPlonkProofBLS12_381(
56-
proof: ListRef,
57-
public_input: ListRef,
58-
verification_key: ListRef,
59-
) -> bool;
60-
pub fn VerifyPlonkProofBN254(
61-
proof: ListRef,
62-
public_input: ListRef,
63-
verification_key: ListRef,
64-
) -> bool;
65-
pub fn VerifyGroth16ProofBN254(
66-
proof: ListRef,
67-
public_input: ListRef,
68-
verification_key: ListRef,
69-
) -> bool;
70-
}

0 commit comments

Comments
 (0)