diff --git a/.gitmodules b/.gitmodules index ded3488..b124aaf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,7 +9,7 @@ url = https://github.com/Uniswap/v4-core [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts - url = https://github.com/OpenZeppelin/openzeppelin-contracts -[submodule "lib/v4-periphery"] - path = lib/v4-periphery - url = https://github.com/Uniswap/v4-periphery + url = https://github.com/openzeppelin/openzeppelin-contracts +[submodule "lib/periphery-next"] + path = lib/periphery-next + url = https://github.com/Uniswap/periphery-next diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts new file mode 160000 index 0000000..a7a94c7 --- /dev/null +++ b/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit a7a94c77463acea95d979aae1580fb0ddc3b6a1e diff --git a/lib/periphery-next b/lib/periphery-next new file mode 160000 index 0000000..e9ea3c9 --- /dev/null +++ b/lib/periphery-next @@ -0,0 +1 @@ +Subproject commit e9ea3c9cb6caaa7b50f51a4e52073b60b8ccfe3a diff --git a/lib/v4-periphery b/lib/v4-periphery deleted file mode 160000 index bb589f1..0000000 --- a/lib/v4-periphery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bb589f1340a2e60ffc476d05cb0794edaa5b0810 diff --git a/remappings.txt b/remappings.txt index 26e8d88..ca81926 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,4 +1,4 @@ @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ -@uniswap/v4-periphery/=lib/v4-periphery/ +@uniswap/v4-periphery/=lib/periphery-next/ @uniswap/v4-core/=lib/v4-core/ forge-std/=lib/forge-std/src/ \ No newline at end of file diff --git a/src/SaltMiner.huff b/src/SaltMiner.huff index 626fcd8..08e7611 100644 --- a/src/SaltMiner.huff +++ b/src/SaltMiner.huff @@ -13,22 +13,19 @@ /// @author devtooligan /* Interface */ -#define function mineSalt(bytes32,uint256,address) view returns (uint256,address) +#define function mineSalt(address,uint256,bytes32) view returns (uint256,address) /* Constants */ #define constant CREATE2_MARKER = 0xff #define constant PREFIX_MASK = 0x00ff00000000000000000000000000000000000000 #define constant ADDRESS_MASK = 0x000000000000000000000000FFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF -/* Methods */ -#define macro _MINE_SALT() = takes (3) returns (2) { - // takes: [deployerAddress, initCodeHash, prefix] +#define macro MINE_SALT() = takes (0) returns (0) { + 0x60 0x04 0x00 calldatacopy + 0x20 mload // [prefix] - 0x00 mstore // [initCodeHash, prefix] - [CREATE2_MARKER] // [0xff,initCodeHash, prefix] - 0x0b mstore8 // [initCodeHash, prefix] - // leave 0x20-0x3f untouched so initial salt is 0x00 - 0x40 mstore // [prefix] + [CREATE2_MARKER] // [0xff, prefix] + 0x0b mstore8 // [prefix] // Memory layout // Hashing : 0xff(1) . deployerAddress(20) . salt(32) . initCodeHash(32) @@ -38,41 +35,27 @@ // 0x00: 00 00 00 00 00 00 00 00 00 00 00 ff |-- address(this) -------------- | // 0x20: |------------------------ salt ------------------------------------- | // 0x40: |----------------- keccak256(initCode) ----------------------------- | + + timestamp + begin_loop: // [salt, prefix] + 0x20 mstore // [prefix] + 0x55 0x0b sha3 // [hash, prefix] + dup1 // [hash, hash, prefix] + [PREFIX_MASK] and // [maskedHash, hash, prefix] + dup3 // [prefix, maskedHash, hash, prefix] + sub // [matchesPrefix, hash, prefix] + begin_loop + jumpi - begin_loop: - 0x55 0x0b sha3 // [hash, prefix] - [ADDRESS_MASK] and // [newAddress, prefix] - dup1 // [newAddress, newAddress, prefix] - [PREFIX_MASK] and // [maskedAddress, newAddress, prefix] - dup3 // [prefix, maskedAddress, newAddress, prefix] - eq // [matchesPrefix, newAddress, prefix] - dup2 // [newAddress, matchesPrefix, newAddress, prefix] - extcodesize // [codeSize, matchesPrefix, newAddress, prefix] - iszero // [noCode, matchesPrefix, newAddress, prefix] - and // [matchesPrefix && noCode, newAddress, prefix] - found jumpi // [newAddress, prefix] - - // use remaining gas as new salt, cheaper than maintining a counter - gas // [salt, newAddress, prefix] - // update salt in memory, not needed on stack - 0x20 mstore // [newAddress, prefix] - pop // [prefix] - begin_loop jump // [prefix] + dup1 // [hash, hash, prefix] + extcodesize // [codeSize, hash, prefix] + begin_loop + jumpi - found: // [newAddress, prefix] - swap1 // [prefix, newAddress] - pop // [newAddress] - 0x20 mload // [salt, newAddress] -} - -#define macro MINE_SALT() = takes (0) returns (0) { - 0x24 calldataload // [prefix] - 0x04 calldataload // [initCodeHash, prefix] - 0x44 calldataload // [deployerAddress, initCodeHash, prefix] - _MINE_SALT() // [salt, newAddress] - 0x00 mstore // [newAddress] - 0x20 mstore // [] - 0x40 0x00 return // [] + [ADDRESS_MASK] and // [newAddress, prefix] + 0x40 mstore // [prefix] + pop + 0x40 0x20 return } #define macro MAIN() = takes (0) returns (0) { diff --git a/test/SaltMiner.t.sol b/test/SaltMiner.t.sol index 14e6d70..f5e0889 100644 --- a/test/SaltMiner.t.sol +++ b/test/SaltMiner.t.sol @@ -36,14 +36,14 @@ contract SaltMinerTest is Test { afterDonate: false })); - uint start = gasleft(); - (uint256 salt, address expectedAddress) = saltMiner.mineSalt(initCodeHash, prefix, address(this)); - console.log("gas used: %s", salt); + // uint start = gasleft(); + (uint256 salt, address expectedAddress) = saltMiner.mineSalt(address(this), prefix,initCodeHash ); + console.log("salt: %s", salt); address actualAddress = HookDeployer.deployHook(initCode, salt); assertEq(actualAddress, expectedAddress); } } interface ISaltMiner { - function mineSalt(bytes32 initCodeHash,uint256 prefix, address deployer) external view returns (uint256,address); + function mineSalt( address deployer,uint256 prefix,bytes32 initCodeHash) external view returns (uint256,address); }