Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R]-{develop}: fix secure mtl-32 #1293

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions tss/node/signer/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ func (p *Processor) Keygen() {
if err := json.Unmarshal(req.Params, &keyR); err != nil {
logger.Error().Msg("failed to unmarshal ask request")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err = p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
verifyResult := p.verifyThreshold(keyR)
if !verifyResult {
logger.Error().Msg("verify threshold in keygen request is false")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", "verify threshold in keygen request is false")
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}

Expand All @@ -74,22 +78,28 @@ func (p *Processor) Keygen() {
if err != nil {
logger.Err(err).Msg("failed to keygen !")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 202, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
} else {
if resp.Status == common.Success {
keygenResponse := tsscommon.KeygenResponse{
ClusterPublicKey: resp.PubKey,
}
RpcResponse := tdtypes.NewRPCSuccessResponse(tdtypes.JSONRPCStringID(resId), keygenResponse)
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
logger.Info().Msgf("keygen start to set group publickey for l1 contract")
err := p.setGroupPublicKey(p.localPubKeyByte, resp.PubKeyByte)
if err != nil {
logger.Err(err).Msg("failed to send tss group manager transactionx")
}
} else {
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 202, "failed", resp.FailReason)
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions tss/node/signer/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ func (p *Processor) Sign() {
if err := json.Unmarshal(req.Params, &nodeSignRequest); err != nil {
logger.Error().Msg("failed to unmarshal ask request")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
var requestBody tsscommon.SignStateRequest
if err := json.Unmarshal(rawMsg, &requestBody); err != nil {
logger.Error().Msg("failed to unmarshal asker's params request body")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
if requestBody.StartBlock == nil ||
Expand All @@ -63,7 +67,9 @@ func (p *Processor) Sign() {
requestBody.OffsetStartsAtIndex.Cmp(big.NewInt(0)) < 0 {
logger.Error().Msg("StartBlock and OffsetStartsAtIndex must not be nil or negative")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", "StartBlock and OffsetStartsAtIndex must not be nil or negative")
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
nodeSignRequest.RequestBody = requestBody
Expand All @@ -84,7 +90,9 @@ func (p *Processor) SignGo(resId tdtypes.JSONRPCStringID, sign tsscommon.NodeSig
if err != nil {
RpcResponse := tdtypes.NewRPCErrorResponse(resId, 201, "failed", err.Error())

p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
logger.Err(err).Msg("check event failed")
return err
}
Expand Down
16 changes: 12 additions & 4 deletions tss/node/signer/sign_rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,37 @@ func (p *Processor) SignRollBack() {
if err := json.Unmarshal(req.Params, &nodeSignRequest); err != nil {
logger.Error().Msg("failed to unmarshal roll back request")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
var requestBody tsscommon.RollBackRequest
if err := json.Unmarshal(rawMsg, &requestBody); err != nil {
logger.Error().Msg("failed to umarshal roll back params request body")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
if requestBody.StartBlock == nil ||
requestBody.StartBlock.Cmp(big.NewInt(0)) < 0 {
logger.Error().Msg("StartBlock must not be nil or negative")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", "StartBlock must not be nil or negative")
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
nodeSignRequest.RequestBody = requestBody
hashTx, err := tsscommon.RollBackHash(requestBody.StartBlock)
if err != nil {
logger.Err(err).Msg("failed to encode roll back msg")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}

Expand Down
16 changes: 12 additions & 4 deletions tss/node/signer/sign_slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ func (p *Processor) SignSlash() {
if err := json.Unmarshal(req.Params, &nodeSignRequest); err != nil {
logger.Error().Msg("failed to unmarshal node sign request")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
var requestBody tsscommon.SlashRequest
if err := json.Unmarshal(rawMsg, &requestBody); err != nil {
logger.Error().Msg("failed to umarshal slash params request body")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
nodeSignRequest.RequestBody = requestBody
Expand All @@ -56,7 +60,9 @@ func (p *Processor) SignSlash() {
if err != nil {
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())

p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
logger.Err(err).Msg("check event failed")
continue
}
Expand All @@ -70,7 +76,9 @@ func (p *Processor) SignSlash() {
if err != nil {
logger.Err(err).Msg("failed to encode SlashMsg")
RpcResponse := tdtypes.NewRPCErrorResponse(req.ID, 201, "failed", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}

Expand Down
24 changes: 18 additions & 6 deletions tss/node/signer/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func (p *Processor) Verify() {
if err := json.Unmarshal(req.Params, &askRequest); err != nil {
logger.Error().Msg("failed to unmarshal ask request")
RpcResponse = tdtypes.NewRPCErrorResponse(req.ID, 201, "failed to unmarshal ", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
if askRequest.StartBlock == nil ||
Expand All @@ -42,7 +44,9 @@ func (p *Processor) Verify() {
askRequest.OffsetStartsAtIndex.Cmp(big.NewInt(0)) < 0 {
logger.Error().Msg("StartBlock and OffsetStartsAtIndex must not be nil or negative")
RpcResponse = tdtypes.NewRPCErrorResponse(req.ID, 201, "invalid askRequest", "StartBlock and OffsetStartsAtIndex must not be nil or negative")
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
return
}
var resId = req.ID
Expand All @@ -51,7 +55,9 @@ func (p *Processor) Verify() {
if len(askRequest.StateRoots) == 0 {
logger.Error().Msg("stateroots size is empty")
RpcResponse = tdtypes.NewRPCErrorResponse(req.ID, 201, "stateroots size is empty ", "do not need to sign")
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
} else {
wg := &sync.WaitGroup{}
Expand All @@ -61,15 +67,19 @@ func (p *Processor) Verify() {
if err != nil {
logger.Error().Msgf("failed to verify block %s", err.Error())
RpcResponse = tdtypes.NewRPCErrorResponse(req.ID, 201, "get error when verify ", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
} else {
hash, err := signMsgToHash(askRequest)
if err != nil {
logger.Err(err).Msg("failed to conv msg to hash")
RpcResponse = tdtypes.NewRPCErrorResponse(req.ID, 201, "failed to conv msg to hash", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
} else {
hashStr := hexutil.Encode(hash)
Expand All @@ -80,7 +90,9 @@ func (p *Processor) Verify() {
Result: result,
}
RpcResponse = tdtypes.NewRPCSuccessResponse(resId, askResponse)
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}

}
}
Expand Down
8 changes: 6 additions & 2 deletions tss/node/signer/verify_rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ func (p *Processor) VerifyRollBack() {
if err != nil {
logger.Error().Msgf("failed to do verify for rollback, %s", err.Error())
RpcResponse = tdtypes.NewRPCErrorResponse(req.ID, 201, "failed to do verify for rollback ", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}
askResponse := common.AskResponse{
Result: ret,
}
RpcResponse = tdtypes.NewRPCSuccessResponse(resId, askResponse)
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
}
}
}()
Expand Down
4 changes: 3 additions & 1 deletion tss/node/signer/verify_slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func (p *Processor) VerifySlash() {
if err := json.Unmarshal(req.Params, &askRequest); err != nil {
logger.Error().Msg("failed to unmarshal ask request")
RpcResponse = tdtypes.NewRPCErrorResponse(resId, 201, "failed to unmarshal", err.Error())
p.wsClient.SendMsg(RpcResponse)
if err := p.wsClient.SendMsg(RpcResponse); err != nil {
logger.Error().Err(err).Msg("failed to send msg to manager")
}
continue
}

Expand Down