Skip to content

Commit 0e4dba0

Browse files
committed
chore: more linting fixes | fix package lint script glob
1 parent 24951a7 commit 0e4dba0

11 files changed

+72
-44
lines changed

package.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
22
"name": "contracts",
3-
"version": "1.0.0",
4-
"description": "",
3+
"version": "0.0.0",
4+
"description": "Hoku core contracts",
55
"main": "index.js",
66
"scripts": {
77
"test": "forge test",
8-
"format": "forge fmt",
9-
"lint": "pnpm run format && solhint src/**/*.sol",
8+
"build": "forge build",
9+
"fmt": "forge fmt --check",
10+
"fmt:fix": "forge fmt",
11+
"lint": "solhint 'src/**/*.sol'",
12+
"lint:fix": "solhint 'src/**/*.sol' --fix",
13+
"format": "pnpm run fmt:fix && pnpm run lint:fix",
1014
"clean": "forge clean"
1115
},
1216
"keywords": [],

src/util/Blake2b.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ library Blake2b {
100100
m[i] = bytesToUint64(state.buf, i * 8);
101101
}
102102

103-
uint8[16][12] memory sigma = sigma();
103+
uint8[16][12] memory sigma = getSigma();
104104

105105
for (uint256 r = 0; r < 12; r++) {
106106
g(v, m, 0, 4, 8, 12, /* 0, 1, */ r, 0, sigma);
@@ -164,7 +164,7 @@ library Blake2b {
164164
state.buf[index / 32] = bytes32((uint256(state.buf[index / 32]) & ~mask) | newValue);
165165
}
166166

167-
function sigma() internal pure returns (uint8[16][12] memory) {
167+
function getSigma() internal pure returns (uint8[16][12] memory) {
168168
return [
169169
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
170170
[14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],

src/util/solidity-cbor/ByteParser.sol

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
//SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
3+
4+
import {InvalidValue} from "./components/CBORErrors.sol";
35

46
/// @dev Helpful byte utility functions.
57
/// Returns decoded CBOR values as their proper types.
@@ -10,7 +12,9 @@ library ByteParser {
1012
/// @param data dynamic bytes array
1113
/// @return value calculated uint64 value
1214
function bytesToUint64(bytes memory data) public pure returns (uint64 value) {
13-
require(value <= MAX_UINT64, "Number too large! Use `bytesToBigNumber` instead!");
15+
if (value > MAX_UINT64) {
16+
revert InvalidValue("Number too large, use bytesToBigNumber");
17+
}
1418
value = uint64(bytesToBigNumber(data));
1519
}
1620

@@ -32,7 +36,9 @@ library ByteParser {
3236
/// @param data dynamic bytes array
3337
/// @return value calculated uint256 value
3438
function bytesToBigNumber(bytes memory data) public pure returns (uint256 value) {
35-
require(data.length <= 64, "Value too large!");
39+
if (data.length > 64) {
40+
revert InvalidValue("Value too large");
41+
}
3642
for (uint256 i = 0; i < data.length; i++) {
3743
value += uint8(data[i]) * uint256(2 ** (8 * (data.length - (i + 1))));
3844
}
@@ -42,14 +48,16 @@ library ByteParser {
4248
/// @param data dynamic bytes array
4349
/// @return value calculated bool value
4450
function bytesToBool(bytes memory data) public pure returns (bool value) {
45-
require(data.length == 1, "Data is not a boolean!");
51+
if (data.length != 1) {
52+
revert InvalidValue("Data is not a boolean");
53+
}
4654
uint8 boolean = uint8(data[0]);
4755
if (boolean == 1) {
4856
value = true;
4957
} else if (boolean == 0) {
5058
value = false;
5159
} else {
52-
revert("Improper boolean!");
60+
revert InvalidValue("Improper boolean");
5361
}
5462
}
5563

src/util/solidity-cbor/CBORDecoding.sol

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
//SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
33

44
import {CBORByteUtils as ByteUtils} from "./components/CBORByteUtils.sol";
55
import {CBORDataStructures as DataStructures} from "./components/CBORDataStructures.sol";
6+
import {InvalidValue} from "./components/CBORErrors.sol";
67
import {CBORPrimitives as Primitives} from "./components/CBORPrimitives.sol";
78
import {CBORSpec as Spec} from "./components/CBORSpec.sol";
89
import {CBORUtilities as Utils} from "./components/CBORUtilities.sol";
@@ -29,7 +30,7 @@ library CBORDecoding {
2930
uint256 cursor = 0;
3031
// Type check
3132
(Spec.MajorType majorType, uint8 shortCount) = Utils.parseFieldEncoding(encoding[cursor]);
32-
require(majorType == Spec.MajorType.Map, "Object is not a mapping!");
33+
if (majorType != Spec.MajorType.Map) revert InvalidValue("Object is not a mapping");
3334

3435
// Decode and return
3536
decodedData = DataStructures.expandMapping(encoding, cursor, shortCount);
@@ -53,7 +54,7 @@ library CBORDecoding {
5354
uint256 cursor = 0;
5455
// Type check
5556
(Spec.MajorType majorType, uint8 shortCount) = Utils.parseFieldEncoding(encoding[cursor]);
56-
require(majorType == Spec.MajorType.Array, "Object is not an array!");
57+
if (majorType != Spec.MajorType.Array) revert InvalidValue("Object is not an array");
5758

5859
// Decode and return
5960
decodedData = DataStructures.expandArray(encoding, cursor, shortCount);
@@ -78,7 +79,9 @@ library CBORDecoding {
7879
// See what our field looks like
7980
(Spec.MajorType majorType, uint8 shortCount, uint256 start, uint256 end, /*next*/ ) =
8081
Utils.parseField(encoding, cursor);
81-
require(majorType != Spec.MajorType.Array && majorType != Spec.MajorType.Map, "Encoding is not a primitive!");
82+
if (majorType != Spec.MajorType.Array && majorType != Spec.MajorType.Map) {
83+
revert InvalidValue("Encoding is not a primitive");
84+
}
8285

8386
// Save our data
8487
decodedData = Utils.extractValue(encoding, majorType, shortCount, start, end);
@@ -110,7 +113,7 @@ library CBORDecoding {
110113
{
111114
// Ensure we start with a mapping
112115
(Spec.MajorType majorType, uint8 shortCount) = Utils.parseFieldEncoding(encoding[0]);
113-
require(majorType == Spec.MajorType.Map, "Object is not a mapping!");
116+
if (majorType != Spec.MajorType.Map) revert InvalidValue("Object is not a mapping");
114117

115118
// Figure out where cursor should start.
116119
if (shortCount == 31) {
@@ -143,7 +146,7 @@ library CBORDecoding {
143146
if (keccak256(currentItem) == searchKeyHash) keyFound = true;
144147
}
145148
// If the key doesn't exist, revert
146-
revert("Key not found!");
149+
revert InvalidValue("Key not found");
147150
}
148151

149152
/**
@@ -167,7 +170,7 @@ library CBORDecoding {
167170
{
168171
// Ensure we start with a mapping
169172
(Spec.MajorType majorType, uint8 shortCount) = Utils.parseFieldEncoding(encoding[0]);
170-
require(majorType == Spec.MajorType.Array, "Object is not an array!");
173+
if (majorType != Spec.MajorType.Array) revert InvalidValue("Object is not an array");
171174

172175
// Figure out where cursor should start.
173176
if (shortCount == 31) {
@@ -194,7 +197,7 @@ library CBORDecoding {
194197
cursor = next;
195198
}
196199
// If the key doesn't exist, revert
197-
revert("Item not found!");
200+
revert InvalidValue("Item not found");
198201
}
199202

200203
/**
@@ -210,7 +213,7 @@ library CBORDecoding {
210213
{
211214
// Ensure we start with a mapping
212215
(Spec.MajorType majorType, uint8 shortCount) = Utils.parseFieldEncoding(encoding[0]);
213-
require(majorType == Spec.MajorType.Array, "Object is not an array!");
216+
if (majorType != Spec.MajorType.Array) revert InvalidValue("Object is not an array");
214217

215218
// Figure out where cursor should start.
216219
if (shortCount == 31) {
@@ -239,6 +242,6 @@ library CBORDecoding {
239242
cursor = next;
240243
}
241244
// If the index doesn't exist in list, revert
242-
revert("Index provided larger than list!");
245+
revert InvalidValue("Index provided larger than list");
243246
}
244247
}

src/util/solidity-cbor/CBOREncoding.sol

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.4;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
33

4+
import {InvalidValue} from "./components/CBORErrors.sol";
45
import {Buffer} from "@ensdomains/buffer/contracts/Buffer.sol";
56

67
/// @title CBOR Encoding Library
@@ -53,7 +54,9 @@ library CBOR {
5354
/// @param buf The CBORBuffer to extract data from
5455
/// @return The encoded CBOR data as bytes
5556
function data(CBORBuffer memory buf) internal pure returns (bytes memory) {
56-
require(buf.depth == 0, "Invalid CBOR");
57+
if (buf.depth != 0) {
58+
revert InvalidValue("Invalid CBOR");
59+
}
5760
return buf.buf.buf;
5861
}
5962

src/util/solidity-cbor/components/CBORByteUtils.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
33

44
/// @dev Helpful byte utility functions.
55
library CBORByteUtils {

src/util/solidity-cbor/components/CBORDataStructures.sol

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
//SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
33

44
import {CBORByteUtils as ByteUtils} from "./CBORByteUtils.sol";
5+
import {InvalidRFCShortcode, InvalidValue} from "./CBORErrors.sol";
56
import {CBORSpec as Spec} from "./CBORSpec.sol";
67
import {CBORUtilities as Utils} from "./CBORUtilities.sol";
78

@@ -23,7 +24,7 @@ library CBORDataStructures {
2324
// Count up how many keys we have, set cursor
2425
(uint256 totalItems, uint256 dataStart,) =
2526
getDataStructureItemLength(encoding, mappingCursor, Spec.MajorType.Map, shortCount);
26-
require(totalItems % 2 == 0, "Invalid mapping provided!");
27+
if (totalItems % 2 != 0) revert InvalidValue("Invalid mapping provided");
2728
mappingCursor = dataStart;
2829

2930
// Allocate new array
@@ -168,7 +169,7 @@ library CBORDataStructures {
168169
} else if (shortCount == 27) {
169170
countEnd += 8;
170171
} else if (shortCount >= 28 && shortCount <= 30) {
171-
revert("Invalid data structure RFC Shortcode!");
172+
revert InvalidRFCShortcode();
172173
}
173174

174175
// We have something we need to add up / interpret
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
3+
4+
error InvalidValue(string);
5+
error InvalidRFCShortcode();
6+
error InvalidTagType();
7+
error InvalidMajorType();

src/util/solidity-cbor/components/CBORPrimitives.sol

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
//SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
33

44
import {CBORByteUtils as ByteUtils} from "./CBORByteUtils.sol";
5+
import {InvalidRFCShortcode, InvalidTagType} from "./CBORErrors.sol";
56
import {CBORSpec as Spec} from "./CBORSpec.sol";
67
import {CBORUtilities as Utils} from "./CBORUtilities.sol";
78

@@ -39,7 +40,7 @@ library CBORPrimitives {
3940
} else if (shortCount == 27) {
4041
dataEnd += 8;
4142
} else if (shortCount >= 28) {
42-
revert("Invalid integer RFC Shortcode!");
43+
revert InvalidRFCShortcode();
4344
}
4445
}
4546

@@ -82,7 +83,7 @@ library CBORPrimitives {
8283
} else if (shortCount == 27) {
8384
countEnd += 8;
8485
} else if (shortCount >= 28 && shortCount <= 30) {
85-
revert("Invalid string RFC Shortcode!");
86+
revert InvalidRFCShortcode();
8687
}
8788

8889
// Calculate the value of the count
@@ -115,7 +116,7 @@ library CBORPrimitives {
115116
(, shortCount) = Utils.parseFieldEncoding(encoding[cursor]);
116117
(dataStart, dataEnd) = parseString(encoding, cursor, shortCount);
117118
} else {
118-
revert("Unsupported Tag Type!");
119+
revert InvalidTagType();
119120
}
120121

121122
return (dataStart, dataEnd);
@@ -139,13 +140,13 @@ library CBORPrimitives {
139140

140141
// Predetermined sizes
141142
if (shortCount <= 19 || shortCount >= 28) {
142-
revert("Invalid special RFC Shortcount!");
143+
revert InvalidRFCShortcode();
143144
} else if (shortCount >= 20 && shortCount <= 23) {
144145
// 20-23 are false, true, null, and undefined (respectively).
145146
// There's no extra data to grab.
146147
return (cursor, cursor);
147148
} else if (shortCount >= 24 && shortCount <= 27) {
148-
revert("Unimplemented Shortcount!");
149+
revert InvalidRFCShortcode();
149150
}
150151
// NOTE: - floats could be implemented in the future if needed
151152
// else if (shortCount == 24) dataEnd += 1;

src/util/solidity-cbor/components/CBORSpec.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
33

44
/// @dev Basic CBOR specification tools and constants.
55
library CBORSpec {

src/util/solidity-cbor/components/CBORUtilities.sol

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
//SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
33

44
import {CBORByteUtils as ByteUtils} from "./CBORByteUtils.sol";
55
import {CBORDataStructures as DataStructures} from "./CBORDataStructures.sol";
6+
import {InvalidMajorType} from "./CBORErrors.sol";
67
import {CBORPrimitives as Primitives} from "./CBORPrimitives.sol";
78
import {CBORSpec as Spec} from "./CBORSpec.sol";
89

@@ -48,7 +49,7 @@ library CBORUtilities {
4849
}
4950
// Unsupported types (shouldn't ever really)
5051
else {
51-
revert("Unimplemented Major Type!");
52+
revert InvalidMajorType();
5253
}
5354

5455
// `end` is non-inclusive

0 commit comments

Comments
 (0)