adding support to read from byte buffers

This commit is contained in:
Dmitriy Ryajov 2024-01-20 15:27:45 -06:00
parent 03939d583e
commit c148bd106a
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,6 @@
use ark_ff::PrimeField;
use num_bigint::BigInt;
use std::{collections::HashMap, fs::File, io::BufReader, path::Path};
use std::{collections::HashMap, fs::File, io::{BufReader, Cursor}, path::Path};
use wasmer::Store;
use super::{CircomCircuit, R1CS};
@ -53,12 +53,14 @@ impl<F: PrimeField> CircomConfig<F> {
})
}
pub fn from_bytes(wtns: &[u8], r1cs: &[u8]) -> Result<Self> {
let wtns = WitnessCalculator::from_bytes(wtns).unwrap();
pub fn new_from_bytes(wtns: &[u8], r1cs: &[u8]) -> Result<Self> {
let mut store = Store::default();
let wtns = WitnessCalculator::from_bytes(&mut store, wtns).unwrap();
let r1cs = R1CSFile::new(Cursor::new(r1cs))?.into();
Ok(Self {
wtns,
r1cs,
store,
sanity_check: false,
})
}

View File

@ -55,6 +55,11 @@ impl WitnessCalculator {
Self::from_module(store, module)
}
pub fn from_file(store: &mut Store, path: impl AsRef<std::path::Path>) -> Result<Self> {
let module = Module::new(&store, bytes)?;
Self::from_module(store, module)
}
pub fn from_file(store: &mut Store, path: impl AsRef<std::path::Path>) -> Result<Self> {
let module = Module::from_file(&store, path)?;
Self::from_module(store, module)