https://github.com/firstbatchxyz/hollowdb-prover-go
Zero-knowledge prover utility for HollowDB.
https://github.com/firstbatchxyz/hollowdb-prover-go
circom go groth16 hollowdb zero-knowledge
Last synced: 25 days ago
JSON representation
Zero-knowledge prover utility for HollowDB.
- Host: GitHub
- URL: https://github.com/firstbatchxyz/hollowdb-prover-go
- Owner: firstbatchxyz
- Created: 2023-08-03T12:43:52.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-29T10:38:41.000Z (almost 3 years ago)
- Last Synced: 2025-01-12T05:28:30.506Z (over 1 year ago)
- Topics: circom, go, groth16, hollowdb, zero-knowledge
- Language: Go
- Homepage: https://docs.hollowdb.xyz/
- Size: 1.07 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
HollowDB Prover
Proof generator package for HollowDB.
## Usage
We use [Go RapidSnark](https://github.com/iden3/go-rapidsnark) to create witnesses and generate Groth16 proofs. As for the WASM execution engine, it currently uses [RapidSnark Wasmer](https://github.com/iden3/go-rapidsnark/tree/main/witness/wasmer). The prover does not support PLONK at the moment.
### Generating Proofs
To create a prover:
```go
prover, err := hollowprover.Prover(wasmPath, pkeyPath)
```
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:
```go
proof, publicSignals, err := prover.Prove(
preimage,
map[string]interface{}{
"foo": 123,
"hollow": true,
"awesome": "yes",
},
map[string]interface{}{
"foo": 123789789,
"hollow": false,
"awesome": "yes",
})
```
The resulting proof and public signals are stringified JSON objects.
The user must be aware of the following with regards to Go's JSON marshalling logic with respect to the user inputs:
- Maps have their keys sorted lexicographically
- Structs keys are marshalled in the order defined in the struct
The effect of this is that if you have the following object `{b: 1, a: 2}` in a Map then Go will stringify it as `{"a":2,"b":1}` but JavaScript may have it as `{"b":1,"a":2}`, resulting in different hashes of the "same" object! We suggest using struct for the inputs to the prover, but if you really have to use maps you can perhaps hash them elsewhere with more care on their keys, and then use `proveHashed` function.
### Computing Key
To compute the key (i.e. the Poseidon hash of your preimage) without generating a proof, you can use the `ComputeKey` function.
```go
preimage, ok := new(big.Int).SetString("0xDEADBEEF", 0)
key, err := hollowprover.ComputeKey(preimage)
```
### Hashing to Group
If you would like to compute the hashes manually, you can use `HashToGroup` function.
```go
hash, err := hollowprover.HashToGroup(
// accepts anything!
struct {
Foo int `json:"foo"`
Bar bool `json:"bar"`
Baz string `json:"baz"`
}{
123,
true,
"zab",
})
```
Notice that the JSON field names must be provided if you are using a struct, so that they can be stringified.
## Testing
Running the Go tests will generate a proof and public signals under `out` folder, which can be verified using SnarkJS. You can run all tests with:
```sh
yarn test
```
which will run Go tests, and then run SnarkJS to verify the proofs. To verify generated proofs you can also type `yarn verify`. To run Go tests without SnarkJS, you can do:
```sh
go test ./test/*.go -test.v
```
You can also run benchmarks with:
```sh
go test -bench=.
```
## See Also
We have prover implementations in Rust and JavaScript as well:
- [Rust](https://github.com/firstbatchxyz/hollowdb-prover-rust)
- [JavaScript](https://github.com/firstbatchxyz/hollowdb-prover)