From 2bb54b79e7acb5c078ae0418807aaf812ee282d7 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 20 Jan 2024 15:27:45 -0600 Subject: [PATCH] adding support to read from byte buffers --- src/circom/builder.rs | 12 +++++++++++- src/witness/witness_calculator.rs | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/circom/builder.rs b/src/circom/builder.rs index 670e22b..b71378d 100644 --- a/src/circom/builder.rs +++ b/src/circom/builder.rs @@ -1,5 +1,5 @@ use ark_ec::pairing::Pairing; -use std::{fs::File, path::Path}; +use std::{fs::File, path::Path, io::Cursor}; use super::{CircomCircuit, R1CS}; @@ -34,6 +34,16 @@ impl CircomConfig { sanity_check: false, }) } + + pub fn new_from_bytes(wtns: &[u8], r1cs: &[u8]) -> Result { + let wtns = WitnessCalculator::from_bytes(wtns).unwrap(); + let r1cs = R1CSFile::new(Cursor::new(r1cs))?.into(); + Ok(Self { + wtns, + r1cs, + sanity_check: false, + }) + } } impl CircomBuilder { diff --git a/src/witness/witness_calculator.rs b/src/witness/witness_calculator.rs index 49582b9..a296b8b 100644 --- a/src/witness/witness_calculator.rs +++ b/src/witness/witness_calculator.rs @@ -57,6 +57,12 @@ impl WitnessCalculator { Self::from_file(path) } + pub fn from_bytes(bytes: &[u8]) -> Result { + let store = Store::default(); + let module = Module::new(&store, bytes)?; + Self::from_module(module) + } + pub fn from_file(path: impl AsRef) -> Result { let store = Store::default(); let module = Module::from_file(&store, path)?;