Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
215 changes: 215 additions & 0 deletions solidity/security/uniswap-v4-callback-not-protected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ struct BeforeSwapDelta {
int128 deltaAmountUnspecified;
}

error HookNotImplemented();
error NotImplemented();

contract Test {
modifier onlyPoolManager() {
require(msg.sender == address(poolManager), "Not authorized");
Expand Down Expand Up @@ -176,6 +179,218 @@ contract Test {
return bytes4(0);
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function beforeSwap(
address,
PoolKey calldata,
IPoolManager.SwapParams calldata,
bytes calldata
) external pure override returns (bytes4, BeforeSwapDelta memory, uint24) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function afterInitialize(
address,
PoolKey calldata,
uint160,
int24,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function beforeAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function afterRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
BeforeSwapDelta memory,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function beforeDonate(
address,
PoolKey calldata,
uint256,
uint256,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function afterSwap(
address,
PoolKey calldata,
IPoolManager.SwapParams calldata,
BeforeSwapDelta memory,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function afterDonate(
address,
PoolKey calldata,
uint256,
uint256,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function beforeRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function beforeInitialize(
address,
PoolKey calldata,
uint160,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with HookNotImplemented() should not be detected
function afterAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
BeforeSwapDelta memory,
bytes calldata
) external pure override returns (bytes4) {
revert HookNotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function beforeSwap(
address,
PoolKey calldata,
IPoolManager.SwapParams calldata,
bytes calldata
) external pure override returns (bytes4, BeforeSwapDelta memory, uint24) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function afterInitialize(
address,
PoolKey calldata,
uint160,
int24,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function beforeAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function afterRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
BeforeSwapDelta memory,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function beforeDonate(
address,
PoolKey calldata,
uint256,
uint256,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function afterSwap(
address,
PoolKey calldata,
IPoolManager.SwapParams calldata,
BeforeSwapDelta memory,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function afterDonate(
address,
PoolKey calldata,
uint256,
uint256,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function beforeRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function beforeInitialize(
address,
PoolKey calldata,
uint160,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ok: uniswap-v4-callback-not-protected - functions that revert with NotImplemented() should not be detected
function afterAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
BeforeSwapDelta memory,
bytes calldata
) external pure override returns (bytes4) {
revert NotImplemented();
}

// ruleid: uniswap-v4-callback-not-protected
function beforeSwap(
address sender,
Expand Down
12 changes: 12 additions & 0 deletions solidity/security/uniswap-v4-callback-not-protected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ rules:
- pattern-not: function $CALLBACK(...) external view onlyPoolManager whenNotPaused {...}
- pattern-not: function $CALLBACK(...) external override onlyPoolManager whenNotPaused {...}
- pattern-not: function $CALLBACK(...) external view override onlyPoolManager whenNotPaused {...}
- pattern-not: |
function $CALLBACK(...) external {...
...
revert HookNotImplemented();
...
}
- pattern-not: |
function $CALLBACK(...) external {...
...
revert NotImplemented();
...
}
- pattern-not: |
function $CALLBACK(...) external {...
...
Expand Down
Loading