@@ -25,13 +25,13 @@ type BadEncodingProof struct {
25
25
// Shares that did not pass verification in rmst2d will be nil.
26
26
// For non-nil shares MerkleProofs are computed.
27
27
Shares []* ipld.ShareWithProof
28
- // Index represents the row/col index where ErrByzantineRow/ErrByzantineColl occurred
29
- Index uint8
30
- // isRow shows that verification failed on row
28
+ // Index represents the row/col index where ErrByzantineRow/ErrByzantineColl occurred.
29
+ Index uint32
30
+ // isRow shows that verification failed on row.
31
31
isRow bool
32
32
}
33
33
34
- // CreateBadEncodingProof creates a new Bad Encoding Fraud Proof that should be propagated through network
34
+ // CreateBadEncodingProof creates a new Bad Encoding Fraud Proof that should be propagated through network.
35
35
// The fraud proof will contain shares that did not pass verification and their relevant Merkle proofs.
36
36
func CreateBadEncodingProof (
37
37
hash []byte ,
@@ -48,7 +48,7 @@ func CreateBadEncodingProof(
48
48
}
49
49
}
50
50
51
- // Type returns type of fraud proof
51
+ // Type returns type of fraud proof.
52
52
func (p * BadEncodingProof ) Type () ProofType {
53
53
return BadEncoding
54
54
}
@@ -58,12 +58,12 @@ func (p *BadEncodingProof) HeaderHash() []byte {
58
58
return p .headerHash
59
59
}
60
60
61
- // Height returns block height
61
+ // Height returns block height.
62
62
func (p * BadEncodingProof ) Height () uint64 {
63
63
return p .BlockHeight
64
64
}
65
65
66
- // MarshalBinary converts BadEncodingProof to binary
66
+ // MarshalBinary converts BadEncodingProof to binary.
67
67
func (p * BadEncodingProof ) MarshalBinary () ([]byte , error ) {
68
68
shares := make ([]* ipld_pb.Share , 0 , len (p .Shares ))
69
69
for _ , share := range p .Shares {
@@ -74,7 +74,7 @@ func (p *BadEncodingProof) MarshalBinary() ([]byte, error) {
74
74
HeaderHash : p .headerHash ,
75
75
Height : p .BlockHeight ,
76
76
Shares : shares ,
77
- Index : uint32 ( p .Index ) ,
77
+ Index : p .Index ,
78
78
IsRow : p .isRow ,
79
79
}
80
80
return badEncodingFraudProof .Marshal ()
@@ -89,7 +89,7 @@ func UnmarshalBEFP(data []byte) (Proof, error) {
89
89
return befp , nil
90
90
}
91
91
92
- // UnmarshalBinary converts binary to BadEncodingProof
92
+ // UnmarshalBinary converts binary to BadEncodingProof.
93
93
func (p * BadEncodingProof ) UnmarshalBinary (data []byte ) error {
94
94
in := pb.BadEncoding {}
95
95
if err := in .Unmarshal (data ); err != nil {
@@ -99,7 +99,7 @@ func (p *BadEncodingProof) UnmarshalBinary(data []byte) error {
99
99
headerHash : in .HeaderHash ,
100
100
BlockHeight : in .Height ,
101
101
Shares : ipld .ProtoToShare (in .Shares ),
102
- Index : uint8 ( in .Index ) ,
102
+ Index : in .Index ,
103
103
isRow : in .IsRow ,
104
104
}
105
105
@@ -114,23 +114,24 @@ func (p *BadEncodingProof) UnmarshalBinary(data []byte) error {
114
114
// and compares it with block's Merkle Root.
115
115
func (p * BadEncodingProof ) Validate (header * header.ExtendedHeader ) error {
116
116
if header .Height != int64 (p .BlockHeight ) {
117
- return errors .New ("invalid fraud proof : incorrect block height" )
117
+ return errors .New ("fraud: incorrect block height" )
118
118
}
119
119
merkleRowRoots := header .DAH .RowsRoots
120
120
merkleColRoots := header .DAH .ColumnRoots
121
121
if len (merkleRowRoots ) != len (merkleColRoots ) {
122
122
// NOTE: This should never happen as callers of this method should not feed it with a
123
123
// malformed extended header.
124
- panic (fmt .Sprintf ("invalid extended header: length of row and column roots do not match. (rowRoots=%d) (colRoots=%d)" ,
124
+ panic (fmt .Sprintf (
125
+ "fraud: invalid extended header: length of row and column roots do not match. (rowRoots=%d) (colRoots=%d)" ,
125
126
len (merkleRowRoots ),
126
127
len (merkleColRoots )),
127
128
)
128
129
}
129
130
if int (p .Index ) >= len (merkleRowRoots ) {
130
- return fmt .Errorf ("invalid fraud proof: index out of bounds (%d >= %d)" , int (p .Index ), len (merkleRowRoots ))
131
+ return fmt .Errorf ("fraud: invalid proof: index out of bounds (%d >= %d)" , int (p .Index ), len (merkleRowRoots ))
131
132
}
132
133
if len (merkleRowRoots ) != len (p .Shares ) {
133
- return fmt .Errorf ("invalid fraud proof: incorrect number of shares %d != %d" , len (p .Shares ), len (merkleRowRoots ))
134
+ return fmt .Errorf ("fraud: invalid proof: incorrect number of shares %d != %d" , len (p .Shares ), len (merkleRowRoots ))
134
135
}
135
136
136
137
root := merkleRowRoots [p .Index ]
@@ -140,19 +141,19 @@ func (p *BadEncodingProof) Validate(header *header.ExtendedHeader) error {
140
141
141
142
shares := make ([][]byte , len (merkleRowRoots ))
142
143
143
- // verify that Merkle proofs correspond to particular shares
144
+ // verify that Merkle proofs correspond to particular shares.
144
145
for index , share := range p .Shares {
145
146
if share == nil {
146
147
continue
147
148
}
148
149
shares [index ] = share .Share
149
150
if ok := share .Validate (plugin .MustCidFromNamespacedSha256 (root )); ! ok {
150
- return fmt .Errorf ("invalid fraud proof: incorrect share received at Index %d" , index )
151
+ return fmt .Errorf ("fraud: invalid proof: incorrect share received at index %d" , index )
151
152
}
152
153
}
153
154
154
155
codec := consts .DefaultCodec ()
155
- // rebuild a row or col
156
+ // rebuild a row or col.
156
157
rebuiltShares , err := codec .Decode (shares )
157
158
if err != nil {
158
159
return err
@@ -168,9 +169,9 @@ func (p *BadEncodingProof) Validate(header *header.ExtendedHeader) error {
168
169
tree .Push (share , rsmt2d.SquareIndex {Axis : uint (p .Index ), Cell : uint (i )})
169
170
}
170
171
171
- // comparing rebuilt Merkle Root of bad row/col with respective Merkle Root of row/col from block
172
+ // comparing rebuilt Merkle Root of bad row/col with respective Merkle Root of row/col from block.
172
173
if bytes .Equal (tree .Root (), root ) {
173
- return errors .New ("invalid fraud proof: recomputed Merkle root matches the header 's row/column root" )
174
+ return errors .New ("fraud: invalid proof: recomputed Merkle root matches the DAH 's row/column root" )
174
175
}
175
176
176
177
return nil
0 commit comments