Skip to content

Commit

Permalink
Merge pull request zcash#92 from filecoin-project/feat/api
Browse files Browse the repository at this point in the history
Initial API placeholder.
  • Loading branch information
porcuquine authored Jul 19, 2018
2 parents 077bad9 + ac5c59e commit f96cdc6
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = ["dignifiedquire <[email protected]>"]
sapling-crypto = { git = "https://github.com/zcash-hackworks/sapling-crypto", branch = "master" }
rand = "0.4"
ring = "0.12"
libc = "0.2"
merkle_light = { git = "https://github.com/dignifiedquire/merkle_light", branch = "master" }
openssl = "*"
failure = "0.1"
Expand Down
89 changes: 89 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use libc;
use std::ffi::{CStr, CString};

type CstrT = *const libc::c_char;

type SectorID = i32;
type Commitment = u32;
type ProverID = [u8; 31];

type SectorAccess = CstrT;
type SectorAccessor = extern "C" fn(i: SectorID) -> CstrT;

fn from_cstr(c_str: CstrT) -> String {
unsafe {
CStr::from_ptr(c_str)
.to_string_lossy()
.to_owned()
.to_string()
}
}

fn to_cstr(s: &str) -> CstrT {
CString::new(s).unwrap().as_ptr()
}

const DUMMY_COMM_R: Commitment = 12345;
const DUMMY_COMM_D: Commitment = 54321;

#[no_mangle]
pub extern "C" fn seal(
sector_id: SectorID,
unsealed: SectorAccessor,
sealed: SectorAccessor,
_prover_id: ProverID,
_challenge_seed: [u32; 8],
_random_seed: [u32; 8],
) -> [Commitment; 2] {
let _in_path = from_cstr(unsealed(sector_id));
let _out_path = from_cstr(sealed(sector_id));

[DUMMY_COMM_R, DUMMY_COMM_D]
}

#[no_mangle]
pub extern "C" fn verifySeal(comm_r: Commitment, comm_d: Commitment) -> bool {
comm_r == DUMMY_COMM_R && comm_d == DUMMY_COMM_D
}

#[no_mangle]
pub extern "C" fn unseal() {
unimplemented!()
}

#[no_mangle]
pub extern "C" fn generatePost() {
unimplemented!()
}

#[no_mangle]
pub extern "C" fn verifyPost() {
unimplemented!()
}

#[cfg(test)]
mod tests {
use super::*;

extern "C" fn sector_accessor(id: SectorID) -> SectorAccess {
let path = format!("sector{}", id);
println!("received path for {}: {}", id, path);
to_cstr(&path)
}

#[test]
fn seal_verify() {
let comms = seal(
123,
sector_accessor,
sector_accessor,
[1; 31],
[2; 8],
[3; 8],
);

assert_ne!(comms[0], comms[1]);
assert!(verifySeal(comms[0], comms[1]));
assert!(!verifySeal(comms[1], comms[0]));
}
}
2 changes: 1 addition & 1 deletion src/circuit/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn hash_lc<E: Engine>(terms: &[(Variable, E::Fr)], h: &mut Blake2s) {
}
}

fn eval_lc2<E: Engine>(terms: &[(Variable, E::Fr)], inputs: &[E::Fr], aux: &[E::Fr]) -> E::Fr {
fn _eval_lc2<E: Engine>(terms: &[(Variable, E::Fr)], inputs: &[E::Fr], aux: &[E::Fr]) -> E::Fr {
let mut acc = E::Fr::zero();

for &(var, ref coeff) in terms {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate lazy_static;
extern crate bellman;
extern crate blake2_rfc;
extern crate byteorder;
extern crate libc;
extern crate memmap;
extern crate merkle_light;
extern crate num_bigint;
Expand Down Expand Up @@ -36,8 +37,8 @@ pub mod test_helper;

pub mod example_helper;

pub mod api;
pub mod batchpost;

pub mod circuit;
pub mod compound_proof;
pub mod crypto;
Expand Down

0 comments on commit f96cdc6

Please sign in to comment.