@1inch/solidity-utils 2.2.17 → 2.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/libraries/ECDSA.sol +9 -18
- package/contracts/libraries/RevertReasonForwarder.sol +1 -2
- package/contracts/libraries/RevertReasonParser.sol +3 -6
- package/contracts/libraries/SafeERC20.sol +7 -14
- package/contracts/libraries/StringUtil.sol +1 -2
- package/contracts/libraries/UniERC20.sol +2 -4
- package/package.json +4 -5
|
@@ -25,8 +25,7 @@ library ECDSA {
|
|
|
25
25
|
bytes32 r,
|
|
26
26
|
bytes32 s
|
|
27
27
|
) internal view returns (address signer) {
|
|
28
|
-
|
|
29
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
28
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
30
29
|
if lt(s, _S_BOUNDARY) {
|
|
31
30
|
let ptr := mload(0x40)
|
|
32
31
|
|
|
@@ -46,8 +45,7 @@ library ECDSA {
|
|
|
46
45
|
bytes32 r,
|
|
47
46
|
bytes32 vs
|
|
48
47
|
) internal view returns (address signer) {
|
|
49
|
-
|
|
50
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
48
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
51
49
|
let s := and(vs, _COMPACT_S_MASK)
|
|
52
50
|
if lt(s, _S_BOUNDARY) {
|
|
53
51
|
let ptr := mload(0x40)
|
|
@@ -71,8 +69,7 @@ library ECDSA {
|
|
|
71
69
|
/// signature uniqueness will get rekt.
|
|
72
70
|
/// More info: https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-4h98-2769-gh6h
|
|
73
71
|
function recover(bytes32 hash, bytes calldata signature) internal view returns (address signer) {
|
|
74
|
-
|
|
75
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
72
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
76
73
|
let ptr := mload(0x40)
|
|
77
74
|
|
|
78
75
|
// memory[ptr:ptr+0x80] = (hash, v, r, s)
|
|
@@ -166,8 +163,7 @@ library ECDSA {
|
|
|
166
163
|
// (bool success, bytes memory data) = signer.staticcall(abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature));
|
|
167
164
|
// return success && data.length >= 4 && abi.decode(data, (bytes4)) == IERC1271.isValidSignature.selector;
|
|
168
165
|
bytes4 selector = IERC1271.isValidSignature.selector;
|
|
169
|
-
|
|
170
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
166
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
171
167
|
let ptr := mload(0x40)
|
|
172
168
|
|
|
173
169
|
mstore(ptr, selector)
|
|
@@ -189,8 +185,7 @@ library ECDSA {
|
|
|
189
185
|
bytes32 s
|
|
190
186
|
) internal view returns (bool success) {
|
|
191
187
|
bytes4 selector = IERC1271.isValidSignature.selector;
|
|
192
|
-
|
|
193
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
188
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
194
189
|
let ptr := mload(0x40)
|
|
195
190
|
|
|
196
191
|
mstore(ptr, selector)
|
|
@@ -215,8 +210,7 @@ library ECDSA {
|
|
|
215
210
|
// (bool success, bytes memory data) = signer.staticcall(abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, abi.encodePacked(r, vs)));
|
|
216
211
|
// return success && data.length >= 4 && abi.decode(data, (bytes4)) == IERC1271.isValidSignature.selector;
|
|
217
212
|
bytes4 selector = IERC1271.isValidSignature.selector;
|
|
218
|
-
|
|
219
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
213
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
220
214
|
let ptr := mload(0x40)
|
|
221
215
|
|
|
222
216
|
mstore(ptr, selector)
|
|
@@ -240,8 +234,7 @@ library ECDSA {
|
|
|
240
234
|
// (bool success, bytes memory data) = signer.staticcall(abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, abi.encodePacked(r, vs & ~uint256(1 << 255), uint8(vs >> 255))));
|
|
241
235
|
// return success && data.length >= 4 && abi.decode(data, (bytes4)) == IERC1271.isValidSignature.selector;
|
|
242
236
|
bytes4 selector = IERC1271.isValidSignature.selector;
|
|
243
|
-
|
|
244
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
237
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
245
238
|
let ptr := mload(0x40)
|
|
246
239
|
|
|
247
240
|
mstore(ptr, selector)
|
|
@@ -260,8 +253,7 @@ library ECDSA {
|
|
|
260
253
|
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 res) {
|
|
261
254
|
// 32 is the length in bytes of hash, enforced by the type signature above
|
|
262
255
|
// return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
|
|
263
|
-
|
|
264
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
256
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
265
257
|
mstore(0, 0x19457468657265756d205369676e6564204d6573736167653a0a333200000000) // "\x19Ethereum Signed Message:\n32"
|
|
266
258
|
mstore(28, hash)
|
|
267
259
|
res := keccak256(0, 60)
|
|
@@ -270,8 +262,7 @@ library ECDSA {
|
|
|
270
262
|
|
|
271
263
|
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 res) {
|
|
272
264
|
// return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
|
|
273
|
-
|
|
274
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
265
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
275
266
|
let ptr := mload(0x40)
|
|
276
267
|
mstore(ptr, 0x1901000000000000000000000000000000000000000000000000000000000000) // "\x19\x01"
|
|
277
268
|
mstore(add(ptr, 0x02), domainSeparator)
|
|
@@ -8,8 +8,7 @@ library RevertReasonForwarder {
|
|
|
8
8
|
/// @dev Forwards latest externall call revert.
|
|
9
9
|
function reRevert() internal pure {
|
|
10
10
|
// bubble up revert reason from latest external call
|
|
11
|
-
|
|
12
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
11
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
13
12
|
let ptr := mload(0x40)
|
|
14
13
|
returndatacopy(ptr, 0, returndatasize())
|
|
15
14
|
revert(ptr, returndatasize())
|
|
@@ -27,8 +27,7 @@ library RevertReasonParser {
|
|
|
27
27
|
// We assume that revert reason is abi-encoded as Error(string)
|
|
28
28
|
bytes4 selector;
|
|
29
29
|
if (data.length >= 4) {
|
|
30
|
-
|
|
31
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
30
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
32
31
|
selector := mload(add(data, 0x20))
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -36,8 +35,7 @@ library RevertReasonParser {
|
|
|
36
35
|
// 68 = 4-byte selector + 32 bytes offset + 32 bytes length
|
|
37
36
|
if (selector == _ERROR_SELECTOR && data.length >= 68) {
|
|
38
37
|
string memory reason;
|
|
39
|
-
|
|
40
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
38
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
41
39
|
// 68 = 32 bytes data length + 4-byte selector + 32 bytes offset
|
|
42
40
|
reason := add(data, 68)
|
|
43
41
|
}
|
|
@@ -55,8 +53,7 @@ library RevertReasonParser {
|
|
|
55
53
|
// 36 = 4-byte selector + 32 bytes integer
|
|
56
54
|
else if (selector == _PANIC_SELECTOR && data.length == 36) {
|
|
57
55
|
uint256 code;
|
|
58
|
-
|
|
59
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
56
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
60
57
|
// 36 = 32 bytes data length + 4-byte selector
|
|
61
58
|
code := mload(add(data, 36))
|
|
62
59
|
}
|
|
@@ -46,8 +46,7 @@ library SafeERC20 {
|
|
|
46
46
|
) internal {
|
|
47
47
|
bytes4 selector = token.transferFrom.selector;
|
|
48
48
|
bool success;
|
|
49
|
-
|
|
50
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
49
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
51
50
|
let data := mload(0x40)
|
|
52
51
|
|
|
53
52
|
mstore(data, selector)
|
|
@@ -77,8 +76,7 @@ library SafeERC20 {
|
|
|
77
76
|
) internal {
|
|
78
77
|
bytes4 selector = IPermit2.transferFrom.selector;
|
|
79
78
|
bool success;
|
|
80
|
-
|
|
81
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
79
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
82
80
|
let data := mload(0x40)
|
|
83
81
|
|
|
84
82
|
mstore(data, selector)
|
|
@@ -159,8 +157,7 @@ library SafeERC20 {
|
|
|
159
157
|
bytes4 permitSelector = IERC20Permit.permit.selector;
|
|
160
158
|
bytes4 daiPermitSelector = IDaiLikePermit.permit.selector;
|
|
161
159
|
bytes4 permit2Selector = IPermit2.permit.selector;
|
|
162
|
-
|
|
163
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
160
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
164
161
|
let ptr := mload(0x40)
|
|
165
162
|
switch permit.length
|
|
166
163
|
case 100 {
|
|
@@ -250,8 +247,7 @@ library SafeERC20 {
|
|
|
250
247
|
address to,
|
|
251
248
|
uint256 amount
|
|
252
249
|
) private returns (bool success) {
|
|
253
|
-
|
|
254
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
250
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
255
251
|
let data := mload(0x40)
|
|
256
252
|
|
|
257
253
|
mstore(data, selector)
|
|
@@ -273,8 +269,7 @@ library SafeERC20 {
|
|
|
273
269
|
function safeDeposit(IWETH weth, uint256 amount) internal {
|
|
274
270
|
if (amount > 0) {
|
|
275
271
|
bytes4 selector = IWETH.deposit.selector;
|
|
276
|
-
|
|
277
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
272
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
278
273
|
mstore(0, selector)
|
|
279
274
|
if iszero(call(gas(), weth, amount, 0, 4, 0, 0)) {
|
|
280
275
|
returndatacopy(0, 0, returndatasize())
|
|
@@ -286,8 +281,7 @@ library SafeERC20 {
|
|
|
286
281
|
|
|
287
282
|
function safeWithdraw(IWETH weth, uint256 amount) internal {
|
|
288
283
|
bytes4 selector = IWETH.withdraw.selector;
|
|
289
|
-
|
|
290
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
284
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
291
285
|
mstore(0, selector)
|
|
292
286
|
mstore(4, amount)
|
|
293
287
|
if iszero(call(gas(), weth, 0, 0, 0x24, 0, 0)) {
|
|
@@ -300,8 +294,7 @@ library SafeERC20 {
|
|
|
300
294
|
function safeWithdrawTo(IWETH weth, uint256 amount, address to) internal {
|
|
301
295
|
safeWithdraw(weth, amount);
|
|
302
296
|
if (to != address(this)) {
|
|
303
|
-
|
|
304
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
297
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
305
298
|
if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
|
|
306
299
|
returndatacopy(0, 0, returndatasize())
|
|
307
300
|
revert(0, returndatasize())
|
|
@@ -16,8 +16,7 @@ library StringUtil {
|
|
|
16
16
|
/// @dev this is the assembly adaptation of highly optimized toHex16 code from Mikhail Vladimirov
|
|
17
17
|
/// https://stackoverflow.com/a/69266989
|
|
18
18
|
function toHex(bytes memory data) internal pure returns (string memory result) {
|
|
19
|
-
|
|
20
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
19
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
21
20
|
function _toHex16(input) -> output {
|
|
22
21
|
output := or(
|
|
23
22
|
and(input, 0xFFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000),
|
|
@@ -133,8 +133,7 @@ library UniERC20 {
|
|
|
133
133
|
that overall data length is greater or equal than string length + extra 64 bytes
|
|
134
134
|
*/
|
|
135
135
|
if (offset == 0x20 && data.length >= 0x40 + len) {
|
|
136
|
-
|
|
137
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
136
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
138
137
|
result := add(data, 0x40)
|
|
139
138
|
}
|
|
140
139
|
return result;
|
|
@@ -149,8 +148,7 @@ library UniERC20 {
|
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
if (len > 0) {
|
|
152
|
-
|
|
153
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
151
|
+
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
|
|
154
152
|
mstore(data, len)
|
|
155
153
|
}
|
|
156
154
|
return string(data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1inch/solidity-utils",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.19",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"build": "tsc -p tsconfig.publish.json",
|
|
14
|
-
"
|
|
15
|
-
"prepublish": "yarn build",
|
|
12
|
+
"clean": "rimraf artifacts cache coverage contracts/hardhat-dependency-compiler dist typechain-types",
|
|
13
|
+
"build": "yarn typechain && cti src -b && tsc -p tsconfig.publish.json",
|
|
14
|
+
"prepack": "yarn clean && yarn build",
|
|
16
15
|
"coverage": "hardhat coverage",
|
|
17
16
|
"format": "yarn format-ts && yarn format-sol",
|
|
18
17
|
"format-ts": "prettier '**/*.ts' --write",
|