Skip to content

Commit

Permalink
Add viable logging on proof verification error
Browse files Browse the repository at this point in the history
  • Loading branch information
violog committed Jun 20, 2024
1 parent 459518d commit f88cef3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion internal/service/handlers/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func Authorize(w http.ResponseWriter, r *http.Request) {
return
}

if err := Verifier(r).VerifyProof(new(big.Int).SetBytes(nullifier).String(), &proof); err != nil {
if err = Verifier(r).VerifyProof(new(big.Int).SetBytes(nullifier).String(), &proof); err != nil {
Log(r).WithError(err).Info("Failed to verify proof")
ape.RenderErr(w, problems.Unauthorized())
return
}
Expand Down
16 changes: 11 additions & 5 deletions internal/zkp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ func (v *Verifier) VerifyProof(user string, proof *zkptypes.ZKProof) (err error)

// no error can appear
chal, _ := base64.StdEncoding.DecodeString(challenge.Value)
chalDec := new(big.Int).SetBytes(chal).String()

switch {
case proof.PubSignals[NullifierSignalsIndex] != user:
return fmt.Errorf("expected user=%s, got %s", user, proof.PubSignals[NullifierSignalsIndex])
case proof.PubSignals[EventIDSignalsIndex] != EventID:
return fmt.Errorf("expected eventID=%s, got %s", EventID, proof.PubSignals[EventIDSignalsIndex])
case proof.PubSignals[EventDataSignalsIndex] != chalDec:
return fmt.Errorf("expected challenge=%s, got %s", chalDec, proof.PubSignals[EventDataSignalsIndex])
}

proof.PubSignals[NullifierSignalsIndex] = user
proof.PubSignals[EventIDSignalsIndex] = EventID
proof.PubSignals[EventDataSignalsIndex] = new(big.Int).SetBytes(chal).String()

if err := verifier.VerifyGroth16(*proof, verificationKey); err != nil {
if err = verifier.VerifyGroth16(*proof, verificationKey); err != nil {
return errors.Wrap(err, "failed to verify generated proof")
}

Expand Down

0 comments on commit f88cef3

Please sign in to comment.