From f6ce39abe3f2071c4831f8ba774caec1301ac75a Mon Sep 17 00:00:00 2001 From: Pablo Deymonnaz Date: Tue, 24 Sep 2024 16:55:43 -0300 Subject: [PATCH] Chaging data types to avoid dangerous conversions --- chainio/clients/avsregistry/reader.go | 4 ++-- chainio/clients/avsregistry/writer.go | 4 ++-- chainio/txmgr/geometric/geometric.go | 4 ++-- types/operator.go | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/chainio/clients/avsregistry/reader.go b/chainio/clients/avsregistry/reader.go index 3f13d8f2..8733fe9c 100644 --- a/chainio/clients/avsregistry/reader.go +++ b/chainio/clients/avsregistry/reader.go @@ -421,7 +421,7 @@ func (r *ChainReader) QueryExistingRegisteredOperatorPubKeys( if err != nil { return nil, nil, utils.WrapError("Cannot get current block number", err) } - stopBlock = big.NewInt(int64(curBlockNum)) + stopBlock = new(big.Int).SetUint64(curBlockNum) } if blockRange == nil { blockRange = DefaultQueryBlockRange @@ -519,7 +519,7 @@ func (r *ChainReader) QueryExistingRegisteredOperatorSockets( if err != nil { return nil, utils.WrapError("Cannot get current block number", err) } - stopBlock = big.NewInt(int64(curBlockNum)) + stopBlock = new(big.Int).SetUint64(curBlockNum) } if blockRange == nil { blockRange = DefaultQueryBlockRange diff --git a/chainio/clients/avsregistry/writer.go b/chainio/clients/avsregistry/writer.go index df56d83b..71cd47e4 100644 --- a/chainio/clients/avsregistry/writer.go +++ b/chainio/clients/avsregistry/writer.go @@ -344,12 +344,12 @@ func (w *ChainWriter) RegisterOperator( if err != nil { return nil, err } - curBlock, err := w.ethClient.BlockByNumber(context.Background(), big.NewInt(int64(curBlockNum))) + curBlock, err := w.ethClient.BlockByNumber(context.Background(), new(big.Int).SetUint64(curBlockNum)) if err != nil { return nil, err } sigValidForSeconds := int64(60 * 60) // 1 hour - operatorToAvsRegistrationSigExpiry := big.NewInt(int64(curBlock.Time()) + sigValidForSeconds) + operatorToAvsRegistrationSigExpiry := new(big.Int).Add(new(big.Int).SetUint64(curBlock.Time()), big.NewInt(sigValidForSeconds)) // params to register operator in delegation manager's operator-avs mapping msgToSign, err := w.elReader.CalculateOperatorAVSRegistrationDigestHash( diff --git a/chainio/txmgr/geometric/geometric.go b/chainio/txmgr/geometric/geometric.go index 722d3dfe..f7c9627d 100644 --- a/chainio/txmgr/geometric/geometric.go +++ b/chainio/txmgr/geometric/geometric.go @@ -58,7 +58,7 @@ var _ txmgr.TxManager = (*GeometricTxManager)(nil) type GeometricTxnManagerParams struct { // number of blocks to wait for a transaction to be confirmed // default: 0 - ConfirmationBlocks int + ConfirmationBlocks uint64 // time to wait for a transaction to be broadcasted to the network // could be direct via eth_sendRawTransaction or indirect via a wallet service such as fireblocks // default: 2 minutes @@ -310,7 +310,7 @@ func (t *GeometricTxManager) ensureAnyTransactionConfirmed( if err == nil { chainTip, err := t.ethClient.BlockNumber(ctx) if err == nil { - if receipt.BlockNumber.Uint64()+uint64(t.params.ConfirmationBlocks) > chainTip { + if receipt.BlockNumber.Uint64()+t.params.ConfirmationBlocks > chainTip { t.logger.Debug( "transaction has been mined but don't have enough confirmations at current chain tip", "txnBlockNumber", diff --git a/types/operator.go b/types/operator.go index 174ac502..e0187e9f 100644 --- a/types/operator.go +++ b/types/operator.go @@ -173,14 +173,14 @@ type OperatorAvsState struct { } var ( - maxNumberOfQuorums = 192 + maxNumberOfQuorums uint8 = 192 ) func BitmapToQuorumIds(bitmap *big.Int) []QuorumNum { // loop through each index in the bitmap to construct the array quorumIds := make([]QuorumNum, 0, maxNumberOfQuorums) - for i := 0; i < maxNumberOfQuorums; i++ { - if bitmap.Bit(i) == 1 { + for i := uint8(0); i < maxNumberOfQuorums; i++ { + if bitmap.Bit(int(i)) == 1 { quorumIds = append(quorumIds, QuorumNum(i)) } }