Skip to content

firstbatchxyz/hollowdb-prover-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

HollowDB Prover

Proof generator crate for HollowDB.

License: MIT Docs GitHub: HollowDB Discord

Usage

We use ark_circom to generate Groth16 proofs for HollowDB. PLONK is not supported as of yet.

Generating Proofs

To create a prover:

let prover = HollowProver::new(
    wasmPath,
    r1csPath,
    proverKeyPath,
)?;

The prove function accepts any type for the current value and next value, where the inputs will be stringified and then hashed. The resulting string should match that of JSON.stringify in JavaScript. Here is an example of creating a proof:

#[derive(Serialize)]
struct MyStruct {
    foo: i32,
    bar: bool,
    baz: String,
}

let preimage = BigUint::from_str("123456789")?;
let cur_value = MyStruct {
    foo: 123,
    bar: true,
    baz: "zab".to_owned(),
};
let next_value = MyStruct {
    foo: 789,
    bar: false,
    baz: "baz".to_owned(),
};

let (proof, public_signals) = prover.prove(preimage, cur_value, next_value)?;

Note that if you are using the value at both JS and Rust, you need to ensure that keys are ordered the same so that the resulting hashes match.

Computing Key

To compute the key (i.e. the Poseidon hash of your preimage) without generating a proof, you can use the ComputeKey function.

let preimage = BigUint::from_str("123456789")?;
let key = compute_key(preimage)?;

Hashing to Group

If you would like to compute the hashes manually, you can use hash_to_group function. It accepts any argument that is serializable.

Testing

Running the tests will generate a proof and public signals under out folder, which can be verified using SnarkJS. You can run all tests with:

yarn test

which will run all tests, and then run SnarkJS to verify the resulting proofs. To verify generated proofs you can also type yarn verify. To run tests without SnarkJS, you can do:

cargo test --release

Note that due to an issue in ark-circom we have to run in release mode, otherwise it hangs.

See Also

We have prover implementations in Go and JavaScript as well:

Releases

No releases published

Packages

No packages published

Languages