Skip to content

Commit

Permalink
Chaging data types to avoid dangerous conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodeymo authored and afkbyte committed Oct 2, 2024
1 parent 91ca9d4 commit f6ce39a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions chainio/txmgr/geometric/geometric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions types/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down

0 comments on commit f6ce39a

Please sign in to comment.