Skip to content

Commit a0f3246

Browse files
authoredFeb 3, 2025··
fix: part (#1599)
## Description minor fix
1 parent 382f0ce commit a0f3246

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎types/part_set.go

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func (part *Part) ValidateBasic() error {
3737
if int64(part.Index) < part.Proof.Total-1 && len(part.Bytes) != int(BlockPartSizeBytes) {
3838
return ErrPartInvalidSize
3939
}
40+
if int64(part.Index) != part.Proof.Index {
41+
return fmt.Errorf("part index %d != proof index %d", part.Index, part.Proof.Index)
42+
}
4043
if err := part.Proof.ValidateBasic(); err != nil {
4144
return fmt.Errorf("wrong Proof: %w", err)
4245
}

‎types/part_set_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,27 @@ func TestPartValidateBasic(t *testing.T) {
137137
pt.Index = 1
138138
pt.Bytes = make([]byte, BlockPartSizeBytes-1)
139139
pt.Proof.Total = 2
140+
pt.Proof.Index = 1
140141
}, false},
141142
{"Too small inner part", func(pt *Part) {
142143
pt.Index = 0
143144
pt.Bytes = make([]byte, BlockPartSizeBytes-1)
145+
pt.Proof.Index = 1
144146
pt.Proof.Total = 2
145-
}, true},
147+
},
148+
149+
true},
146150
{"Too big proof", func(pt *Part) {
147151
pt.Proof = merkle.Proof{
148152
Total: 2,
149153
Index: 1,
150154
LeafHash: make([]byte, 1024*1024),
151155
}
152156
}, true},
157+
{"Index mismatch", func(pt *Part) {
158+
pt.Index = 1
159+
pt.Proof.Index = 0
160+
}, true},
153161
}
154162

155163
for _, tc := range testCases {

0 commit comments

Comments
 (0)
Please sign in to comment.