Skip to content

Commit

Permalink
feat: remove msg.sender from salt
Browse files Browse the repository at this point in the history
  • Loading branch information
romanagureev committed Sep 13, 2024
1 parent 58ef8b9 commit cf0e22f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion contracts/ChildGaugeFactory.vy
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion contracts/RootGaugeFactory.vy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions scripts/calculate_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion tests/child_gauge_factory/test_deploy_child_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 1 addition & 19 deletions tests/root_gauge_factory/test_gauge_addresses.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/root_gauge_factory/test_root_gauge_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit cf0e22f

Please sign in to comment.