Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembly length checks #396

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129534
129661
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131448
131590
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123653
123769
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123795
123911
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125652
125727
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125134
125160
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132512
132587
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131994
132020
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146379
146495
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154954
155070
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154954
155070
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154319
154373
Original file line number Diff line number Diff line change
@@ -1 +1 @@
112048
112141
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119835
119951
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119200
119254
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135308
135401
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128448
128541
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132522
132638
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 @@
120455
120541
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158857
158973
Original file line number Diff line number Diff line change
@@ -1 +1 @@
157809
157884
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142121
142237
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136396
136418
Original file line number Diff line number Diff line change
@@ -1 +1 @@
177446
177562
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148160
148288
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
365994
366088
Original file line number Diff line number Diff line change
@@ -1 +1 @@
374512
374662
Original file line number Diff line number Diff line change
@@ -1 +1 @@
373748
373857
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
317417
317511
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
318087
318181
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
243656
243750
Original file line number Diff line number Diff line change
@@ -1 +1 @@
418864
419040
Original file line number Diff line number Diff line change
@@ -1 +1 @@
323448
323542
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
419970
420064
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withSettlePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
419040
419093
Original file line number Diff line number Diff line change
@@ -1 +1 @@
455814
455908
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_Bytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6929
6978
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118538
118680
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117514
117656
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126329
126471
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131993
132135
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186727
186869
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
173272
173414
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
241511
241653
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
228056
228198
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131001
131143
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117546
117688
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116490
116632
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124796
124938
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118587
118729
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
127402
127544
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131274
131416
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185065
185207
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178587
178729
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238934
239076
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232456
232598
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
218511
218653
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130279
130421
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123801
123943
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117666
117808
36 changes: 36 additions & 0 deletions src/libraries/CalldataDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ library CalldataDecoder {
returns (uint256 tokenId, uint256 liquidity, uint128 amount0, uint128 amount1, bytes calldata hookData)
{
assembly ("memory-safe") {
if lt(params.length, 0x80) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
tokenId := calldataload(params.offset)
liquidity := calldataload(add(params.offset, 0x20))
amount0 := calldataload(add(params.offset, 0x40))
Expand Down Expand Up @@ -179,13 +183,21 @@ library CalldataDecoder {
/// @dev equivalent to: abi.decode(params, (Currency)) in calldata
function decodeCurrency(bytes calldata params) internal pure returns (Currency currency) {
assembly ("memory-safe") {
if lt(params.length, 0x20) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
}
}

/// @dev equivalent to: abi.decode(params, (Currency, Currency)) in calldata
function decodeCurrencyPair(bytes calldata params) internal pure returns (Currency currency0, Currency currency1) {
assembly ("memory-safe") {
if lt(params.length, 0x40) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency0 := calldataload(params.offset)
currency1 := calldataload(add(params.offset, 0x20))
}
Expand All @@ -198,6 +210,10 @@ library CalldataDecoder {
returns (Currency currency0, Currency currency1, address _address)
{
assembly ("memory-safe") {
if lt(params.length, 0x60) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency0 := calldataload(params.offset)
currency1 := calldataload(add(params.offset, 0x20))
_address := calldataload(add(params.offset, 0x40))
Expand All @@ -211,6 +227,10 @@ library CalldataDecoder {
returns (Currency currency, address _address)
{
assembly ("memory-safe") {
if lt(params.length, 0x40) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
_address := calldataload(add(params.offset, 0x20))
}
Expand All @@ -223,6 +243,10 @@ library CalldataDecoder {
returns (Currency currency, address _address, uint256 amount)
{
assembly ("memory-safe") {
if lt(params.length, 0x60) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
_address := calldataload(add(params.offset, 0x20))
amount := calldataload(add(params.offset, 0x40))
Expand All @@ -236,6 +260,10 @@ library CalldataDecoder {
returns (Currency currency, uint256 amount)
{
assembly ("memory-safe") {
if lt(params.length, 0x40) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
amount := calldataload(add(params.offset, 0x20))
}
Expand All @@ -244,6 +272,10 @@ library CalldataDecoder {
/// @dev equivalent to: abi.decode(params, (uint256)) in calldata
function decodeUint256(bytes calldata params) internal pure returns (uint256 amount) {
assembly ("memory-safe") {
if lt(params.length, 0x20) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
amount := calldataload(params.offset)
}
}
Expand All @@ -255,6 +287,10 @@ library CalldataDecoder {
returns (Currency currency, uint256 amount, bool boolean)
{
assembly ("memory-safe") {
if lt(params.length, 0x60) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
amount := calldataload(add(params.offset, 0x20))
boolean := calldataload(add(params.offset, 0x40))
Expand Down
Loading
Loading