mirror of
https://github.com/logos-blockchain/logos-blockchain-circuits.git
synced 2026-05-18 15:29:26 +00:00
Use dat slice.
This commit is contained in:
parent
f91bd073d1
commit
62c0c9fd0a
@ -0,0 +1,33 @@
|
||||
use std::path::PathBuf;
|
||||
use logos_blockchain_circuits_poq_sys::{generate_witness, generate_witness_from_files};
|
||||
use lbc_types::native::WitnessInput;
|
||||
|
||||
fn lib_dir() -> PathBuf {
|
||||
PathBuf::from(
|
||||
std::env::var("POQ_LIB_DIR").expect("POQ_LIB_DIR must point to the poq library directory"),
|
||||
)
|
||||
}
|
||||
|
||||
fn inputs_path() -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../blend/poq-input.json")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generate_witness_matches_from_files() {
|
||||
let dat = lib_dir().join("witness_generator");
|
||||
let inputs = inputs_path();
|
||||
let witness_path = std::env::temp_dir().join("poq_test_witness.wtns");
|
||||
|
||||
generate_witness_from_files(&dat, &inputs, &witness_path)
|
||||
.expect("generate_witness_from_files failed");
|
||||
|
||||
let dat_bytes = std::fs::read(dat.with_extension("dat"))
|
||||
.expect("failed to read witness_generator.dat");
|
||||
let inputs_json = std::fs::read_to_string(&inputs).expect("failed to read poq-input.json");
|
||||
|
||||
let input = WitnessInput::new(dat_bytes.as_slice(), inputs_json).expect("failed to construct WitnessInput");
|
||||
let output = generate_witness(input).expect("generate_witness failed");
|
||||
|
||||
let expected = std::fs::read(&witness_path).expect("failed to read witness output file");
|
||||
assert_eq!(output.as_slice(), expected.as_slice());
|
||||
}
|
||||
@ -3,15 +3,15 @@ use crate::ffi;
|
||||
use crate::native::Error;
|
||||
|
||||
/// Input for witness generators
|
||||
pub struct WitnessInput {
|
||||
pub struct WitnessInput<'a> {
|
||||
/// The circuit's dat file contents.
|
||||
dat: Vec<u8>,
|
||||
dat: &'a [u8],
|
||||
/// The JSON string containing the circuit inputs.
|
||||
inputs_json: CString,
|
||||
}
|
||||
|
||||
impl WitnessInput {
|
||||
pub fn new(dat: Vec<u8>, inputs_json: String) -> Result<Self, Error> {
|
||||
impl<'a> WitnessInput<'a> {
|
||||
pub fn new(dat: &'a [u8], inputs_json: String) -> Result<Self, Error> {
|
||||
let inputs_json = CString::new(inputs_json).map_err(
|
||||
|error| Error::InvalidInput(Some(
|
||||
format!("The parameter inputs_json could not be converted to CString: {}", error)
|
||||
@ -29,7 +29,7 @@ impl WitnessInput {
|
||||
/// Temporary FFI view of a [`WitnessInput`], which makes [`ffi::WitnessInput`] lifetime-aware.
|
||||
pub struct WitnessInputFfiGuard<'a> {
|
||||
ffi: ffi::WitnessInput,
|
||||
_lifetime: std::marker::PhantomData<&'a WitnessInput>,
|
||||
_lifetime: std::marker::PhantomData<&'a WitnessInput<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> WitnessInputFfiGuard<'a> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user