Skip to content

Commit

Permalink
Merge pull request #31 from iden3/feature/remove-verification-keys
Browse files Browse the repository at this point in the history
Feature/remove verification keys
  • Loading branch information
vmidyllic authored May 26, 2022
2 parents bba35ae + 0455edc commit 8cf46c0
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 1,686 deletions.
90 changes: 46 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,61 @@
# go-circuits

### WARNING
All code here is experimental and WIP

[![Go Reference](https://pkg.go.dev/badge/github.com/iden3/go-circuits.svg)](https://pkg.go.dev/github.com/iden3/go-circuits)
[![Go Report Card](https://goreportcard.com/badge/github.com/iden3/go-circuits)](https://goreportcard.com/report/github.com/iden3/go-circuits)
### General description:

The library goal is to create a wrapper on top of standard circuits set
The library goal is to create a wrapper for private and public inputs for identity circuits

Repository of circuits implementation: https://github.com/iden3/circuits

> Set of functionality for circuits inputs preparation, verification keys, and public signals schema retrieving
> Set of functionality for circuits inputs preparation, and public signals schema retrieving
>
### How to use :

- All circuits implement *InputsPreparer* and *BaseCircuit* Interfaces
- All circuits implement *InputsMarshaller* and *PubSignalsUnmarshal* Interfaces

```go
type InputsPreparer interface {
PrepareInputs(i TypedInputs) (map[string]interface{}, error)
}
type BaseCircuit interface {
InputsPreparer
GetVerificationKey() VerificationKeyJSON
GetPublicSignalsSchema() PublicSchemaJSON
}
type InputsMarshaller interface {
InputsMarshal() ([]byte, error)
}


type PubSignalsUnmarshaller interface {
PubSignalsUnmarshal(data []byte) error
}
```

- If you use an existing circuit

```go
circuitID := "credentialAtomicQuery"
circuitInputs := circuits.AtomicQueryInputs{
ID: ...,
AuthClaim: ...,
Challenge: ...,
Signature: ...,
Query: ...,
Claim: ...,
RevocationStatus: ...,
}
circuit, err := circuits.GetCircuit(circuits.CircuitID(circuitID))
if err != nil {
return nil, nil, err
}
inputs, err := circuit.PrepareInputs(circuitInputs)
if err != nil {
return nil, nil, err

- Example of usage:

At the moment you have to fill all needed attributes for a specific Inputs, take a look in test for each specific Input

```go
inputs := AuthInputs{
ID: identifier,
AuthClaim: Claim{
Claim: claim,
Proof: claimEntryMTP,
TreeState: treeState,
NonRevProof: &ClaimNonRevStatus{treeState, claimNonRevMTP},
},
Signature: signature,
Challenge: challenge,
}
```
circuitInputJSON, err := inputs.InputsMarshal() // marshal JSON inputs for specific circuit in proper format
```

- It’s easy to extend Circuits mapping through registering custom Circuit Wrapper implementation, but it must implement *BaseCircuit* interface
- It’s easy to extend Circuits mapping through registering custom Circuit Wrapper implementation

```go
RegisterCircuit(CustomQueryCircuitID, &CustomQueryCircuit{})
RegisterCircuit(CustomCircuitID, Data{
Input: CustomInputs{},
Output: &CustomPubSignals{},
})
```

### Querying :
Expand All @@ -63,17 +65,17 @@ Repository of circuits implementation: https://github.com/iden3/circuits
```go
// Query represents basic request to claim slot verification
type Query struct {
SlotIndex int
Value *big.Int
Operator int
SlotIndex int
Value *big.Int
Operator int
}
// QueryOperators represents operators for atomic circuits
var QueryOperators = map[string]int{
"$eq": 0,
"$lt": 1,
"$gt": 2,
"$ni": 3,
"$in": 4,
"$eq": 0,
"$lt": 1,
"$gt": 2,
"$ni": 3,
"$in": 4,
}
```
65 changes: 12 additions & 53 deletions circuits.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package circuits

import (
"embed"
"reflect"
"sync"

"github.com/pkg/errors"
)

var (
//go:embed verificationKeys
verificationKeysRes embed.FS
)

// CircuitID is alias for circuit identifier
type CircuitID string

Expand Down Expand Up @@ -55,37 +49,27 @@ func RegisterCircuit(id CircuitID, c Data) {
func init() {

RegisterCircuit(AuthCircuitID, Data{
Input: AuthInputs{},
Output: &AuthPubSignals{},
VerificationKey: embedFSLoader{"verificationKeys/auth.json"},
ProvingKey: nil,
Input: AuthInputs{},
Output: &AuthPubSignals{},
})

RegisterCircuit(StateTransitionCircuitID, Data{
Input: StateTransitionInputs{},
Output: &StateTransitionPubSignals{},
VerificationKey: embedFSLoader{"verificationKeys/stateTransition.json"},
ProvingKey: nil,
Input: StateTransitionInputs{},
Output: &StateTransitionPubSignals{},
})

RegisterCircuit(AtomicQueryMTPCircuitID, Data{
Input: AtomicQueryMTPInputs{},
Output: &AtomicQueryMTPPubSignals{},
VerificationKey: embedFSLoader{"verificationKeys/credentialAtomicQueryMTP.json"},
ProvingKey: nil,
Input: AtomicQueryMTPInputs{},
Output: &AtomicQueryMTPPubSignals{},
})

RegisterCircuit(AtomicQueryMTPWithRelayCircuitID, Data{
Input: AtomicQueryMTPWithRelayInputs{},
Output: &AtomicQueryMTPWithRelayPubSignals{},
VerificationKey: embedFSLoader{"verificationKeys/credentialAtomicQueryMTPWithRelay.json"},
ProvingKey: nil,
Input: AtomicQueryMTPWithRelayInputs{},
Output: &AtomicQueryMTPWithRelayPubSignals{},
})
RegisterCircuit(AtomicQuerySigCircuitID, Data{
Input: AtomicQuerySigInputs{},
Output: &AtomicQuerySigPubSignals{},
VerificationKey: embedFSLoader{"verificationKeys/credentialAtomicQuerySig.json"},
ProvingKey: nil,
Input: AtomicQuerySigInputs{},
Output: &AtomicQuerySigPubSignals{},
})
}

Expand Down Expand Up @@ -140,20 +124,8 @@ type KeyLoader interface {

// Data circuit type
type Data struct {
Input InputsMarshaller // input values type
Output PubSignals // output values type
VerificationKey KeyLoader
ProvingKey KeyLoader
}

// embedFSLoader read keys from embedded FS
type embedFSLoader struct {
path string
}

// Load keys from embedded FS
func (m embedFSLoader) Load() ([]byte, error) {
return verificationKeysRes.ReadFile(m.path)
Input InputsMarshaller // input values type
Output PubSignals // output values type
}

// UnmarshalCircuitOutput unmarshal bytes to specific circuit Output type associated with id
Expand Down Expand Up @@ -181,19 +153,6 @@ func UnmarshalCircuitOutput(id CircuitID, b []byte) (map[string]interface{}, err
return m, nil
}

// GetVerificationKey return verification key registered for given CircuitID
func GetVerificationKey(id CircuitID) ([]byte, error) {
circuitsLock.RLock()
defer circuitsLock.RUnlock()

circuit, ok := circuitsRegistry[id]
if !ok {
return nil, ErrorCircuitIDNotFound
}

return circuit.VerificationKey.Load()
}

// GetCircuit return circuit Data
func GetCircuit(id CircuitID) (*Data, error) {
circuitsLock.RLock()
Expand Down
9 changes: 0 additions & 9 deletions circuits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package circuits

import (
"encoding/json"
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -40,11 +39,3 @@ func TestUnmarshalCircuitOutput_Err(t *testing.T) {

assert.Equal(t, err, ErrorCircuitIDNotFound)
}

func TestGetVerificationKey(t *testing.T) {

got, err := GetVerificationKey(AuthCircuitID)
assert.NoError(t, err)

fmt.Println(string(got))
}
104 changes: 0 additions & 104 deletions verificationKeys/auth.json

This file was deleted.

Loading

0 comments on commit 8cf46c0

Please sign in to comment.