diff --git a/relayer/application_relayer.go b/relayer/application_relayer.go index 682f4772..8daecf58 100644 --- a/relayer/application_relayer.go +++ b/relayer/application_relayer.go @@ -209,6 +209,7 @@ func (r *ApplicationRelayer) ProcessMessage(handler messages.MessageHandler) (co // TODO: do we actually want to pass the pointer here or adapt the interface? signedMessage, err = r.signatureAggregator.AggregateSignaturesAppRequest( unsignedMessage, + make([]byte, 0), r.signingSubnetID, r.warpQuorum.QuorumNumerator, ) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 9c01176c..7077732e 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -72,6 +72,7 @@ func NewSignatureAggregator( func (s *SignatureAggregator) AggregateSignaturesAppRequest( unsignedMessage *avalancheWarp.UnsignedMessage, + justification []byte, inputSigningSubnet ids.ID, quorumPercentage uint64, ) (*avalancheWarp.Message, error) { diff --git a/signature-aggregator/api/api.go b/signature-aggregator/api/api.go index 0f48f23c..d5e4684a 100644 --- a/signature-aggregator/api/api.go +++ b/signature-aggregator/api/api.go @@ -25,8 +25,12 @@ const ( // Defines a request interface for signature aggregation for a raw unsigned message. // Currently a copy of the `ManualWarpMessageRequest` struct in relay_message.go type AggregateSignaturesByRawMsgRequest struct { - // Required. hex-encoded message, optionally prefixed with "0x". - UnsignedMessage string `json:"unsigned-message"` + // Required: either Message or Justification must be provided + + // hex-encoded message, optionally prefixed with "0x". + Message string `json:"message"` + // hex-encoded justification, optionally prefixed with "0x". + Justification string `json:"justification"` // Optional hex or cb58 encoded signing subnet ID. If omitted will default to the subnetID of the source BlockChain SigningSubnetID string `json:"signing-subnet-id"` // Optional. Integer from 0 to 100 representing the percentage of the quorum that is required to sign the message @@ -66,6 +70,15 @@ func writeJsonError( } } +func isEmptyOrZeroes(bytes []byte) bool { + for _, b := range bytes { + if b != 0 { + return false + } + } + return true +} + func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregator.SignatureAggregator) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var req AggregateSignaturesByRawMsgRequest @@ -78,25 +91,48 @@ func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregato } var decodedMessage []byte decodedMessage, err = hex.DecodeString( - strings.TrimPrefix(req.UnsignedMessage, "0x"), + strings.TrimPrefix(req.Message, "0x"), ) if err != nil { msg := "Could not decode message" logger.Warn( msg, - zap.String("msg", req.UnsignedMessage), + zap.String("msg", req.Message), zap.Error(err), ) writeJsonError(logger, w, msg) return } - unsignedMessage, err := types.UnpackWarpMessage(decodedMessage) + message, err := types.UnpackWarpMessage(decodedMessage) if err != nil { msg := "Error unpacking warp message" logger.Warn(msg, zap.Error(err)) writeJsonError(logger, w, msg) return } + + justification, err := hex.DecodeString( + strings.TrimPrefix(req.Justification, "0x"), + ) + if err != nil { + msg := "Could not decode justification" + logger.Warn( + msg, + zap.String("justification", req.Justification), + zap.Error(err), + ) + writeJsonError(logger, w, msg) + return + } + + if isEmptyOrZeroes(message.Bytes()) || isEmptyOrZeroes(justification) { + writeJsonError( + logger, + w, + "Must provide either message or justification", + ) + } + quorumNum := req.QuorumNum if quorumNum == 0 { quorumNum = defaultQuorumNum @@ -123,7 +159,8 @@ func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregato } signedMessage, err := aggregator.AggregateSignaturesAppRequest( - unsignedMessage, + message, + justification, signingSubnetID, quorumNum, ) diff --git a/tests/signature_aggregator_api.go b/tests/signature_aggregator_api.go index 205e3d1d..cd8ed9a9 100644 --- a/tests/signature_aggregator_api.go +++ b/tests/signature_aggregator_api.go @@ -56,7 +56,7 @@ func SignatureAggregatorAPI(network interfaces.LocalNetwork) { time.Sleep(5 * time.Second) reqBody := api.AggregateSignaturesByRawMsgRequest{ - UnsignedMessage: "0x" + hex.EncodeToString(warpMessage.Bytes()), + Message: "0x" + hex.EncodeToString(warpMessage.Bytes()), } client := http.Client{