Skip to content

Commit

Permalink
successful creation of zksync 3-leading-zero address for singlesig
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfoobar committed Jan 16, 2025
1 parent 4089d76 commit 2ad6b7b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mode = "3"
auto_detect_remappings = false
# remappings = []

solc_version = "0.8.24"
solc_version = "0.8.21"
# EVM version must be Paris not Shanghai to prevent PUSH0 incompatibility with other EVM chains
# Extra 137 deployment size, extra 0.1% runtime gas costs from using older version
evm_version = "paris"
Expand Down
57 changes: 40 additions & 17 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {DelegateRegistry} from "../src/DelegateRegistry.sol";
import {Singlesig} from "../src/singlesig/Singlesig.sol";

import {Create2Factory} from "era-contracts/system-contracts/contracts/Create2Factory.sol";
import {ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT} from "era-contracts/system-contracts/contracts/Constants.sol";
import {ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT, CREATE2_PREFIX} from "era-contracts/system-contracts/contracts/Constants.sol";

interface ImmutableCreate2Factory {
function safeCreate2(bytes32 salt, bytes calldata initCode) external payable returns (address deploymentAddress);
Expand All @@ -26,21 +26,37 @@ interface ZksyncCreate2Factory {
}

contract Deploy is Script {
address immutable firstOwner = 0x6Ed7D526b020780f694f3c10Dfb25E1b134D3215;

// ZksyncCreate2Factory immutable zksyncCreateFactory = ZksyncCreate2Factory(0x0000000000000000000000000000000000010000);
Create2Factory immutable zksyncCreateFactory = Create2Factory(0x0000000000000000000000000000000000010000);
ZksyncCreate2Factory immutable zksyncContractDeployer = ZksyncCreate2Factory(0x0000000000000000000000000000000000008006);

ImmutableCreate2Factory immutable factory = ImmutableCreate2Factory(0x0000000000FFe8B47B3e2130213B802212439497);
bytes initCode = type(DelegateRegistry).creationCode;
// bytes32 singlesigSalt = 0x0000000000000000000000000000000000000000fbe49ecfc3decb1164228b89;
bytes32 registrySalt = 0x00000000000000000000000000000000000000002bbc593dd77cb93fbb932d5f;
// bytes32 registrySalt = 0x00000000000000000000000000000000000000002bbc593dd77cb93fbb932d5f;

bytes32 zkSinglesigSalt = 0x0000000000000000000000000000000000000000b46d2eb2b23e8ae404000006;
// bytes32 registrySalt = bytes32(0);
bytes32 registrySalt = 0x0000000000000000000000000000000000000000dc73d3e78582b023010000a0;

// bytes initCode = abi.encodePacked(type(Singlesig).creationCode, abi.encode(address(0x6Ed7D526b020780f694f3c10Dfb25E1b134D3215)));
// bytes32 salt = 0x000000000000000000000000000000000000000016c7768a8c7a2824b846321d;

function run() external {
vm.startBroadcast();

Singlesig predeploySinglesig = new Singlesig{salt: zkSinglesigSalt}(firstOwner);
bytes32 singlesigZKBytecodeHash = ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.getRawCodeHash(address(predeploySinglesig));
bytes32 constructorHash = keccak256(abi.encode(firstOwner));
console2.log(address(predeploySinglesig));
console2.logBytes(abi.encode(firstOwner));
console2.logBytes32(singlesigZKBytecodeHash);
console2.logBytes32(constructorHash);
bytes memory preimage = bytes.concat(CREATE2_PREFIX, bytes32(uint256(uint160(address(zksyncCreateFactory)))), zkSinglesigSalt, singlesigZKBytecodeHash, constructorHash);
console2.logBytes(preimage);

// address singlesigAddress = factory.safeCreate2(singlesigSalt, initCode);
// Singlesig singlesig = Singlesig(payable(singlesigAddress));
// console2.log(address(singlesig));
Expand All @@ -49,21 +65,28 @@ contract Deploy is Script {
// bytes32[] memory hashes = existing.getOutgoingDelegationHashes(0x86362a4C99d900D72d787Ef1BddA38Fd318aa5E9);
// console2.logBytes32(hashes[0]);

DelegateRegistry saltDeploy = new DelegateRegistry{salt: registrySalt}();
console2.log(address(saltDeploy));

DelegateRegistry predeploy = new DelegateRegistry();

bytes32 bytecodeHash = keccak256(initCode);
bytes32 zkBytecodeHash = ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.getRawCodeHash(address(predeploy));

console2.logBytes32(bytecodeHash);
console2.logBytes32(zkBytecodeHash);
console2.log(address(predeploy));
console2.log(msg.sender);
console2.logBytes32(registrySalt);
address registryAddress = zksyncContractDeployer.getNewAddressCreate2(address(zksyncCreateFactory), zkBytecodeHash, registrySalt, "");
console2.log(registryAddress);
// DelegateRegistry saltDeploy = new DelegateRegistry{salt: registrySalt}();
// console2.logBytes32(keccak256(""));
// console2.log(address(saltDeploy));

// DelegateRegistry predeploy = new DelegateRegistry();

// bytes32 bytecodeHash = keccak256(initCode);
// bytes32 zkBytecodeHash = ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.getRawCodeHash(address(predeploy));

// console2.logBytes32(bytecodeHash);
// console2.logBytes32(zkBytecodeHash);
// console2.log(address(predeploy));
// console2.log(msg.sender);
// console2.logBytes32(registrySalt);
// bytes memory preimage = bytes.concat(CREATE2_PREFIX, bytes32(uint256(uint160(address(zksyncCreateFactory)))), registrySalt, zkBytecodeHash, keccak256(""));
// console2.logBytes(preimage);
// address localRegistryAddress = address(uint160(uint256(keccak256(
// bytes.concat(CREATE2_PREFIX, bytes32(uint256(uint160(address(zksyncCreateFactory)))), registrySalt, zkBytecodeHash, keccak256(""))
// ))));
// console2.log(localRegistryAddress);
// address registryAddress = zksyncContractDeployer.getNewAddressCreate2(address(zksyncCreateFactory), zkBytecodeHash, registrySalt, "");
// console2.log(registryAddress);

// zksyncCreateFactory.create2(registrySalt, zkBytecodeHash, "");

Expand Down

0 comments on commit 2ad6b7b

Please sign in to comment.