Skip to content

firstbatchxyz/hollowdb-prover-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

HollowDB Prover

Proof generator package for HollowDB.

License: MIT Docs GitHub: HollowDB Discord

Usage

We use Go RapidSnark to create witnesses and generate Groth16 proofs. As for the WASM execution engine, it currently uses RapidSnark Wasmer. The prover does not support PLONK at the moment.

Generating Proofs

To create a prover:

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:

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.

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.

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:

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:

go test ./test/*.go -test.v

You can also run benchmarks with:

go test -bench=.

See Also

We have prover implementations in Rust and JavaScript as well:

Releases

No releases published

Packages

No packages published

Languages