diff --git a/internal/service/handlers/authorize.go b/internal/service/handlers/authorize.go index 5245d66..62b559b 100644 --- a/internal/service/handlers/authorize.go +++ b/internal/service/handlers/authorize.go @@ -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 } diff --git a/internal/zkp/main.go b/internal/zkp/main.go index 83fbf1c..44c893d 100644 --- a/internal/zkp/main.go +++ b/internal/zkp/main.go @@ -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") }