Skip to content

Commit 39d4c7d

Browse files
authored
hotfix: added validation to check if index to fetch element is within limits (#1267)
* hotfix: added validation to check if index to fetch element is within limits * refactor: added condition numOfProposedBlocks <= 0
1 parent d4aa054 commit 39d4c7d

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
mv razor_go.linux-amd64.tar.gz ../../
123123
124124
- name: Upload AMD Artifact
125-
uses: actions/upload-artifact@v3
125+
uses: actions/upload-artifact@v4
126126
with:
127127
name: razor_go.linux-amd64.tar.gz
128128
path: razor_go.linux-amd64.tar.gz
@@ -173,7 +173,7 @@ jobs:
173173
mv razor_go.linux-arm64.tar.gz ../../
174174
175175
- name: Upload ARM Artifact
176-
uses: actions/upload-artifact@v3
176+
uses: actions/upload-artifact@v4
177177
with:
178178
name: razor_go.linux-arm64.tar.gz
179179
path: razor_go.linux-arm64.tar.gz
@@ -197,12 +197,12 @@ jobs:
197197
node-version: "20"
198198

199199
- name: Download Artifacts AMD
200-
uses: actions/download-artifact@v3
200+
uses: actions/download-artifact@v4
201201
with:
202202
name: razor_go.linux-amd64.tar.gz
203203

204204
- name: Download Artifacts ARM
205-
uses: actions/download-artifact@v3
205+
uses: actions/download-artifact@v4
206206
with:
207207
name: razor_go.linux-arm64.tar.gz
208208

cmd/propose.go

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ func (*UtilsStruct) Propose(client *ethclient.Client, config types.Configuration
113113
return err
114114
}
115115
log.Debug("Propose: Sorted proposed blocks: ", sortedProposedBlocks)
116+
117+
if numOfProposedBlocks <= 0 || len(sortedProposedBlocks) < int(numOfProposedBlocks) {
118+
log.Errorf("Invalid numOfProposedBlocks (%d) or mismatch with sortedProposedBlocks length (%d)", numOfProposedBlocks, len(sortedProposedBlocks))
119+
return errors.New("proposed blocks count mismatch")
120+
}
121+
116122
lastBlockIndex := sortedProposedBlocks[numOfProposedBlocks-1]
117123
log.Debug("Propose: Last block index: ", lastBlockIndex)
118124
lastProposedBlockStruct, err := razorUtils.GetProposedBlock(client, epoch, lastBlockIndex)

cmd/propose_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,21 @@ func TestPropose(t *testing.T) {
501501
},
502502
wantErr: errors.New("waitForBlockCompletion error"),
503503
},
504+
{
505+
name: "Test 20: When there is a mismatch in number of proposed blocks and length of sorted proposed blocks array",
506+
args: args{
507+
state: 2,
508+
staker: bindings.StructsStaker{},
509+
numStakers: 5,
510+
biggestStake: big.NewInt(1).Mul(big.NewInt(5356), big.NewInt(1e18)),
511+
biggestStakerId: 2,
512+
salt: saltBytes32,
513+
iteration: 1,
514+
numOfProposedBlocks: 3,
515+
sortedProposedBlockIds: []uint32{2, 1},
516+
},
517+
wantErr: errors.New("proposed blocks count mismatch"),
518+
},
504519
}
505520
for _, tt := range tests {
506521
SetUpMockInterfaces()

0 commit comments

Comments
 (0)