Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init default zkp packer #56

Merged
merged 2 commits into from
Oct 4, 2024
Merged

Conversation

ilya-korotya
Copy link
Contributor

Next Steps for Improvement:

  1. Default Function for Verification Setup:

    • Currently, we can create a default function for the verification setup. This means we can instantiate a ZkpPacker with verification functionality. However, we face limitations when trying to create a default function for the proofing setup.
    • The issue arises because the process of finding the identity by ID (to retrieve the authentication keys) and preparing the inputs is intertwined. This means we can't provide a default algorithm for preparing inputs, as the identity-finding algorithm would be embedded in the process.

    Example:

    func(hash []byte, id *w3c.DID, circuitID circuits.CircuitID) ([]byte, error)

    Current implementation:

    func (p *Proof) prepareAuthV2Circuit(ctx context.Context, identifier *w3c.DID,
        challenge *big.Int) (circuits.AuthV2Inputs, error) {
    
        authClaim, err := p.claimService.GetAuthClaim(ctx, identifier)
        if err != nil {
            return circuits.AuthV2Inputs{}, err
        }
    
        authClaimData, err := p.fillAuthClaimData(ctx, identifier, authClaim)
        if err != nil {
            return circuits.AuthV2Inputs{}, err
        }
    
        signature, err := p.signChallange(ctx, authClaim, challenge)
        if err != nil {
            return circuits.AuthV2Inputs{}, err
        }
    
        globalTree, err := populateGlobalTree(ctx, identifier, p.stateService)
        if err != nil {
            return circuits.AuthV2Inputs{}, err
        }
    
        return prepareAuthV2CircuitInputs(identifier, authClaimData,
            challenge, signature, globalTree)
    }

    Proposed refactor:

    func (p *Proof) prepareAuthV2Circuit(ctx context.Context, authClaim *auth.Claim, challenge *big.Int)
    • By refactoring in this way, we can move the identity-finding algorithm to a higher level. This allows for a more flexible proof setup with default inputs preparation.
  2. Flexible Management of Default Packagers:

    • We need to improve the flexibility in managing default packagers. Consider the example for AuthV2Groth16. Users may want to work with:
      1. Only unpacker functionality (requires only the verification key).
      2. Only packer functionality (requires only the proving key and witness file).
      3. Both packer and unpacker functionalities.

    Possible solutions:

    • Simple implementation (but risk of users using wrong packer for verification or proofing keys):

      func TestConstructors() {
          AuthV2 = NewDefaultAuthV2(resolver, verificationKey, nil) // for verification only, default verification function inside
          AuthV3 = NewDefaultAuthV3(resolver, nil, provingKey) // for proofing only, default proofing function inside
      
          v := map[jwz.ProvingMethodAlg]VerificationParams
          p := map[jwz.ProvingMethodAlg]ProvingParams
          v[AuthV2.Key] = AuthV2.VerificationParams()
          p[AuthV3.Key] = AuthV3.ProvingParams()
      }
    • Mid-level complexity for developers, easier for users:

      func TestConsumer() {
          v := map[jwz.ProvingMethodAlg]VerificationParams
          p := map[jwz.ProvingMethodAlg]ProvingParams
          v.Set(AuthV2)
          p.Set(AuthV3)
      }
    • Both solutions are easy to extend. We just need to add new constructors for new authentication circuits, or even non-authentication circuits.

packers/zkp.go Outdated
@@ -237,3 +240,83 @@ func unmarshalPubSignals(obj circuits.PubSignalsUnmarshaller, pubSignals []strin
func (p *ZKPPacker) MediaType() iden3comm.MediaType {
return MediaTypeZKPMessage
}

// DefaultZKPPakcerOption is a function that sets the default ZKP packer options
type DefaultZKPPakcerOption func(*defaultZKPPacker)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pakcer

packers/zkp.go Outdated
return errors.Errorf("error getting global state info by state '%s': %v",
globalState, err)
}
// if (big.NewInt(0)).Cmp(globalStateInfo.CreatedAtTimestamp) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code

packers/zkp.go Outdated Show resolved Hide resolved
packers/zkp.go Outdated
}

// DefaultZKPPacker creates a default ZKP packer with the provided verification key and resolvers
func DefaultZKPPacker(verificationKey []byte, resolvers map[int]eth.Resolver, opts ...DefaultZKPPakcerOption) *ZKPPacker {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we have resolvers as option and as explicit parameter?

@vmidyllic
Copy link
Contributor

regarding that

    authClaim, err := p.claimService.GetAuthClaim(ctx, identifier)
    if err != nil {
        return circuits.AuthV2Inputs{}, err
    }```
    
    We should not add any reference to 'claim' as a part of interface.
    You are free to use any signing alg for identity if circuit will support it.
    so maybe signer functuin be good enough to pass.
    
    On the other hand maybe it will be a circuit that doesn't require signature at all, maybe some mtp.
    That is why current approach with id param is ok.
    
    

@vmidyllic
Copy link
Contributor

vmidyllic commented Sep 20, 2024

func TestConsumer() {
    v := map[jwz.ProvingMethodAlg]VerificationParams
    p := map[jwz.ProvingMethodAlg]ProvingParams
    v.Set(AuthV2)
    p.Set(AuthV3)
}

This I like much more. And Iden3comm package in this case should extend go-circuits structure

@vmidyllic vmidyllic merged commit f2336de into main Oct 4, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants