Skip to content

Commit

Permalink
add justification, rename message to drop Unsigned
Browse files Browse the repository at this point in the history
addresses review comment #408 (comment)
  • Loading branch information
feuGeneA committed Aug 6, 2024
1 parent 9db9153 commit 557262a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions relayer/application_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions signature-aggregator/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func NewSignatureAggregator(

func (s *SignatureAggregator) AggregateSignaturesAppRequest(
unsignedMessage *avalancheWarp.UnsignedMessage,
justification []byte,
inputSigningSubnet ids.ID,
quorumPercentage uint64,
) (*avalancheWarp.Message, error) {
Expand Down
49 changes: 43 additions & 6 deletions signature-aggregator/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -123,7 +159,8 @@ func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregato
}

signedMessage, err := aggregator.AggregateSignaturesAppRequest(
unsignedMessage,
message,
justification,
signingSubnetID,
quorumNum,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/signature_aggregator_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 557262a

Please # to comment.