mirror of
https://github.com/logos-storage/logos-storage-proofs.git
synced 2026-01-02 13:33:10 +00:00
re-add original prove for comparison
This commit is contained in:
parent
ce36442059
commit
dd115d484d
@ -50,7 +50,7 @@ impl StorageProofs {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prove(
|
||||
pub fn prove_mpack(
|
||||
&mut self,
|
||||
inputs: &[u8],
|
||||
proof_bytes: &mut Vec<u8>,
|
||||
@ -90,6 +90,46 @@ impl StorageProofs {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn prove(
|
||||
&mut self,
|
||||
chunks: &[U256],
|
||||
siblings: &[U256],
|
||||
hashes: &[U256],
|
||||
path: &[i32],
|
||||
root: U256,
|
||||
salt: U256,
|
||||
proof_bytes: &mut Vec<u8>,
|
||||
public_inputs_bytes: &mut Vec<u8>,
|
||||
) -> 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<RR: Read>(
|
||||
&mut self,
|
||||
proof_bytes: RR,
|
||||
@ -122,7 +162,8 @@ fn decode_u256(val: &rmpv::Value) -> Result<U256, String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_mpack_args(builder: &mut CircomBuilder<Params256Ty>, mut inputs: &[u8]) -> Result<(), String> {
|
||||
fn parse_mpack_args(builder: &mut CircomBuilder<Params256Ty>,
|
||||
mut inputs: &[u8]) -> Result<(), String> {
|
||||
let values: rmpv::Value = read_value(&mut inputs).map_err(|e| e.to_string())?;
|
||||
let args: &Vec<(rmpv::Value, rmpv::Value)> = match values.as_map() {
|
||||
Some(args) => args,
|
||||
@ -166,13 +207,6 @@ fn parse_mpack_args(builder: &mut CircomBuilder<Params256Ty>, mut inputs: &[u8])
|
||||
println!("done: name: {}", name);
|
||||
}
|
||||
},
|
||||
// directly add a (name,string) arg pair
|
||||
// ie, "path" => "/some/file/path"
|
||||
rmpv::Value::String(s) => {
|
||||
println!("deserde: string");
|
||||
let s = s.clone().into_bytes();
|
||||
s.iter().for_each(|c| builder.push_input(name, (*c) as i32));
|
||||
}
|
||||
// directly add a (name,u256) arg pair
|
||||
rmpv::Value::Ext(_, _) => {
|
||||
let n = decode_u256(val)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user