solidity-scale-codec 0.1.0

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.
Files changed (38) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +48 -0
  3. package/package.json +41 -0
  4. package/src/Scale/Array/BoolArr.sol +44 -0
  5. package/src/Scale/Array/I128Arr.sol +44 -0
  6. package/src/Scale/Array/I16Arr.sol +44 -0
  7. package/src/Scale/Array/I256Arr.sol +44 -0
  8. package/src/Scale/Array/I32Arr.sol +44 -0
  9. package/src/Scale/Array/I64Arr.sol +44 -0
  10. package/src/Scale/Array/I8Arr.sol +44 -0
  11. package/src/Scale/Array/U128Arr.sol +44 -0
  12. package/src/Scale/Array/U16Arr.sol +44 -0
  13. package/src/Scale/Array/U256Arr.sol +44 -0
  14. package/src/Scale/Array/U32Arr.sol +44 -0
  15. package/src/Scale/Array/U64Arr.sol +44 -0
  16. package/src/Scale/Array/U8Arr.sol +44 -0
  17. package/src/Scale/Array.sol +17 -0
  18. package/src/Scale/Bool/Bool.sol +40 -0
  19. package/src/Scale/Bool.sol +4 -0
  20. package/src/Scale/Compact/Compact.sol +543 -0
  21. package/src/Scale/Compact/Compact.t.sol +326 -0
  22. package/src/Scale/Compact.sol +4 -0
  23. package/src/Scale/Signed/I128.sol +39 -0
  24. package/src/Scale/Signed/I16.sol +39 -0
  25. package/src/Scale/Signed/I256.sol +39 -0
  26. package/src/Scale/Signed/I32.sol +39 -0
  27. package/src/Scale/Signed/I64.sol +39 -0
  28. package/src/Scale/Signed/I8.sol +39 -0
  29. package/src/Scale/Signed.sol +10 -0
  30. package/src/Scale/Unsigned/U128.sol +40 -0
  31. package/src/Scale/Unsigned/U16.sol +40 -0
  32. package/src/Scale/Unsigned/U256.sol +40 -0
  33. package/src/Scale/Unsigned/U32.sol +40 -0
  34. package/src/Scale/Unsigned/U64.sol +40 -0
  35. package/src/Scale/Unsigned/U8.sol +40 -0
  36. package/src/Scale/Unsigned.sol +10 -0
  37. package/src/Utils/LittleEndian/LittleEndian.sol +354 -0
  38. package/src/Utils/LittleEndian/LittleEndian.t.sol +542 -0
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ /// @title Scale Codec for the `uint256` type.
5
+ /// @notice SCALE-compliant encoder/decoder for the `uint256` type.
6
+ /// @dev SCALE reference: https://docs.polkadot.com/polkadot-protocol/basics/data-encoding
7
+ library U256 {
8
+ error InvalidU256Length();
9
+
10
+ /// @notice Encodes an `uint256` into SCALE format (32-byte little-endian).
11
+ /// @param value The unsigned 256-bit integer to encode.
12
+ /// @return SCALE-encoded byte sequence.
13
+ function encode(uint256 value) internal pure returns (bytes memory) {
14
+ return abi.encodePacked(toLittleEndian(value));
15
+ }
16
+
17
+ /// @notice Decodes SCALE-encoded bytes into an `uint256`.
18
+ /// @param data The SCALE-encoded byte sequence.
19
+ /// @return The decoded `uint256`.
20
+ function decode(bytes memory data) internal pure returns (uint256) {
21
+ return decodeAt(data, 0);
22
+ }
23
+
24
+ /// @notice Decodes an `uint256` at the specified offset.
25
+ /// @param data The SCALE-encoded byte sequence.
26
+ /// @param offset The byte offset to start decoding from.
27
+ /// @return value The decoded `uint256`.
28
+ function decodeAt(
29
+ bytes memory data,
30
+ uint256 offset
31
+ ) internal pure returns (uint256 value) {
32
+ if (data.length < offset + 32) revert InvalidU256Length();
33
+ assembly { let ptr := add(add(data, 32), offset) value := 0 for { let i := 0 } lt(i, 32) { i := add(i, 1) } { let b := and(mload(add(ptr, i)), 0xFF) value := or(value, shl(mul(i, 8), b)) } }
34
+ }
35
+
36
+ /// @notice Converts an `uint256` to little-endian bytes32
37
+ function toLittleEndian(uint256 value) internal pure returns (bytes32 result) {
38
+ assembly { let v := value v := or(shl(8, and(v, 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF)), shr(8, and(v, 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00))) v := or(shl(16, and(v, 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF)), shr(16, and(v, 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000))) v := or(shl(32, and(v, 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF)), shr(32, and(v, 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000))) v := or(shl(64, and(v, 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF)), shr(64, and(v, 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000))) v := or(shl(128, v), shr(128, v)) result := v }
39
+ }
40
+ }
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ /// @title Scale Codec for the `uint32` type.
5
+ /// @notice SCALE-compliant encoder/decoder for the `uint32` type.
6
+ /// @dev SCALE reference: https://docs.polkadot.com/polkadot-protocol/basics/data-encoding
7
+ library U32 {
8
+ error InvalidU32Length();
9
+
10
+ /// @notice Encodes an `uint32` into SCALE format (4-byte little-endian).
11
+ /// @param value The unsigned 32-bit integer to encode.
12
+ /// @return SCALE-encoded byte sequence.
13
+ function encode(uint32 value) internal pure returns (bytes memory) {
14
+ return abi.encodePacked(toLittleEndian(value));
15
+ }
16
+
17
+ /// @notice Decodes SCALE-encoded bytes into an `uint32`.
18
+ /// @param data The SCALE-encoded byte sequence.
19
+ /// @return The decoded `uint32`.
20
+ function decode(bytes memory data) internal pure returns (uint32) {
21
+ return decodeAt(data, 0);
22
+ }
23
+
24
+ /// @notice Decodes an `uint32` at the specified offset.
25
+ /// @param data The SCALE-encoded byte sequence.
26
+ /// @param offset The byte offset to start decoding from.
27
+ /// @return value The decoded `uint32`.
28
+ function decodeAt(
29
+ bytes memory data,
30
+ uint256 offset
31
+ ) internal pure returns (uint32 value) {
32
+ if (data.length < offset + 4) revert InvalidU32Length();
33
+ assembly { let ptr := add(add(data, 32), offset) let b0 := and(mload(ptr), 0xFF) let b1 := and(mload(add(ptr, 1)), 0xFF) let b2 := and(mload(add(ptr, 2)), 0xFF) let b3 := and(mload(add(ptr, 3)), 0xFF) value := or(or(b0, shl(8, b1)), or(shl(16, b2), shl(24, b3))) }
34
+ }
35
+
36
+ /// @notice Converts an `uint32` to little-endian bytes4
37
+ function toLittleEndian(uint32 value) internal pure returns (bytes4 result) {
38
+ assembly { let v := or(or(shl(24, and(value, 0xff)), shl(16, and(shr(8, value), 0xff))), or(shl(8, and(shr(16, value), 0xff)), and(shr(24, value), 0xff))) result := shl(224, v) }
39
+ }
40
+ }
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ /// @title Scale Codec for the `uint64` type.
5
+ /// @notice SCALE-compliant encoder/decoder for the `uint64` type.
6
+ /// @dev SCALE reference: https://docs.polkadot.com/polkadot-protocol/basics/data-encoding
7
+ library U64 {
8
+ error InvalidU64Length();
9
+
10
+ /// @notice Encodes an `uint64` into SCALE format (8-byte little-endian).
11
+ /// @param value The unsigned 64-bit integer to encode.
12
+ /// @return SCALE-encoded byte sequence.
13
+ function encode(uint64 value) internal pure returns (bytes memory) {
14
+ return abi.encodePacked(toLittleEndian(value));
15
+ }
16
+
17
+ /// @notice Decodes SCALE-encoded bytes into an `uint64`.
18
+ /// @param data The SCALE-encoded byte sequence.
19
+ /// @return The decoded `uint64`.
20
+ function decode(bytes memory data) internal pure returns (uint64) {
21
+ return decodeAt(data, 0);
22
+ }
23
+
24
+ /// @notice Decodes an `uint64` at the specified offset.
25
+ /// @param data The SCALE-encoded byte sequence.
26
+ /// @param offset The byte offset to start decoding from.
27
+ /// @return value The decoded `uint64`.
28
+ function decodeAt(
29
+ bytes memory data,
30
+ uint256 offset
31
+ ) internal pure returns (uint64 value) {
32
+ if (data.length < offset + 8) revert InvalidU64Length();
33
+ assembly { let ptr := add(add(data, 32), offset) value := 0 for { let i := 0 } lt(i, 8) { i := add(i, 1) } { let b := and(mload(add(ptr, i)), 0xFF) value := or(value, shl(mul(i, 8), b)) } }
34
+ }
35
+
36
+ /// @notice Converts an `uint64` to little-endian bytes8
37
+ function toLittleEndian(uint64 value) internal pure returns (bytes8 result) {
38
+ assembly { let v := value v := or(shl(8, and(v, 0x00FF00FF00FF00FF)), shr(8, and(v, 0xFF00FF00FF00FF00))) v := or(shl(16, and(v, 0x0000FFFF0000FFFF)), shr(16, and(v, 0xFFFF0000FFFF0000))) v := or(shl(32, v), shr(32, v)) result := shl(192, v) }
39
+ }
40
+ }
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ /// @title Scale Codec for the `uint8` type.
5
+ /// @notice SCALE-compliant encoder/decoder for the `uint8` type.
6
+ /// @dev SCALE reference: https://docs.polkadot.com/polkadot-protocol/basics/data-encoding
7
+ library U8 {
8
+ error InvalidU8Length();
9
+
10
+ /// @notice Encodes an `uint8` into SCALE format (1-byte little-endian).
11
+ /// @param value The unsigned 8-bit integer to encode.
12
+ /// @return SCALE-encoded byte sequence.
13
+ function encode(uint8 value) internal pure returns (bytes memory) {
14
+ return abi.encodePacked(toLittleEndian(value));
15
+ }
16
+
17
+ /// @notice Decodes SCALE-encoded bytes into an `uint8`.
18
+ /// @param data The SCALE-encoded byte sequence.
19
+ /// @return The decoded `uint8`.
20
+ function decode(bytes memory data) internal pure returns (uint8) {
21
+ return decodeAt(data, 0);
22
+ }
23
+
24
+ /// @notice Decodes an `uint8` at the specified offset.
25
+ /// @param data The SCALE-encoded byte sequence.
26
+ /// @param offset The byte offset to start decoding from.
27
+ /// @return value The decoded `uint8`.
28
+ function decodeAt(
29
+ bytes memory data,
30
+ uint256 offset
31
+ ) internal pure returns (uint8 value) {
32
+ if (data.length < offset + 1) revert InvalidU8Length();
33
+ assembly { value := and(mload(add(add(data, 32), offset)), 0xFF) }
34
+ }
35
+
36
+ /// @notice Converts an `uint8` to little-endian bytes1
37
+ function toLittleEndian(uint8 value) internal pure returns (bytes1 result) {
38
+ return bytes1(value);
39
+ }
40
+ }
@@ -0,0 +1,10 @@
1
+
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ pragma solidity ^0.8.20;
4
+
5
+ import { U8 } from "./Unsigned/U8.sol";
6
+ import { U16 } from "./Unsigned/U16.sol";
7
+ import { U32 } from "./Unsigned/U32.sol";
8
+ import { U64 } from "./Unsigned/U64.sol";
9
+ import { U128 } from "./Unsigned/U128.sol";
10
+ import { U256 } from "./Unsigned/U256.sol";
@@ -0,0 +1,354 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ /// @title LittleEndian
5
+ /// @notice Gas-optimized library for converting unsigned integers from big-endian to little-endian
6
+ library LittleEndian {
7
+ /// @notice Converts a uint8 to little-endian bytes1
8
+ function toLittleEndianU8(uint8 value) internal pure returns (bytes1) {
9
+ return bytes1(value);
10
+ }
11
+
12
+ /// @notice Converts an int8 to little-endian bytes1 (two's complement)
13
+ function toLittleEndianI8(int8 value) internal pure returns (bytes1) {
14
+ return bytes1(uint8(value));
15
+ }
16
+
17
+ /// @notice Converts a uint16 to little-endian bytes2
18
+ function toLittleEndianU16(uint16 value) internal pure returns (bytes2) {
19
+ return bytes2(uint16((value >> 8) | (value << 8)));
20
+ }
21
+
22
+ /// @notice Converts an int16 to little-endian bytes2 (two's complement)
23
+ function toLittleEndianI16(int16 value) internal pure returns (bytes2) {
24
+ return toLittleEndianU16(uint16(value));
25
+ }
26
+
27
+ /// @notice Converts a uint32 to little-endian bytes4
28
+ function toLittleEndianU32(
29
+ uint32 value
30
+ ) internal pure returns (bytes4 result) {
31
+ assembly {
32
+ let v := or(
33
+ or(
34
+ shl(24, and(value, 0xff)),
35
+ shl(16, and(shr(8, value), 0xff))
36
+ ),
37
+ or(shl(8, and(shr(16, value), 0xff)), and(shr(24, value), 0xff))
38
+ )
39
+ result := shl(224, v) // Shift to bytes4 position (left-align in 256-bit word)
40
+ }
41
+ }
42
+
43
+ /// @notice Converts an int32 to little-endian bytes4 (two's complement)
44
+ function toLittleEndianI32(int32 value) internal pure returns (bytes4) {
45
+ return toLittleEndianU32(uint32(value));
46
+ }
47
+
48
+ /// @notice Converts a uint64 to little-endian bytes8
49
+ function toLittleEndianU64(
50
+ uint64 value
51
+ ) internal pure returns (bytes8 result) {
52
+ assembly {
53
+ let v := value
54
+ v := or(
55
+ shl(8, and(v, 0x00FF00FF00FF00FF)),
56
+ shr(8, and(v, 0xFF00FF00FF00FF00))
57
+ )
58
+ v := or(
59
+ shl(16, and(v, 0x0000FFFF0000FFFF)),
60
+ shr(16, and(v, 0xFFFF0000FFFF0000))
61
+ )
62
+ v := or(shl(32, v), shr(32, v))
63
+ result := shl(192, v)
64
+ }
65
+ }
66
+
67
+ /// @notice Converts an int64 to little-endian bytes8 (two's complement)
68
+ function toLittleEndianI64(int64 value) internal pure returns (bytes8) {
69
+ return toLittleEndianU64(uint64(value));
70
+ }
71
+
72
+ /// @notice Converts a uint128 to little-endian bytes16
73
+ function toLittleEndianU128(
74
+ uint128 value
75
+ ) internal pure returns (bytes16 result) {
76
+ assembly {
77
+ let v := value
78
+ v := or(
79
+ shl(8, and(v, 0x00FF00FF00FF00FF00FF00FF00FF00FF)),
80
+ shr(8, and(v, 0xFF00FF00FF00FF00FF00FF00FF00FF00))
81
+ )
82
+ v := or(
83
+ shl(16, and(v, 0x0000FFFF0000FFFF0000FFFF0000FFFF)),
84
+ shr(16, and(v, 0xFFFF0000FFFF0000FFFF0000FFFF0000))
85
+ )
86
+ v := or(
87
+ shl(32, and(v, 0x00000000FFFFFFFF00000000FFFFFFFF)),
88
+ shr(32, and(v, 0xFFFFFFFF00000000FFFFFFFF00000000))
89
+ )
90
+ v := or(shl(64, v), shr(64, v))
91
+ result := shl(128, v)
92
+ }
93
+ }
94
+
95
+ /// @notice Converts an int128 to little-endian bytes16 (two's complement)
96
+ function toLittleEndianI128(int128 value) internal pure returns (bytes16) {
97
+ return toLittleEndianU128(uint128(value));
98
+ }
99
+
100
+ /// @notice Converts a uint256 to little-endian bytes32
101
+ function toLittleEndianU256(
102
+ uint256 value
103
+ ) internal pure returns (bytes32 result) {
104
+ assembly {
105
+ let v := value
106
+ v := or(
107
+ shl(
108
+ 8,
109
+ and(
110
+ v,
111
+ 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF
112
+ )
113
+ ),
114
+ shr(
115
+ 8,
116
+ and(
117
+ v,
118
+ 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00
119
+ )
120
+ )
121
+ )
122
+ v := or(
123
+ shl(
124
+ 16,
125
+ and(
126
+ v,
127
+ 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF
128
+ )
129
+ ),
130
+ shr(
131
+ 16,
132
+ and(
133
+ v,
134
+ 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000
135
+ )
136
+ )
137
+ )
138
+ v := or(
139
+ shl(
140
+ 32,
141
+ and(
142
+ v,
143
+ 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF
144
+ )
145
+ ),
146
+ shr(
147
+ 32,
148
+ and(
149
+ v,
150
+ 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000
151
+ )
152
+ )
153
+ )
154
+ v := or(
155
+ shl(
156
+ 64,
157
+ and(
158
+ v,
159
+ 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF
160
+ )
161
+ ),
162
+ shr(
163
+ 64,
164
+ and(
165
+ v,
166
+ 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000
167
+ )
168
+ )
169
+ )
170
+ v := or(shl(128, v), shr(128, v))
171
+ result := v
172
+ }
173
+ }
174
+
175
+ /// @notice Converts an int256 to little-endian bytes32 (two's complement)
176
+ function toLittleEndianI256(int256 value) internal pure returns (bytes32) {
177
+ return toLittleEndianU256(uint256(value));
178
+ }
179
+
180
+ /// @notice Converts little-endian bytes1 to uint8
181
+ function fromLittleEndianU8(bytes1 value) internal pure returns (uint8) {
182
+ return uint8(value);
183
+ }
184
+
185
+ /// @notice Converts little-endian bytes1 to int8
186
+ function fromLittleEndianI8(bytes1 value) internal pure returns (int8) {
187
+ return int8(uint8(value));
188
+ }
189
+
190
+ /// @notice Converts little-endian bytes2 to uint16
191
+ function fromLittleEndianU16(bytes2 value) internal pure returns (uint16) {
192
+ return uint16(uint8(value[0])) | (uint16(uint8(value[1])) << 8);
193
+ }
194
+
195
+ /// @notice Converts little-endian bytes2 to int16
196
+ function fromLittleEndianI16(bytes2 value) internal pure returns (int16) {
197
+ return int16(fromLittleEndianU16(value));
198
+ }
199
+
200
+ /// @notice Converts little-endian bytes4 to uint32
201
+ function fromLittleEndianU32(
202
+ bytes4 value
203
+ ) internal pure returns (uint32 result) {
204
+ assembly {
205
+ let v := shr(224, value)
206
+ v := or(
207
+ or(shl(24, and(v, 0xff)), shl(16, and(shr(8, v), 0xff))),
208
+ or(shl(8, and(shr(16, v), 0xff)), and(shr(24, v), 0xff))
209
+ )
210
+ result := v
211
+ }
212
+ }
213
+
214
+ /// @notice Converts little-endian bytes4 to int32
215
+ function fromLittleEndianI32(bytes4 value) internal pure returns (int32) {
216
+ return int32(fromLittleEndianU32(value));
217
+ }
218
+
219
+ /// @notice Converts little-endian bytes8 to uint64
220
+ function fromLittleEndianU64(
221
+ bytes8 value
222
+ ) internal pure returns (uint64 result) {
223
+ assembly {
224
+ let v := shr(192, value)
225
+ v := or(
226
+ shl(8, and(v, 0x00FF00FF00FF00FF)),
227
+ shr(8, and(v, 0xFF00FF00FF00FF00))
228
+ )
229
+ v := or(
230
+ shl(16, and(v, 0x0000FFFF0000FFFF)),
231
+ shr(16, and(v, 0xFFFF0000FFFF0000))
232
+ )
233
+ v := or(shl(32, v), shr(32, v))
234
+ result := v
235
+ }
236
+ }
237
+
238
+ /// @notice Converts little-endian bytes8 to int64
239
+ function fromLittleEndianI64(bytes8 value) internal pure returns (int64) {
240
+ return int64(fromLittleEndianU64(value));
241
+ }
242
+
243
+ /// @notice Converts little-endian bytes16 to uint128
244
+ function fromLittleEndianU128(
245
+ bytes16 value
246
+ ) internal pure returns (uint128 result) {
247
+ assembly {
248
+ let v := shr(128, value)
249
+ v := or(
250
+ shl(8, and(v, 0x00FF00FF00FF00FF00FF00FF00FF00FF)),
251
+ shr(8, and(v, 0xFF00FF00FF00FF00FF00FF00FF00FF00))
252
+ )
253
+ v := or(
254
+ shl(16, and(v, 0x0000FFFF0000FFFF0000FFFF0000FFFF)),
255
+ shr(16, and(v, 0xFFFF0000FFFF0000FFFF0000FFFF0000))
256
+ )
257
+ v := or(
258
+ shl(32, and(v, 0x00000000FFFFFFFF00000000FFFFFFFF)),
259
+ shr(32, and(v, 0xFFFFFFFF00000000FFFFFFFF00000000))
260
+ )
261
+ v := or(shl(64, v), shr(64, v))
262
+ result := v
263
+ }
264
+ }
265
+
266
+ /// @notice Converts little-endian bytes16 to int128
267
+ function fromLittleEndianI128(
268
+ bytes16 value
269
+ ) internal pure returns (int128) {
270
+ return int128(fromLittleEndianU128(value));
271
+ }
272
+
273
+ /// @notice Converts little-endian bytes32 to uint256
274
+ function fromLittleEndianU256(
275
+ bytes32 value
276
+ ) internal pure returns (uint256 result) {
277
+ assembly {
278
+ let v := value
279
+ v := or(
280
+ shl(
281
+ 8,
282
+ and(
283
+ v,
284
+ 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF
285
+ )
286
+ ),
287
+ shr(
288
+ 8,
289
+ and(
290
+ v,
291
+ 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00
292
+ )
293
+ )
294
+ )
295
+ v := or(
296
+ shl(
297
+ 16,
298
+ and(
299
+ v,
300
+ 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF
301
+ )
302
+ ),
303
+ shr(
304
+ 16,
305
+ and(
306
+ v,
307
+ 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000
308
+ )
309
+ )
310
+ )
311
+ v := or(
312
+ shl(
313
+ 32,
314
+ and(
315
+ v,
316
+ 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF
317
+ )
318
+ ),
319
+ shr(
320
+ 32,
321
+ and(
322
+ v,
323
+ 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000
324
+ )
325
+ )
326
+ )
327
+ v := or(
328
+ shl(
329
+ 64,
330
+ and(
331
+ v,
332
+ 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF
333
+ )
334
+ ),
335
+ shr(
336
+ 64,
337
+ and(
338
+ v,
339
+ 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000
340
+ )
341
+ )
342
+ )
343
+ v := or(shl(128, v), shr(128, v))
344
+ result := v
345
+ }
346
+ }
347
+
348
+ /// @notice Converts little-endian bytes32 to int256
349
+ function fromLittleEndianI256(
350
+ bytes32 value
351
+ ) internal pure returns (int256) {
352
+ return int256(fromLittleEndianU256(value));
353
+ }
354
+ }