From aac457c262073bb2aa877799eb1f0c827d958c70 Mon Sep 17 00:00:00 2001 From: chabanyknikita Date: Mon, 30 Sep 2024 16:07:19 +0300 Subject: [PATCH] fix decimal to utf8 convertion and add error handling in convert event-data --- internal/service/handlers/helpers/proof_params.go | 11 +++++------ .../service/handlers/verification_callback_light.go | 7 ++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/service/handlers/helpers/proof_params.go b/internal/service/handlers/helpers/proof_params.go index 85bd224..13ca972 100644 --- a/internal/service/handlers/helpers/proof_params.go +++ b/internal/service/handlers/helpers/proof_params.go @@ -8,7 +8,6 @@ import ( zk "github.com/rarimo/zkverifier-kit" "github.com/status-im/keycard-go/hexutils" "math/big" - "strconv" "time" ) @@ -65,12 +64,12 @@ func Utf8ToHex(input string) string { } func DecimalToHexToUtf8(input string) (string, error) { - inputDecimal, err := strconv.Atoi(input) - if err != nil { - return "", fmt.Errorf("failde to convert input string to decimal: %w", err) - + inputBig, ok := new(big.Int).SetString(input, 10) + if !ok { + return "", fmt.Errorf("failed to parse big int when converting to UTF8") } - inputUtf8 := string(hexutils.HexToBytes(strconv.FormatInt(int64(inputDecimal), 16))) + + inputUtf8 := string(inputBig.Bytes()) return inputUtf8, nil } diff --git a/internal/service/handlers/verification_callback_light.go b/internal/service/handlers/verification_callback_light.go index 077171f..87cde3b 100644 --- a/internal/service/handlers/verification_callback_light.go +++ b/internal/service/handlers/verification_callback_light.go @@ -59,7 +59,12 @@ func VerificationSignatureCallback(w http.ResponseWriter, r *http.Request) { return } - userIDHashDecimal, _ := new(big.Int).SetString(pubSignals[10], 10) + userIDHashDecimal, ok := new(big.Int).SetString(pubSignals[10], 10) + if !ok { + Log(r).Error("failed to parse event data") + ape.RenderErr(w, problems.BadRequest(err)...) + return + } var eventDataBytes [32]byte userIDHashDecimal.FillBytes(eventDataBytes[:])