Skip to content

Instantly share code, notes, and snippets.

@miukki
Created June 17, 2021 06:00
Show Gist options
  • Save miukki/83f4e966fdb9861d20383139dfe9fe0f to your computer and use it in GitHub Desktop.
Save miukki/83f4e966fdb9861d20383139dfe9fe0f to your computer and use it in GitHub Desktop.
package circuit
import (
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/hash/mimc"
)
// Circuit defines a pre-image knowledge proof
// mimc(secret preImage) = public hash
type Circuit struct {
// struct tags on a variable is optional
// default uses variable name and secret visibility.
ByteSliceRecipient frontend.Variable
ByteSliceMissing1 frontend.Variable
ByteSliceMissing2 frontend.Variable
Hash frontend.Variable `gnark:",public"`
}
var OrderID = ""
// Define declares the circuit's constraints
func (circuit *Circuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
// hash function, with hardcoded order ID
mimcLoc, err := mimc.NewMiMC(OrderID, curveID)
if err != nil {
return err
}
// specify constraint using the missing complement slice
hx := mimcLoc.Hash(cs, circuit.ByteSliceRecipient, circuit.ByteSliceMissing1, circuit.ByteSliceMissing2)
cs.Println("debug circuit.ByteSliceMissing1", circuit.ByteSliceMissing1)
cs.Println("debug circuit.ByteSliceMissing2", circuit.ByteSliceMissing2)
cs.Println("debug hash", hx)
cs.Println("debug circuit.Hash", circuit.Hash)
cs.AssertIsEqual(circuit.Hash, hx)
return nil
}
//go:generate abigen --sol ../../../../registry-contract/contracts/Verifier.sol --pkg circuit --out wrapper.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment