Skip to content

Commit

Permalink
[R4R] - {develop}: fix consensys minor audit issue: cs-6.43, cs-6.44 …
Browse files Browse the repository at this point in the history
…and cs-6.45 (#1183)

* fix data race in unit test

* improve error handle

* fix typos in variables

---------

Co-authored-by: Raymond <6427270+wukongcheng@users.noreply.github.com>
  • Loading branch information
HaoyangLiu and wukongcheng committed Jul 2, 2023
1 parent 6271b15 commit 1e75491
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
15 changes: 8 additions & 7 deletions mt-batcher/services/sequencer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"crypto/ecdsa"
"encoding/json"
"fmt"
"math/big"
"strings"
"sync"
"time"

"github.com/Layr-Labs/datalayr/common/graphView"
pb "github.com/Layr-Labs/datalayr/common/interfaces/interfaceDL"
"github.com/Layr-Labs/datalayr/common/logging"
Expand All @@ -31,10 +36,6 @@ import (
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"math/big"
"strings"
"sync"
"time"
)

type SignerFn func(context.Context, common.Address, *types.Transaction) (*types.Transaction, error)
Expand Down Expand Up @@ -359,7 +360,7 @@ func (d *Driver) StoreData(ctx context.Context, uploadHeader []byte, duration ui
return tx, nil

case d.IsMaxPriorityFeePerGasNotFoundError(err):
log.Warn("MtBather eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap")
log.Warn("MtBatcher eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap")
opts.GasTipCap = common4.FallbackGasTipCap
return d.Cfg.EigenDaContract.StoreData(opts, uploadHeader, duration, blockNumber, startL2BlockNumber, endL2BlockNumber, totalOperatorsIndex, isReRollup)

Expand Down Expand Up @@ -409,7 +410,7 @@ func (d *Driver) ConfirmData(ctx context.Context, callData []byte, searchData rc
return tx, nil

case d.IsMaxPriorityFeePerGasNotFoundError(err):
log.Warn("MtBather eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap")
log.Warn("MtBatcher eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap")
opts.GasTipCap = common4.FallbackGasTipCap
return d.Cfg.EigenDaContract.ConfirmData(opts, callData, searchData, startL2BlockNumber, endL2BlockNumber, originDataStoreId, reConfirmedBatchIndex, isReRollup)

Expand Down Expand Up @@ -660,7 +661,7 @@ func (d *Driver) UpdateFee(ctx context.Context, l2Block, daFee *big.Int) (*types
case err == nil:
return tx, nil
case d.IsMaxPriorityFeePerGasNotFoundError(err):
log.Warn("MtBather eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap")
log.Warn("MtBatcher eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap")
opts.GasTipCap = common4.FallbackGasTipCap
return d.Cfg.EigenFeeContract.SetRollupFee(opts, l2Block, daFee)
default:
Expand Down
10 changes: 6 additions & 4 deletions tss/manager/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ func TestWrongSignature(t *testing.T) {
ClusterPubKey: publicKey,
})
afterMsgSent := func(request server.RequestMsg, respCh chan server.ResponseMsg) error {
signature[22] = 0x67 // modify the signature
newSig := make([]byte, len(signature), len(signature))
copy(newSig, signature)
newSig[22] = 0x67 // modify the sig
signResp := tss.SignResponse{
Signature: signature,
Signature: newSig,
}
rpcResp := tmtypes.NewRPCSuccessResponse(request.RpcRequest.ID, signResp)
respCh <- server.ResponseMsg{
Expand Down Expand Up @@ -222,7 +224,7 @@ func TestSignSlash(t *testing.T) {

afterMsgSent := func(request server.RequestMsg, respCh chan server.ResponseMsg) error {
signResp := tss.SignResponse{
Signature: signature,
Signature: signature,
}
rpcResp := tmtypes.NewRPCSuccessResponse(request.RpcRequest.ID, signResp)
respCh <- server.ResponseMsg{
Expand All @@ -243,7 +245,7 @@ func TestSignSlash(t *testing.T) {
}

signResp := tss.SignResponse{
Signature: signature,
Signature: signature,
}
rpcResp := tmtypes.NewRPCSuccessResponse(request.RpcRequest.ID, signResp)
respCh <- server.ResponseMsg{
Expand Down
12 changes: 6 additions & 6 deletions tss/node/tsslib/keysign.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ func (t *TssServer) isPartOfKeysignParty(parties []string) bool {
func (t *TssServer) isContainPubkeys(signerPubKeys, participants []string, poolPubkey string) error {

participantsStr := strings.Join(participants, ",")
var errPubkyes []string
for _, pubkey := range signerPubKeys {
if !strings.Contains(participantsStr, pubkey) {
errPubkyes = append(errPubkyes, pubkey)
var errPubKeys []string
for _, pubKey := range signerPubKeys {
if !strings.Contains(participantsStr, pubKey) {
errPubKeys = append(errPubKeys, pubKey)
}
}
if len(errPubkyes) != 0 {
return errors.New(fmt.Sprintf("these pub keys %s are not members of %s's participants", strings.Join(errPubkyes, ","), poolPubkey))
if len(errPubKeys) != 0 {
return errors.New(fmt.Sprintf("these public keys %s are not members of %s's participants", strings.Join(errPubKeys, ","), poolPubkey))
}
return nil
}
Expand Down
9 changes: 3 additions & 6 deletions tss/node/tsslib/p2p/communication.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,11 @@ func (c *Communication) Start(priKeyBytes []byte) error {

// Stop communication
func (c *Communication) Stop() error {
// we need to stop the handler and the p2p services firstly, then terminate the our communication threads
if err := c.host.Close(); err != nil {
c.logger.Err(err).Msg("fail to close host network")
}

// we need to stop the handler and the p2p services firstly, then terminate the communication threads
err := c.host.Close()
close(c.stopChan)
c.wg.Wait()
return nil
return err
}

func (c *Communication) SetSubscribe(topic messages.TSSMessageTpe, msgID string, channel chan *Message) {
Expand Down
14 changes: 8 additions & 6 deletions tss/node/tsslib/tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"encoding/hex"
"errors"
"fmt"
"os"
"sort"
"strings"
"sync"

bkeygen "github.com/binance-chain/tss-lib/ecdsa/keygen"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/mantlenetworkio/mantle/l2geth/crypto"
Expand All @@ -18,10 +23,6 @@ import (
storage2 "github.com/mantlenetworkio/mantle/tss/node/tsslib/storage"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
"sort"
"strings"
"sync"
)

type TssServer struct {
Expand Down Expand Up @@ -190,9 +191,10 @@ func (t *TssServer) Stop() {
// stop the p2p and finish the p2p wait group
err := t.p2pCommunication.Stop()
if err != nil {
t.logger.Error().Msgf("error in shutdown the p2p server")
t.logger.Err(err).Msgf("error in shutdown the p2p server")
} else {
log.Info().Msg("The Tss and p2p server has been stopped successfully")
}
log.Info().Msg("The Tss and p2p server has been stopped successfully")
}

func (t *TssServer) GetLocalPeerID() string {
Expand Down

0 comments on commit 1e75491

Please sign in to comment.