From 60e341912f0fbfd163782852438385fe737d54f3 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Mon, 11 Dec 2023 11:26:27 -0700 Subject: [PATCH] add mpack proof func --- src/storage_proofs.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/storage_proofs.rs b/src/storage_proofs.rs index 09bd570..cb06ff6 100644 --- a/src/storage_proofs.rs +++ b/src/storage_proofs.rs @@ -81,6 +81,44 @@ impl StorageProofs { Ok(()) } + pub fn prove_mpack( + &mut self, + proof_bytes: &mut Vec, + public_inputs_bytes: &mut Vec, + ) -> Result<(), String> { + + let mut builder = self.builder.clone(); + + // vec of vecs is flattened, since wasm expects a contiguous array in memory + + // chunks.iter().for_each(|c| builder.push_input("chunks", *c)); + + // siblings + // .iter() + // .for_each(|c| builder.push_input("siblings", *c)); + + // hashes.iter().for_each(|c| builder.push_input("hashes", *c)); + + // path.iter().for_each(|c| builder.push_input("path", *c)); + + // builder.push_input("root", root); + // builder.push_input("salt", salt); + + let circuit = builder.build() + .map_err(|e| e.to_string())?; + let inputs = circuit + .get_public_inputs() + .ok_or("Unable to get public inputs!")?; + let proof = prove(circuit, &self.params, &mut self.rng).map_err(|e| e.to_string())?; + + proof.serialize(proof_bytes).map_err(|e| e.to_string())?; + inputs + .serialize(public_inputs_bytes) + .map_err(|e| e.to_string())?; + + Ok(()) + } + pub fn verify( &mut self, proof_bytes: RR,