Skip to content

Commit

Permalink
masking in toBytes, remove selector constant
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 committed Sep 5, 2024
1 parent 69f556f commit 2fd239f
Show file tree
Hide file tree
Showing 64 changed files with 67 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BaseActionsRouter_mock10commands.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60116
60128
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129770
129782
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131762
131774
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123997
124009
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124139
124151
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47392
47428
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47209
47245
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122755
122791
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122266
122302
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129788
129824
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129299
129335
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141940
141994
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150731
150785
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150731
150785
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150108
150162
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108497
108540
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115612
115666
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115032
115075
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133665
133723
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126450
126508
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128299
128353
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_take_take.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116187
116241
Original file line number Diff line number Diff line change
@@ -1 +1 @@
155218
155272
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154202
154256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136669
136723
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132377
132431
Original file line number Diff line number Diff line change
@@ -1 +1 @@
173229
173283
Original file line number Diff line number Diff line change
@@ -1 +1 @@
143911
143965
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
340370
340424
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348824
348878
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348116
348170
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
318688
318742
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
319358
319412
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
244927
244981
Original file line number Diff line number Diff line change
@@ -1 +1 @@
374761
374815
Original file line number Diff line number Diff line change
@@ -1 +1 @@
324719
324773
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
376019
376073
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withSettlePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
375145
375199
Original file line number Diff line number Diff line change
@@ -1 +1 @@
420166
420220
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_Bytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7098
7110
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115466
115478
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115943
115955
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124758
124770
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130476
130488
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179484
179496
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170184
170196
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
228471
228483
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
219195
219207
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129770
129782
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114760
114772
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115206
115218
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121663
121675
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116964
116976
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125779
125791
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129696
129708
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179528
179540
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
175412
175424
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229367
229379
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
225275
225287
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
220576
220588
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128977
128989
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120944
120956
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116320
116332
10 changes: 4 additions & 6 deletions src/libraries/CalldataDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ library CalldataDecoder {

error SliceOutOfBounds();

/// @notice equivalent to SliceOutOfBounds.selector
bytes4 constant SLICE_ERROR_SELECTOR = 0x3b99b53d;

/// @notice mask used for offsets and lengths to ensure no overflow
/// @dev no sane abi encoding will pass in an offset or length greater than type(uint32).max
uint256 constant OFFSET_OR_LENGTH_MASK = 0xffffffff;
Expand Down Expand Up @@ -228,15 +225,16 @@ library CalldataDecoder {
uint256 length;
uint256 relativeOffset;
assembly ("memory-safe") {
let bytesOffset := and(_bytes.offset, OFFSET_OR_LENGTH_MASK)
// The offset of the `_arg`-th element is `32 * arg`, which stores the offset of the length pointer.
// shl(5, x) is equivalent to mul(32, x)
let lengthPtr := add(_bytes.offset, calldataload(add(_bytes.offset, shl(5, _arg))))
let lengthPtr := add(bytesOffset, and(calldataload(add(bytesOffset, shl(5, _arg))), OFFSET_OR_LENGTH_MASK))
// the number of bytes in the bytes string
length := calldataload(lengthPtr)
length := and(calldataload(lengthPtr), OFFSET_OR_LENGTH_MASK)
// the offset where the bytes string begins
let offset := add(lengthPtr, 0x20)
// the relative offset of the array from the calldata parameter
relativeOffset := sub(offset, _bytes.offset)
relativeOffset := sub(offset, bytesOffset)
// assign the return parameters
res.length := length
res.offset := offset
Expand Down

0 comments on commit 2fd239f

Please sign in to comment.