Skip to content

Commit e2daa12

Browse files
committed
chore: add an error instead of reverting
1 parent 0b9a380 commit e2daa12

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/lib/verifier/DAVerifier.sol

+15-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ library DAVerifier {
6464
/// @notice The verifier data length isn't equal to the number of shares in the shares proofs.
6565
UnequalDataLengthAndNumberOfSharesProofs,
6666
/// @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
6870
}
6971

7072
///////////////
@@ -107,12 +109,13 @@ library DAVerifier {
107109
uint256 cursor = 0;
108110
for (uint256 i = 0; i < _sharesProof.shareProofs.length; i++) {
109111
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+
}
110116
if (
111117
!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
116119
)
117120
) {
118121
return (false, ErrorCodes.InvalidSharesToRowsProof);
@@ -235,14 +238,18 @@ library DAVerifier {
235238
/// @param _begin The beginning of the range (inclusive).
236239
/// @param _end The ending of the range (exclusive).
237240
/// @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+
{
239246
if (_begin > _end) {
240-
revert("Invalid range: _begin is greater than _end");
247+
return (_data, ErrorCodes.InvalidRange);
241248
}
242249
bytes[] memory out = new bytes[](_end-_begin);
243250
for (uint256 i = _begin; i < _end; i++) {
244251
out[i - _begin] = _data[i];
245252
}
246-
return out;
253+
return (out, ErrorCodes.NoError);
247254
}
248255
}

0 commit comments

Comments
 (0)