Skip to content

Commit

Permalink
Merge pull request #51 from worldcoin/dcbuild3r/deletion_trusted_setu…
Browse files Browse the repository at this point in the history
…p_fix

PRO-441: fix trusted setup import for deletion circuits
  • Loading branch information
dcbuild3r authored Dec 18, 2023
2 parents 9836c4d + d774e9d commit eab34ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
34 changes: 34 additions & 0 deletions prover/deletion_circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"worldcoin/gnark-mbu/prover/keccak"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
"github.com/reilabs/gnark-lean-extractor/v2/abstractor"
)

Expand Down Expand Up @@ -68,3 +70,35 @@ func (circuit *DeletionMbuCircuit) Define(api frontend.API) error {

return nil
}

func ImportDeletionSetup(treeDepth uint32, batchSize uint32, pkPath string, vkPath string) (*ProvingSystem, error) {
proofs := make([][]frontend.Variable, batchSize)
for i := 0; i < int(batchSize); i++ {
proofs[i] = make([]frontend.Variable, treeDepth)
}
circuit := DeletionMbuCircuit{
Depth: int(treeDepth),
BatchSize: int(batchSize),
DeletionIndices: make([]frontend.Variable, batchSize),
IdComms: make([]frontend.Variable, batchSize),
MerkleProofs: proofs,
}
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
return nil, err
}

pk, err := LoadProvingKey(pkPath)

if err != nil {
return nil, err
}

vk, err := LoadVerifyingKey(vkPath)

if err != nil {
return nil, err
}

return &ProvingSystem{treeDepth, batchSize, pk, vk, ccs}, nil
}
31 changes: 0 additions & 31 deletions prover/deletion_proving_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,34 +143,3 @@ func (ps *ProvingSystem) VerifyDeletion(inputHash big.Int, proof *Proof) error {
}
return groth16.Verify(proof.Proof, ps.VerifyingKey, witness)
}

func ImportDeletionSetup(treeDepth uint32, batchSize uint32, pkPath string, vkPath string) (*ProvingSystem, error) {
proofs := make([][]frontend.Variable, batchSize)
for i := 0; i < int(batchSize); i++ {
proofs[i] = make([]frontend.Variable, treeDepth)
}
circuit := DeletionMbuCircuit{
Depth: int(treeDepth),
BatchSize: int(batchSize),
IdComms: make([]frontend.Variable, batchSize),
MerkleProofs: proofs,
}
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
return nil, err
}

pk, err := LoadProvingKey(pkPath)

if err != nil {
return nil, err
}

vk, err := LoadVerifyingKey(vkPath)

if err != nil {
return nil, err
}

return &ProvingSystem{treeDepth, batchSize, pk, vk, ccs}, nil
}

0 comments on commit eab34ad

Please sign in to comment.