-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] feat: update contracts for zksync (#32)
* feat: update proxy factory to zksync * fix: added correct hashes for v0.8.19 * fix: added hashes with 1.5.0 * fix: 1.4.1 hashes * fix: sepparate zksync contracts * fix: added zksync configs * fix: separate zksync contracts to specific profile * fix: fixed missing conflict * fix: removed fixed version * fix: remove not needed diffs * fix: prettier * fix: added correct profiles * Add TransparentProxyFactoryBase (#37) * Add TransparentProxyFactoryBase * cleanup ITransparentProxyFactoryZkSync --------- Co-authored-by: sendra <[email protected]> Co-authored-by: Andrey <[email protected]>
- Loading branch information
1 parent
b42cacb
commit 9e12156
Showing
10 changed files
with
324 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ out/ | |
broadcast | ||
node_modules | ||
package-lock.json | ||
zkout/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule forge-std
updated
42 files
75 changes: 75 additions & 0 deletions
75
src-zksync/contracts/transparent-proxy/TransparentProxyFactoryZkSync.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import {TransparentProxyFactoryBase, ITransparentProxyFactory} from '../../../src/contracts/transparent-proxy/TransparentProxyFactoryBase.sol'; | ||
import {ITransparentProxyFactoryZkSync} from './interfaces/ITransparentProxyFactoryZkSync.sol'; | ||
|
||
/** | ||
* @title TransparentProxyFactoryZkSync | ||
* @author BGD Labs | ||
* @notice Factory contract to create transparent proxies, both with CREATE and CREATE2 | ||
* @dev `create()` and `createDeterministic()` are not unified for clearer interface, and at the same | ||
* time allowing `createDeterministic()` with salt == 0 | ||
* @dev Highly recommended to pass as `admin` on creation an OZ ProxyAdmin instance | ||
* @dev This contract needs solc=0.8.19 and zksolc=1.4.1 as codeHashes are specifically made for those versions | ||
**/ | ||
contract TransparentProxyFactoryZkSync is | ||
TransparentProxyFactoryBase, | ||
ITransparentProxyFactoryZkSync | ||
{ | ||
/// @inheritdoc ITransparentProxyFactoryZkSync | ||
bytes32 public constant TRANSPARENT_UPGRADABLE_PROXY_INIT_CODE_HASH = | ||
0x010001b73fa7f2c39ea2d9c597a419e15436fc9d3e00e032410072fb94ad95e1; | ||
|
||
/// @inheritdoc ITransparentProxyFactoryZkSync | ||
bytes32 public constant PROXY_ADMIN_INIT_CODE_HASH = | ||
0x010000e7f9a8b61da13fe7e27804d9f641f5f8db05b07df720973af749a01ac1; | ||
|
||
/// @inheritdoc ITransparentProxyFactoryZkSync | ||
bytes32 public constant ZKSYNC_CREATE2_PREFIX = keccak256('zksyncCreate2'); | ||
|
||
/// @inheritdoc ITransparentProxyFactory | ||
function predictCreateDeterministic( | ||
address logic, | ||
address admin, | ||
bytes calldata data, | ||
bytes32 salt | ||
) public view override returns (address) { | ||
return | ||
_predictCreate2Address( | ||
address(this), | ||
salt, | ||
TRANSPARENT_UPGRADABLE_PROXY_INIT_CODE_HASH, | ||
abi.encode(logic, admin, data) | ||
); | ||
} | ||
|
||
/// @inheritdoc ITransparentProxyFactory | ||
function predictCreateDeterministicProxyAdmin(bytes32 salt) | ||
public | ||
view | ||
override | ||
returns (address) | ||
{ | ||
return _predictCreate2Address(address(this), salt, PROXY_ADMIN_INIT_CODE_HASH, abi.encode()); | ||
} | ||
|
||
function _predictCreate2Address( | ||
address sender, | ||
bytes32 salt, | ||
bytes32 creationCodeHash, | ||
bytes memory constructorInput | ||
) internal pure returns (address) { | ||
bytes32 addressHash = keccak256( | ||
bytes.concat( | ||
ZKSYNC_CREATE2_PREFIX, | ||
bytes32(uint256(uint160(sender))), | ||
salt, | ||
creationCodeHash, | ||
keccak256(constructorInput) | ||
) | ||
); | ||
|
||
return address(uint160(uint256(addressHash))); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src-zksync/contracts/transparent-proxy/interfaces/ITransparentProxyFactoryZkSync.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
interface ITransparentProxyFactoryZkSync { | ||
/** | ||
* @notice method to get the hash of creation bytecode of the TransparentUpgradableProxy contract | ||
* @return hashed of creation bytecode of the TransparentUpgradableProxy contract | ||
*/ | ||
function TRANSPARENT_UPGRADABLE_PROXY_INIT_CODE_HASH() external returns (bytes32); | ||
|
||
/** | ||
* @notice method to get the hash of creation bytecode of the ProxyAdmin contract | ||
* @return hashed of creation bytecode of the ProxyAdmin contract | ||
*/ | ||
function PROXY_ADMIN_INIT_CODE_HASH() external returns (bytes32); | ||
|
||
/** | ||
* @notice method to get the zksync create2 prefix used for create2 address derivation in zksync | ||
* @return create2 prefix used for create2 address derivation | ||
*/ | ||
function ZKSYNC_CREATE2_PREFIX() external returns (bytes32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/contracts/transparent-proxy/TransparentProxyFactoryBase.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import {IOwnable} from './interfaces/IOwnable.sol'; | ||
import {ITransparentProxyFactory} from './interfaces/ITransparentProxyFactory.sol'; | ||
import {TransparentUpgradeableProxy} from './TransparentUpgradeableProxy.sol'; | ||
import {ProxyAdmin} from './ProxyAdmin.sol'; | ||
|
||
/** | ||
* @title TransparentProxyFactory | ||
* @author BGD Labs | ||
* @notice Factory contract to create transparent proxies, both with CREATE and CREATE2 | ||
* @dev `create()` and `createDeterministic()` are not unified for clearer interface, and at the same | ||
* time allowing `createDeterministic()` with salt == 0 | ||
* @dev Highly recommended to pass as `admin` on creation an OZ ProxyAdmin instance | ||
**/ | ||
abstract contract TransparentProxyFactoryBase is ITransparentProxyFactory { | ||
/// @inheritdoc ITransparentProxyFactory | ||
function create( | ||
address logic, | ||
address admin, | ||
bytes calldata data | ||
) external returns (address) { | ||
address proxy = address(new TransparentUpgradeableProxy(logic, admin, data)); | ||
|
||
emit ProxyCreated(proxy, logic, admin); | ||
return proxy; | ||
} | ||
|
||
/// @inheritdoc ITransparentProxyFactory | ||
function createProxyAdmin(address adminOwner) external returns (address) { | ||
address proxyAdmin = address(new ProxyAdmin()); | ||
IOwnable(proxyAdmin).transferOwnership(adminOwner); | ||
|
||
emit ProxyAdminCreated(proxyAdmin, adminOwner); | ||
return proxyAdmin; | ||
} | ||
|
||
/// @inheritdoc ITransparentProxyFactory | ||
function createDeterministic( | ||
address logic, | ||
address admin, | ||
bytes calldata data, | ||
bytes32 salt | ||
) external returns (address) { | ||
address proxy = address(new TransparentUpgradeableProxy{salt: salt}(logic, admin, data)); | ||
|
||
emit ProxyDeterministicCreated(proxy, logic, admin, salt); | ||
return proxy; | ||
} | ||
|
||
/// @inheritdoc ITransparentProxyFactory | ||
function createDeterministicProxyAdmin(address adminOwner, bytes32 salt) | ||
external | ||
returns (address) | ||
{ | ||
address proxyAdmin = address(new ProxyAdmin{salt: salt}()); | ||
IOwnable(proxyAdmin).transferOwnership(adminOwner); | ||
|
||
emit ProxyAdminDeterministicCreated(proxyAdmin, adminOwner, salt); | ||
return proxyAdmin; | ||
} | ||
|
||
/// @inheritdoc ITransparentProxyFactory | ||
function predictCreateDeterministic( | ||
address logic, | ||
address admin, | ||
bytes calldata data, | ||
bytes32 salt | ||
) public view virtual returns (address); | ||
|
||
/// @inheritdoc ITransparentProxyFactory | ||
function predictCreateDeterministicProxyAdmin(bytes32 salt) public view virtual returns (address); | ||
} |
Oops, something went wrong.