Skip to content

Commit 58fa41b

Browse files
committed
Include address in salt
1 parent 81791ba commit 58fa41b

File tree

6 files changed

+71
-37
lines changed

6 files changed

+71
-37
lines changed

src/UniswapV4DeployerCompetition.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ contract UniswapV4DeployerCompetition is IUniswapV4DeployerCompetition {
4343
revert CompetitionOver(block.timestamp, competitionDeadline);
4444
}
4545

46+
address saltSubAddress = address(bytes20(salt));
47+
if (saltSubAddress != msg.sender && saltSubAddress != address(0)) revert InvalidSender(salt, msg.sender);
48+
4649
address newAddress = Create2.computeAddress(salt, initCodeHash, address(this));
4750
if (bestAddress != address(0) && !newAddress.betterThan(bestAddress)) {
4851
revert WorseAddress(newAddress, bestAddress, newAddress.score(), bestAddress.score());

src/interfaces/IUniswapV4DeployerCompetition.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface IUniswapV4DeployerCompetition {
1111
error CompetitionOver(uint256 currentTime, uint256 deadline);
1212
error NotAllowedToDeploy(address sender, address deployer);
1313
error WorseAddress(address newAddress, address bestAddress, uint256 newScore, uint256 bestScore);
14-
error InvalidTokenId(uint256 tokenId);
14+
error InvalidSender(bytes32 salt, address sender);
1515

1616
/// @notice Updates the best address if the new address has a better vanity score
1717
/// @param salt The salt to use to compute the new address with CREATE2

src/libraries/VanityAddressLib.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.0;
33

4-
import {console2} from "forge-std/console2.sol";
5-
64
/// @title VanityAddressLib
75
/// @notice A library to score addresses based on their vanity
86
library VanityAddressLib {

test/UniswapV4DeployerCompetition.t.sol

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
pragma solidity ^0.8.20;
33

44
import {Owned} from "solmate/src/auth/Owned.sol";
5-
import {Test, console2} from "forge-std/Test.sol";
5+
import {Test} from "forge-std/Test.sol";
6+
import {console2} from "forge-std/console2.sol";
67
import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol";
78
import {UniswapV4DeployerCompetition} from "../src/UniswapV4DeployerCompetition.sol";
89
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol";
@@ -20,6 +21,8 @@ contract UniswapV4DeployerCompetitionTest is Test {
2021
address winner;
2122
uint256 competitionDeadline;
2223

24+
bytes32 mask20bytes = bytes32(uint256(type(uint96).max));
25+
2326
function setUp() public {
2427
competitionDeadline = block.timestamp + 7 days;
2528
v4Owner = makeAddr("V4Owner");
@@ -31,7 +34,9 @@ contract UniswapV4DeployerCompetitionTest is Test {
3134
assertEq(competition.v4Owner(), v4Owner);
3235
}
3336

34-
function testUpdateBestAddress(bytes32 salt) public {
37+
function test_updateBestAddress_succeeds(bytes32 salt) public {
38+
salt = (salt & mask20bytes) | bytes32(bytes20(winner));
39+
3540
assertEq(competition.bestAddress(), address(0));
3641
assertEq(competition.bestAddressSubmitter(), address(0));
3742
assertEq(competition.bestAddressSalt(), bytes32(0));
@@ -57,7 +62,7 @@ contract UniswapV4DeployerCompetitionTest is Test {
5762
assertEq(address(competition).balance, 0 ether);
5863
}
5964

60-
function testCompetitionOver(bytes32 salt) public {
65+
function test_updateBestAddress_reverts_CompetitionOver(bytes32 salt) public {
6166
vm.warp(competition.competitionDeadline() + 1);
6267
vm.expectRevert(
6368
abi.encodeWithSelector(
@@ -69,7 +74,52 @@ contract UniswapV4DeployerCompetitionTest is Test {
6974
competition.updateBestAddress(salt);
7075
}
7176

72-
function testUpdateBestAddressOpen(bytes32 salt) public {
77+
function test_updateBestAddress_reverts_InvalidSigner(bytes32 salt) public {
78+
vm.assume(bytes20(salt) != bytes20(0));
79+
vm.assume(bytes20(salt) != bytes20(winner));
80+
81+
vm.expectRevert(abi.encodeWithSelector(IUniswapV4DeployerCompetition.InvalidSender.selector, salt, winner));
82+
vm.prank(winner);
83+
competition.updateBestAddress(salt);
84+
}
85+
86+
function test_updateBestAddress_equalSalt_reverts_WorseAddress(bytes32 salt) public {
87+
vm.assume(salt != bytes32(0));
88+
console2.logBytes32(salt);
89+
salt = (salt & mask20bytes) | bytes32(bytes20(winner));
90+
console2.logBytes32(salt);
91+
92+
vm.prank(winner);
93+
competition.updateBestAddress(salt);
94+
assertFalse(competition.bestAddress() == address(0));
95+
assertEq(competition.bestAddressSubmitter(), winner);
96+
assertEq(competition.bestAddressSalt(), salt);
97+
98+
bytes32 newSalt = (salt & mask20bytes) | bytes32(bytes20(address(1)));
99+
address newAddr = Create2.computeAddress(newSalt, initCodeHash, address(competition));
100+
if (!newAddr.betterThan(competition.bestAddress())) {
101+
vm.expectRevert(
102+
abi.encodeWithSelector(
103+
IUniswapV4DeployerCompetition.WorseAddress.selector,
104+
newAddr,
105+
competition.bestAddress(),
106+
newAddr.score(),
107+
competition.bestAddress().score()
108+
)
109+
);
110+
vm.prank(address(1));
111+
competition.updateBestAddress(newSalt);
112+
} else {
113+
vm.prank(address(1));
114+
competition.updateBestAddress(newSalt);
115+
assertEq(competition.bestAddressSubmitter(), address(1));
116+
assertEq(competition.bestAddressSalt(), newSalt);
117+
}
118+
}
119+
120+
function test_deploy_succeeds(bytes32 salt) public {
121+
salt = (salt & mask20bytes) | bytes32(bytes20(winner));
122+
73123
vm.prank(winner);
74124
competition.updateBestAddress(salt);
75125
address v4Core = competition.bestAddress();
@@ -81,7 +131,9 @@ contract UniswapV4DeployerCompetitionTest is Test {
81131
assertEq(TickMath.MAX_TICK_SPACING, type(int16).max);
82132
}
83133

84-
function testCompetitionNotOver(bytes32 salt, uint256 timestamp) public {
134+
function test_deploy_reverts_CompetitionNotOver(bytes32 salt, uint256 timestamp) public {
135+
salt = (salt & mask20bytes) | bytes32(bytes20(winner));
136+
85137
vm.assume(timestamp < competition.competitionDeadline());
86138
vm.prank(winner);
87139
competition.updateBestAddress(salt);
@@ -94,15 +146,19 @@ contract UniswapV4DeployerCompetitionTest is Test {
94146
competition.deploy(abi.encodePacked(type(PoolManager).creationCode, uint256(uint160(v4Owner))));
95147
}
96148

97-
function testInvalidBytecode(bytes32 salt) public {
149+
function test_deploy_reverts_InvalidBytecode(bytes32 salt) public {
150+
salt = (salt & mask20bytes) | bytes32(bytes20(winner));
151+
98152
vm.prank(winner);
99153
competition.updateBestAddress(salt);
100154
vm.expectRevert(IUniswapV4DeployerCompetition.InvalidBytecode.selector);
101155
// set the owner as the winner not the correct owner
102156
competition.deploy(abi.encodePacked(type(PoolManager).creationCode, uint256(uint160(winner))));
103157
}
104158

105-
function testInvalidMsgSender(bytes32 salt) public {
159+
function test_deploy_reverts_InvalidMsgSender(bytes32 salt) public {
160+
salt = (salt & mask20bytes) | bytes32(bytes20(winner));
161+
106162
vm.prank(winner);
107163
competition.updateBestAddress(salt);
108164
vm.warp(competition.competitionDeadline() + 1);
@@ -113,34 +169,13 @@ contract UniswapV4DeployerCompetitionTest is Test {
113169
competition.deploy(abi.encodePacked(type(PoolManager).creationCode, uint256(uint160(v4Owner))));
114170
}
115171

116-
function testAfterExcusiveDeployDeadline(bytes32 salt) public {
172+
function test_deploy_afterExcusiveDeployDeadline(bytes32 salt) public {
173+
salt = (salt & mask20bytes) | bytes32(bytes20(winner));
174+
117175
vm.prank(winner);
118176
competition.updateBestAddress(salt);
119177
vm.warp(competition.exclusiveDeployDeadline() + 1);
120178
vm.prank(address(1));
121179
competition.deploy(abi.encodePacked(type(PoolManager).creationCode, uint256(uint160(v4Owner))));
122180
}
123-
124-
function testEqualSaltNotChanged(bytes32 salt) public {
125-
vm.prank(winner);
126-
competition.updateBestAddress(salt);
127-
assertFalse(competition.bestAddress() == address(0));
128-
assertEq(competition.bestAddressSubmitter(), winner);
129-
assertEq(competition.bestAddressSalt(), salt);
130-
131-
address newAddr = Create2.computeAddress(salt >> 1, initCodeHash, address(competition));
132-
vm.assume(competition.bestAddress().betterThan(newAddr));
133-
134-
vm.prank(address(1));
135-
vm.expectRevert(
136-
abi.encodeWithSelector(
137-
IUniswapV4DeployerCompetition.WorseAddress.selector,
138-
newAddr,
139-
competition.bestAddress(),
140-
newAddr.score(),
141-
competition.bestAddress().score()
142-
)
143-
);
144-
competition.updateBestAddress(salt >> 1);
145-
}
146181
}

test/libraries/VanityAddressLib.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.24;
33

4-
import {Test, console} from "forge-std/Test.sol";
4+
import {Test} from "forge-std/Test.sol";
55
import {VanityAddressLib} from "../../src/libraries/VanityAddressLib.sol";
66

77
contract VanityAddressLibTest is Test {

test/position-managers/PositionManager.modifyLiquidities.t.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import {ActionConstants} from "../../src/libraries/ActionConstants.sol";
3333
import {Planner, Plan} from "../shared/Planner.sol";
3434
import {DeltaResolver} from "../../src/base/DeltaResolver.sol";
3535

36-
import "forge-std/console2.sol";
37-
3836
contract PositionManagerModifyLiquiditiesTest is Test, PosmTestSetup, LiquidityFuzzers {
3937
using StateLibrary for IPoolManager;
4038
using PoolIdLibrary for PoolKey;

0 commit comments

Comments
 (0)