Skip to content

Commit

Permalink
fix: add code size check
Browse files Browse the repository at this point in the history
  • Loading branch information
devtooligan committed Jun 17, 2023
1 parent ce535ff commit 2c777e8
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 14 deletions.
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/v4-periphery"]
path = lib/v4-periphery
url = https://github.com/Uniswap/v4-periphery
[submodule "lib/v4-core"]
path = lib/v4-core
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img align="right" width="150" height="150" top="100" src="./assets/blueprint.png">

# huff-project-template • [![ci](https://github.com/huff-language/huff-project-template/actions/workflows/ci.yaml/badge.svg)](https://github.com/huff-language/huff-project-template/actions/workflows/ci.yaml) ![license](https://img.shields.io/github/license/huff-language/huff-project-template.svg) ![solidity](https://img.shields.io/badge/solidity-^0.8.15-lightgrey)
# huff-project-template • [![ci](https://github.com/huff-language/huff-project-template/actions/workflows/ci.yaml/badge.svg)](https://github.com/huff-language/huff-project-template/actions/workflows/ci.yaml) ![license](https://img.shields.io/github/license/huff-language/huff-project-template.svg) ![solidity](https://img.shields.io/badge/solidity-^0.8.19-lightgrey)

Versatile Huff Project Template using Foundry.

Expand All @@ -11,7 +11,7 @@ Versatile Huff Project Template using Foundry.

The following will need to be installed in order to use this template. Please follow the links and instructions.

- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- You'll know you've done it right if you can run `git --version`
- [Foundry / Foundryup](https://github.com/gakonst/foundry)
- This will install `forge`, `cast`, and `anvil`
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[profile.default]
solc_version = '0.8.15'
solc_version = '0.8.19'
auto_detect_solc = false
optimizer = true
optimizer_runs = 200 # Default amount
Expand Down
2 changes: 1 addition & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.15;
pragma solidity ^0.8.19;

import "foundry-huff/HuffDeployer.sol";
import "forge-std/Script.sol";
Expand Down
Empty file removed src/HookDeployerLib.sol
Empty file.
2 changes: 1 addition & 1 deletion src/ReferenceImplementations/SaltMiner.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.15;
pragma solidity =0.8.19;

contract HookMineAndSinker {
uint256 constant PREFIX_MASK = 0x00ff00000000000000000000000000000000000000;
Expand Down
18 changes: 18 additions & 0 deletions src/SaltMiner.huff
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*

███████╗ █████╗ ██╗ ████████╗███╗ ███╗██╗███╗ ██╗███████╗██████╗
██╔════╝██╔══██╗██║ ╚══██╔══╝████╗ ████║██║████╗ ██║██╔════╝██╔══██╗
███████╗███████║██║ ██║ ██╔████╔██║██║██╔██╗ ██║█████╗ ██████╔╝
╚════██║██╔══██║██║ ██║ ██║╚██╔╝██║██║██║╚██╗██║██╔══╝ ██╔══██╗
███████║██║ ██║███████╗██║ ██║ ╚═╝ ██║██║██║ ╚████║███████╗██║ ██║
╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝

*/

/// @notice A utility for finding the salt for a CREATE2 address for a UniV4 Hook
/// @author devtooligan

/* Interface */
#define function mineSalt(bytes32,uint256,address) view returns (uint256,address)

Expand Down Expand Up @@ -32,6 +46,10 @@
[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
Expand Down
38 changes: 32 additions & 6 deletions test/SaltMiner.t.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.15;
pragma solidity ^0.8.19;

import "foundry-huff/HuffDeployer.sol";
import {HookDeployer} from "../src/HookDeployer.sol";
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol";
import {PoolManager} from "@uniswap/v4-core/contracts/PoolManager.sol";
import {LimitOrder} from "@uniswap/v4-periphery/contracts/hooks/examples/LimitOrder.sol";
import "forge-std/Test.sol";
import "forge-std/console.sol";

contract SaltMinerTest is Test {
/// @dev Address of the SaltMiner contract.
ISaltMiner public saltMiner;
PoolManager manager;

/// @dev Setup the testing environment.
function setUp() public {
saltMiner = ISaltMiner(HuffDeployer.deploy("SaltMiner"));
manager = new PoolManager(500000);

}

/// @dev Ensure that you can set and get the value.
function testMineSalt() public {
(uint256 salt, address newAddress) = saltMiner.mineSalt(keccak256("myCode"), uint(0x004400000000000000000000000000000000000000), address(this));
console.log(salt);
console.log(newAddress);
function testMineSalt__LimitOrder() public {
// LimitOrder
bytes memory initCode = abi.encodePacked(type(LimitOrder).creationCode, abi.encode(manager));
bytes32 initCodeHash = keccak256(initCode);
uint prefix = HookDeployer.getPrefix(Hooks.Calls({
beforeInitialize: false,
afterInitialize: true,
beforeModifyPosition: false,
afterModifyPosition: false,
beforeSwap: false,
afterSwap: true,
beforeDonate: false,
afterDonate: false
}));

uint start = gasleft();
(uint256 salt, address expectedAddress) = saltMiner.mineSalt(initCodeHash, prefix, address(this));
console.log("gas used: %s", salt);
address actualAddress = HookDeployer.deployHook(initCode, salt);

// console.log(salt);
// console.log(expectedAddress);
// console.log(actualAddress);
}
}

Expand Down

0 comments on commit 2c777e8

Please sign in to comment.