-
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.
fix: use bytecode-hash from creationCode in proxy-factory (#38)
* feat: fetch bytecodehash from the creationCode * chore: update deploy scripts zksync * fix: script for zksync * More abstraction on the Proxy Factory (#39) * More abstraction on the Proxy Factory * Remove unnececcery imports * refactor: folder structure --------- Co-authored-by: Andrey <[email protected]>
- Loading branch information
1 parent
58c5243
commit 4c76eb4
Showing
10 changed files
with
118 additions
and
139 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
75 changes: 0 additions & 75 deletions
75
src-zksync/contracts/transparent-proxy/TransparentProxyFactoryZkSync.sol
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src-zksync/contracts/transparent-proxy/interfaces/ITransparentProxyFactoryZkSync.sol
This file was deleted.
Oops, something went wrong.
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
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,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {Script} from 'forge-std/Script.sol'; | ||
import {TransparentProxyFactoryZkSync} from '../src/contracts/transparent-proxy/TransparentProxyFactoryZkSync.sol'; | ||
|
||
contract DeployZkSync is Script { | ||
function run() external { | ||
vm.startBroadcast(); | ||
new TransparentProxyFactoryZkSync(); | ||
vm.stopBroadcast(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
zksync/src/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,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
|
||
import {TransparentProxyFactoryBase} from '../../../../src/contracts/transparent-proxy/TransparentProxyFactoryBase.sol'; | ||
import {ITransparentProxyFactoryZkSync} from './interfaces/ITransparentProxyFactoryZkSync.sol'; | ||
|
||
/** | ||
* @title TransparentProxyFactoryZkSync | ||
* @author BGD Labs | ||
* @notice Factory contract specific to zkSync 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 | ||
**/ | ||
contract TransparentProxyFactoryZkSync is | ||
TransparentProxyFactoryBase, | ||
ITransparentProxyFactoryZkSync | ||
{ | ||
/// @inheritdoc ITransparentProxyFactoryZkSync | ||
bytes32 public constant ZKSYNC_CREATE2_PREFIX = keccak256('zksyncCreate2'); | ||
|
||
function _predictCreate2Address( | ||
address sender, | ||
bytes32 salt, | ||
bytes memory creationCode, | ||
bytes memory constructorInput | ||
) internal pure override returns (address) { | ||
bytes32 addressHash = keccak256( | ||
bytes.concat( | ||
ZKSYNC_CREATE2_PREFIX, | ||
bytes32(uint256(uint160(sender))), | ||
salt, | ||
bytes32(_sliceBytes(creationCode, 36, 32)), | ||
keccak256(constructorInput) | ||
) | ||
); | ||
|
||
return address(uint160(uint256(addressHash))); | ||
} | ||
|
||
function _sliceBytes( | ||
bytes memory data, | ||
uint256 start, | ||
uint256 length | ||
) internal pure returns (bytes memory) { | ||
require(start + length <= data.length, 'Slice out of bounds'); | ||
|
||
bytes memory result = new bytes(length); | ||
assembly { | ||
let dataPtr := add(data, 32) | ||
let resultPtr := add(result, 32) | ||
|
||
// Use mcopy to efficiently copy the slice | ||
mcopy(resultPtr, add(dataPtr, start), length) | ||
|
||
mstore(result, length) | ||
} | ||
return result; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
zksync/src/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,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
interface ITransparentProxyFactoryZkSync { | ||
/** | ||
* @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); | ||
} |
10 changes: 5 additions & 5 deletions
10
...ksync/TransparentProxyFactoryZkSync.t.sol → .../test/TransparentProxyFactoryZkSync.t.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