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

Chaging data types to avoid dangerous conversions #348

Merged
merged 2 commits into from
Oct 2, 2024
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
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
6 changes: 4 additions & 2 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,14 @@ 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