@@ -64,7 +64,9 @@ library DAVerifier {
64
64
/// @notice The verifier data length isn't equal to the number of shares in the shares proofs.
65
65
UnequalDataLengthAndNumberOfSharesProofs,
66
66
/// @notice The number of leaves in the binary merkle proof is not divisible by 4.
67
- InvalidNumberOfLeavesInProof
67
+ InvalidNumberOfLeavesInProof,
68
+ /// @notice The provided range is invalid.
69
+ InvalidRange
68
70
}
69
71
70
72
///////////////
@@ -107,12 +109,13 @@ library DAVerifier {
107
109
uint256 cursor = 0 ;
108
110
for (uint256 i = 0 ; i < _sharesProof.shareProofs.length ; i++ ) {
109
111
uint256 sharesUsed = _sharesProof.shareProofs[i].endKey - _sharesProof.shareProofs[i].beginKey;
112
+ (bytes [] memory s , ErrorCodes err ) = slice (_sharesProof.data, cursor, cursor + sharesUsed);
113
+ if (err != ErrorCodes.NoError) {
114
+ return (false , err);
115
+ }
110
116
if (
111
117
! NamespaceMerkleTree.verifyMulti (
112
- _sharesProof.rowRoots[i],
113
- _sharesProof.shareProofs[i],
114
- _sharesProof.namespace,
115
- slice (_sharesProof.data, cursor, cursor + sharesUsed)
118
+ _sharesProof.rowRoots[i], _sharesProof.shareProofs[i], _sharesProof.namespace, s
116
119
)
117
120
) {
118
121
return (false , ErrorCodes.InvalidSharesToRowsProof);
@@ -235,14 +238,18 @@ library DAVerifier {
235
238
/// @param _begin The beginning of the range (inclusive).
236
239
/// @param _end The ending of the range (exclusive).
237
240
/// @return _ the sliced data.
238
- function slice (bytes [] memory _data , uint256 _begin , uint256 _end ) internal pure returns (bytes [] memory ) {
241
+ function slice (bytes [] memory _data , uint256 _begin , uint256 _end )
242
+ internal
243
+ pure
244
+ returns (bytes [] memory , ErrorCodes)
245
+ {
239
246
if (_begin > _end) {
240
- revert ( " Invalid range: _begin is greater than _end " );
247
+ return (_data, ErrorCodes.InvalidRange );
241
248
}
242
249
bytes [] memory out = new bytes [](_end- _begin);
243
250
for (uint256 i = _begin; i < _end; i++ ) {
244
251
out[i - _begin] = _data[i];
245
252
}
246
- return out;
253
+ return ( out, ErrorCodes.NoError) ;
247
254
}
248
255
}
0 commit comments