From cf0e22fee85767b889bb11b32c0264a603834a5e Mon Sep 17 00:00:00 2001 From: Roman Agureev Date: Fri, 13 Sep 2024 19:02:37 +0300 Subject: [PATCH] feat: remove msg.sender from salt --- contracts/ChildGaugeFactory.vy | 2 +- contracts/RootGaugeFactory.vy | 2 +- scripts/calculate_proxy.py | 4 ++-- .../test_deploy_child_gauge.py | 2 +- .../test_gauge_addresses.py | 20 +------------------ .../test_root_gauge_deploy.py | 2 +- 6 files changed, 7 insertions(+), 25 deletions(-) diff --git a/contracts/ChildGaugeFactory.vy b/contracts/ChildGaugeFactory.vy index 1324acc..820df80 100644 --- a/contracts/ChildGaugeFactory.vy +++ b/contracts/ChildGaugeFactory.vy @@ -166,7 +166,7 @@ def deploy_gauge(_lp_token: address, _salt: bytes32, _manager: address = msg.sen gauge_data: uint256 = 1 # set is_valid_gauge = True implementation: address = self.get_implementation - salt: bytes32 = keccak256(_abi_encode(chain.id, msg.sender, _salt)) + salt: bytes32 = keccak256(_abi_encode(chain.id, _salt)) gauge: address = create_minimal_proxy_to( implementation, salt=salt ) diff --git a/contracts/RootGaugeFactory.vy b/contracts/RootGaugeFactory.vy index 9978faf..48a70b9 100644 --- a/contracts/RootGaugeFactory.vy +++ b/contracts/RootGaugeFactory.vy @@ -114,7 +114,7 @@ def deploy_gauge(_chain_id: uint256, _salt: bytes32) -> RootGauge: assert bridger != empty(Bridger) # dev: chain id not supported implementation: address = self.get_implementation - salt: bytes32 = keccak256(_abi_encode(_chain_id, msg.sender, _salt)) + salt: bytes32 = keccak256(_abi_encode(_chain_id, _salt)) gauge: RootGauge = RootGauge(create_minimal_proxy_to( implementation, value=msg.value, diff --git a/scripts/calculate_proxy.py b/scripts/calculate_proxy.py index 05221de..acb8fda 100644 --- a/scripts/calculate_proxy.py +++ b/scripts/calculate_proxy.py @@ -41,12 +41,12 @@ def create2_address_of(_addr, _salt, _initcode): return to_address(keccak(prefix + addr + salt + keccak(initcode))[12:]) -def main(_chain_id: str, _deployer: str, _salt: str): +def main(_chain_id: str, _salt: str): factory = RootGaugeFactory.at("0xabC000d88f23Bb45525E447528DBF656A9D55bf5") implementation_addr = factory.get_implementation() init_code = vyper_proxy_init_code(implementation_addr) salt = keccak( - encode_single("(uint256,address,bytes32)", [int(_chain_id), _deployer, HexBytes(_salt)]) + encode_single("(uint256,bytes32)", [int(_chain_id), HexBytes(_salt)]) ) print(create2_address_of(factory.address, salt, init_code)) diff --git a/tests/child_gauge_factory/test_deploy_child_gauge.py b/tests/child_gauge_factory/test_deploy_child_gauge.py index 1ef6ff4..c344615 100644 --- a/tests/child_gauge_factory/test_deploy_child_gauge.py +++ b/tests/child_gauge_factory/test_deploy_child_gauge.py @@ -16,7 +16,7 @@ def test_deploy_child_gauge( ): proxy_init_code = vyper_proxy_init_code(child_gauge_impl.address) salt = encode( - ["(uint256,address,bytes32)"], [(chain.id, alice.address, (0).to_bytes(32, "big"))] + ["(uint256,bytes32)"], [(chain.id, (0).to_bytes(32, "big"))] ) expected = create2_address_of(child_gauge_factory.address, web3.keccak(salt), proxy_init_code) diff --git a/tests/root_gauge_factory/test_gauge_addresses.py b/tests/root_gauge_factory/test_gauge_addresses.py index c1ded09..a6ac134 100644 --- a/tests/root_gauge_factory/test_gauge_addresses.py +++ b/tests/root_gauge_factory/test_gauge_addresses.py @@ -1,26 +1,9 @@ from brownie import Contract, web3 -from brownie.convert import to_address from eth_abi import encode -from hexbytes import HexBytes SALT = b"5A170000000000000000000000000000" -def salt(chain_id, sender): - return web3.keccak(encode(["(uint256,address,bytes32)"], [(chain_id, sender, SALT)])) - - -def zksync_create2_address_of(_addr, _salt, _initcode): - prefix = web3.keccak(text="zksyncCreate2") - addr = HexBytes(_addr) - addr = HexBytes(0) * 12 + addr + HexBytes(0) * (20 - len(addr)) - salt = HexBytes(_salt) - initcode = HexBytes(_initcode) - return to_address( - web3.keccak(prefix + addr + salt + web3.keccak(initcode) + web3.keccak(b""))[12:] - ) - - def test_gauge_address( alice, chain, @@ -57,12 +40,11 @@ def test_gauge_address_chain_id( RootGauge, vyper_proxy_init_code, create2_address_of, - web3, ): chain_id = chain.id + 1 proxy_init_code = vyper_proxy_init_code(child_gauge_impl.address) expected = create2_address_of( - child_gauge_factory.address, salt(chain_id, alice.address), proxy_init_code + child_gauge_factory.address, web3.keccak(encode(["(uint256,bytes32)"], [(chain_id, SALT)])), proxy_init_code ) bridger = MockBridger.deploy({"from": alice}) root_gauge_factory.set_child( diff --git a/tests/root_gauge_factory/test_root_gauge_deploy.py b/tests/root_gauge_factory/test_root_gauge_deploy.py index f56bde7..b18f3fc 100644 --- a/tests/root_gauge_factory/test_root_gauge_deploy.py +++ b/tests/root_gauge_factory/test_root_gauge_deploy.py @@ -15,7 +15,7 @@ def test_deploy_root_gauge( ): proxy_init_code = vyper_proxy_init_code(root_gauge_impl.address) salt = encode( - ["(uint256,address,bytes32)"], [(chain.id, alice.address, (0).to_bytes(32, "big"))] + ["(uint256,bytes32)"], [(chain.id, (0).to_bytes(32, "big"))] ) expected = create2_address_of(root_gauge_factory.address, web3.keccak(salt), proxy_init_code)