Skip to content

[Multi ZNS] Multi zNS Prototype [WIP] #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 125 commits into
base: rc/multi-zns-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
be93527
install zkevm contracts from local package
Whytecrowe Sep 17, 2024
cc745d6
create test contracts
Whytecrowe Sep 17, 2024
295edbf
create deploy script base
Whytecrowe Sep 17, 2024
3715535
create base scripts for bridge and claim
Whytecrowe Sep 17, 2024
7001729
fix networkId
Whytecrowe Sep 17, 2024
c2c4fec
create extension of the Bridge interface to be able to call networkID()
Whytecrowe Sep 19, 2024
103276e
fix test contracts
Whytecrowe Sep 19, 2024
c974173
add zchaintest to HH config
Whytecrowe Sep 19, 2024
7160586
install error decoder package from ethers and add script for easy run
Whytecrowe Sep 19, 2024
3351405
modify test flow scripts
Whytecrowe Sep 19, 2024
85649b9
add Bridge json for easy contract access and use it's abi
Whytecrowe Sep 19, 2024
0397d93
save deployed contract addresses from testnets
Whytecrowe Sep 19, 2024
df6bb6d
install zkevm-contracts from the newly made package
Whytecrowe Sep 19, 2024
1694feb
remove zk-evm contracts for now and comment out test bridge contracts…
Whytecrowe Sep 25, 2024
6ac127a
comment out BridgeSender code temporarily
Whytecrowe Sep 25, 2024
bb42ff1
add ChainResolver prototype
Whytecrowe Sep 25, 2024
14ae190
small type fix for test helpers
Whytecrowe Sep 25, 2024
6dce79b
add chainRootHash concept to zns contract code
Whytecrowe Sep 26, 2024
33976c4
add chainRootHash to ts code and tests
Whytecrowe Sep 26, 2024
6db2c2f
comment out networks in hh config
Whytecrowe Sep 26, 2024
72223ad
update eslint config
Whytecrowe Sep 26, 2024
011e7ac
Revert "add chainRootHash concept to zns contract code"
Whytecrowe Oct 7, 2024
237cf32
Revert "add chainRootHash to ts code and tests"
Whytecrowe Oct 7, 2024
5927914
move and unblock the extended bridge interface
Whytecrowe Oct 7, 2024
4467940
fix chain resolver and add todo
Whytecrowe Oct 7, 2024
fd02224
create initial PolygonZkEvmPortal contract and struct for bridging
Whytecrowe Oct 7, 2024
8797db9
add zkevm-contracts package
Whytecrowe Oct 7, 2024
f241b65
create base for EthPortal contract
Whytecrowe Oct 8, 2024
4d2afbb
move ZkEvmPortal and add some logic
Whytecrowe Oct 8, 2024
a1312c2
create generic ERC20 mock
Whytecrowe Oct 8, 2024
fb06bcc
create ZkEvmBridge mock
Whytecrowe Oct 8, 2024
c985d2a
create new tests and add some deploy helpers for new contracts
Whytecrowe Oct 8, 2024
b29ad06
fix pricing error and add onERC721Received to ZkEvmPortal
Whytecrowe Oct 8, 2024
efe7014
refactor registering logic and add new function to register without p…
Whytecrowe Oct 8, 2024
04e69cd
change getDomainHashFromEvent helper
Whytecrowe Oct 8, 2024
10d235f
fix changed param in event helper usage across tests
Whytecrowe Oct 8, 2024
7830877
fix tests
Whytecrowe Oct 8, 2024
b37297e
add comment to EthPortal
Whytecrowe Oct 8, 2024
dc5b14f
add erc721 receiver function to EthPortal, inherit base interface for…
Whytecrowe Oct 9, 2024
1af8ce4
add .isSet prop setting on FixedPricer in setPrice call as well
Whytecrowe Oct 9, 2024
1ec8cb9
create generic event getter helper for tests
Whytecrowe Oct 9, 2024
2d4371d
add base tests for L2 side
Whytecrowe Oct 9, 2024
dd40699
refactor subRegistrar to have function access to a bridged flow where…
Whytecrowe Oct 11, 2024
dd2108a
adapt EthPortal to do a proper call to SubRegistrar
Whytecrowe Oct 11, 2024
55dd705
make all tests work for both root and subdomains
Whytecrowe Oct 11, 2024
a356b88
add base logic for ChainResolver data and unblock the test
Whytecrowe Oct 11, 2024
d01e2c7
create interfaces for both portals
Whytecrowe Oct 11, 2024
d63a4a8
fix payment logic in PolygonZkEvmPortal
Whytecrowe Oct 14, 2024
021011b
various refactorings
Whytecrowe Oct 14, 2024
e4f37c5
make tests better by making a 3rd party user buy subdomains in all te…
Whytecrowe Oct 14, 2024
4eecd88
add chainId and chainName to PolygonZkEvmPortal state, refactor it's …
Whytecrowe Oct 14, 2024
17b9db4
fix types in chain resolver
Whytecrowe Oct 14, 2024
c627808
adapt tests to new changes
Whytecrowe Oct 14, 2024
70ba43f
refactor EthereumPortal to new namings
Whytecrowe Oct 14, 2024
4997c5d
extend test to check BridgeEvent from the bridge
Whytecrowe Oct 14, 2024
2c67762
extend resolverTypes constant map
Whytecrowe Oct 14, 2024
96bfc0d
add new Portal role and thread it everywhere for Portal registration …
Whytecrowe Oct 14, 2024
b26ebdd
rename PolygonZkEvmPortal to ZChainPortal
Whytecrowe Oct 15, 2024
b3f46e4
create chain resolver DM and some name constants
Whytecrowe Oct 15, 2024
07d9db2
create ZChainPortal DM base and extend types
Whytecrowe Oct 15, 2024
373f022
rearrange deploy params for EthPortal
Whytecrowe Oct 15, 2024
419a0a0
add EthPortal DM base
Whytecrowe Oct 15, 2024
9b70b79
small test fix
Whytecrowe Oct 15, 2024
9281dda
add base logic for zkEvmBridge deploy mission, extent campaign config…
Whytecrowe Oct 22, 2024
2e1baee
Update class name for EthPortal and remove redundant code in meow tok…
Whytecrowe Oct 22, 2024
5424677
split folder structure for DMs in 2, separating zns base logic from c…
Whytecrowe Oct 22, 2024
502293b
convert bridge mock into a proxy
Whytecrowe Oct 23, 2024
72d390d
move portal and bridge DMs to a new folder and refine
Whytecrowe Oct 23, 2024
7869919
create config builder for cross chain data along with new types
Whytecrowe Oct 23, 2024
32c0aa5
extend ZNS deploy function to support new contracts
Whytecrowe Oct 23, 2024
ca59e36
convert tests to use Campaign deploy
Whytecrowe Oct 23, 2024
24274b2
add new unit tests
Whytecrowe Oct 23, 2024
e3f9944
fix tests
Whytecrowe Oct 24, 2024
8ade296
expand env.sample
Whytecrowe Oct 28, 2024
55c7404
fix wrong param name in ZkEVMBridgeMock
Whytecrowe Oct 28, 2024
4291247
split RootRegistrar into multiple contracts and interfaces
Whytecrowe Oct 29, 2024
b58fea8
add logic to RootRegistrarDM to determine which contract to deploy ba…
Whytecrowe Oct 29, 2024
408b990
split ZNSSubRegistrar into 2 contracts with separate interfaces
Whytecrowe Oct 29, 2024
5acbe9e
extend SubRegistrarDM to determine which contract to deploy based on …
Whytecrowe Oct 29, 2024
39beb3b
fix inheritance and remove redundant imports
Whytecrowe Oct 29, 2024
ae67938
add revert to not allow bridging domains if the opposite portal is no…
Whytecrowe Nov 5, 2024
6fefbe3
extend and adapt some helpers
Whytecrowe Nov 5, 2024
7d4bb74
fix types
Whytecrowe Nov 5, 2024
c6dcebf
adapt test to be run on test networks
Whytecrowe Nov 5, 2024
ec5580c
extend test contract types and fix testnet script
Whytecrowe Nov 13, 2024
5e63d34
add tx confirmation helper and wrap registration helpers to wait for …
Whytecrowe Nov 13, 2024
aab8e68
add helpers to get data from zchain bridge api
Whytecrowe Nov 13, 2024
0cb471b
add callable script to acquire data from bridge API with package.json…
Whytecrowe Nov 13, 2024
cbb97d2
constants for the api helpers
Whytecrowe Nov 13, 2024
47723af
rename test folder
Whytecrowe Nov 14, 2024
5b33208
exteneded api scripts to write to local files
Whytecrowe Nov 14, 2024
7d67076
extend helpers for bridge api to be able to save to a file and read f…
Whytecrowe Nov 14, 2024
5ec3bef
fix event helpers and usages of all helpers in the test
Whytecrowe Nov 14, 2024
074a844
extend api helpers and claim
Whytecrowe Nov 18, 2024
afe5397
add bridging registration helper
Whytecrowe Nov 18, 2024
9fe41ee
fix api helper script
Whytecrowe Nov 18, 2024
4f3740e
small fixes for the test
Whytecrowe Nov 20, 2024
c3c57ab
add minter script for testing, commit HH config setup
Whytecrowe Nov 20, 2024
3265e2d
remove redundant yarn call
Whytecrowe Nov 20, 2024
d5e438b
create environment default stencil
Whytecrowe Nov 21, 2024
4f2fadf
add types and extend Node env globals to type each var
Whytecrowe Nov 21, 2024
2e13ccc
create validation function and add env setup to HH config
Whytecrowe Nov 21, 2024
008b0b5
fix types
Whytecrowe Nov 21, 2024
b3c396b
remove redundant code and checks from campaign config getter
Whytecrowe Nov 21, 2024
0d18fce
move root level getLogger calls to actually read from the env properl…
Whytecrowe Nov 21, 2024
03b8bb8
refactor env setter and validation to be able to use that in tests to…
Whytecrowe Nov 22, 2024
f6f1cb7
update types and remain zPortal key
Whytecrowe Nov 22, 2024
fb001c5
update local deploy helpers with new functions for all contracts
Whytecrowe Nov 22, 2024
ac0cebd
wrap all calls in DMs and HardhatDeployer in a temporary wrapper that…
Whytecrowe Nov 22, 2024
e605748
fix all tests
Whytecrowe Nov 22, 2024
b3bcda1
commit temp helpers used on test networks [to be deleted later]
Whytecrowe Nov 22, 2024
7c7f6bc
delete redundant test contracts and files
Whytecrowe Nov 23, 2024
778d6b5
fix all solhint and eslint errors across the repo, fix event helper c…
Whytecrowe Nov 23, 2024
3a37559
use viaIR when running coverage scripts
Whytecrowe Nov 23, 2024
3bab0dd
try changing the mongo uri dynamically for coverage run
Whytecrowe Nov 23, 2024
4b5b6bc
update to newer axios that is not affected by vulnerabilty
Whytecrowe Nov 25, 2024
17e8387
small refactors and fixes
Whytecrowe Nov 25, 2024
f8b97a9
Merge branch 'rc/multi-zns-main' into multi-zns-proto
Whytecrowe Dec 19, 2024
976f74a
regenerate yarn.lock
Whytecrowe Dec 19, 2024
3381b4c
remove meow token ts files and move z-token folder to zns-base for DMs
Whytecrowe Dec 19, 2024
fa5d0f8
fix eslintrc
Whytecrowe Dec 19, 2024
1c2d4bf
fix get-config file
Whytecrowe Dec 19, 2024
109b5c5
small initial fixes after merge
Whytecrowe Dec 19, 2024
4767b84
more test fixes
Whytecrowe Dec 20, 2024
b270197
fix test helpers to include zToken properly and transfer instead of mint
Whytecrowe Jan 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MOCK_Z_TOKEN=
# This is only used if MOCK_Z_TOKEN is set to false (`test` and `prod` environments)
STAKING_TOKEN_ADDRESS=

# Environment variables to create an entirely custom config when `env_level` above is not dev
# Environment variables to create an entirely custom config for CurvePricer when `env_level` above is not dev
MAX_PRICE=
MIN_PRICE=
MAX_LENGTH=
Expand Down Expand Up @@ -65,10 +65,19 @@ ADMIN_ADDRESSES=
MONITOR_CONTRACTS="false"
VERIFY_CONTRACTS="false"

DEFENDER_KEY=
DEFENDER_SECRET=
RELAYER_KEY=
RELAYER_SECRET=
# Data for Cross-Chain contract deployment
# Common data for both L1 and L2. Needs to be reset for EVERY deploy to every network !!!
SRC_CHAIN_NAME= # Has to match one of the networks in `SupportedChains` enum in `get-portal-dm.ts`
MOCK_ZKEVM_BRIDGE= # "true" | "false" to make Campaign deploy a Mocked version of the bridge for local testing
ZK_EVM_BRIDGE= # HAS to be provided if MOCK_ZKEVM_BRIDGE is set to "false", this would use actual Bridge from the chain
NETWORK_ID= # (For the Mocked Bridge) Network ID withing Polygon ZkEVM of the current chain we are deploying to
BRIDGE_TOKEN= # (For the Mocked Bridge) Address of the Bridge Token on the current chain we are deploying to
# Data for L1/Ethereum ZNS
DEST_NETWORK_ID= # Network ID withing Polygon ZkEVM of the destination chain (ZChain) where the other ZNS lies
DEST_CHAIN_NAME= # Has to match one of the networks in `SupportedChains` enum in `get-portal-dm.ts`
DEST_CHAIN_ID= # Chain ID of the destination chain (ZChain) where the other ZNS lies
# Data for L2/ZChain ZNS
SRC_ZNS_PORTAL= # Address of the ZNS Portal on the source chain (Ethereum ZNS)

# Tenderly
# this is your key to access Tenderly Zer0 Org
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
}
}
]
}
}
55 changes: 29 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types
.idea
dist

# Hardhat files
cache
artifacts

# hardhat-tenderly plugin
deployments

*.env
docker
docker*.tgz

# We don't ever use the generated manifests
.openzeppelin
/.vscode

# Don't source control log files from deployment
deploy-*.log
node_modules
.env
coverage
coverage.json
typechain
typechain-types
.idea
dist

# Hardhat files
cache
artifacts

# hardhat-tenderly plugin
deployments

*.env
docker
docker*.tgz

# We don't ever use the generated manifests
.openzeppelin
/.vscode

# Don't source control log files from deployment
deploy-*.log

# Local tests and ops
test-data
62 changes: 33 additions & 29 deletions contracts/access/IZNSAccessController.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";


interface IZNSAccessController is IAccessControl {
function setRoleAdmin(bytes32 role, bytes32 adminRole) external;

function checkGovernor(address account) external view;

function checkAdmin(address account) external view;

function checkExecutor(address account) external view;

function checkRegistrar(address account) external view;

function checkDomainToken(address account) external view;

function isAdmin(address account) external view returns (bool);

function isRegistrar(address account) external view returns (bool);

function isDomainToken(address account) external view returns (bool);

function isGovernor(address account) external view returns (bool);

function isExecutor(address account) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";


interface IZNSAccessController is IAccessControl {
function setRoleAdmin(bytes32 role, bytes32 adminRole) external;

function checkGovernor(address account) external view;

function checkAdmin(address account) external view;

function checkExecutor(address account) external view;

function checkRegistrar(address account) external view;

function checkPortal(address account) external view;

function checkDomainToken(address account) external view;

function isAdmin(address account) external view returns (bool);

function isRegistrar(address account) external view returns (bool);

function isDomainToken(address account) external view returns (bool);

function isGovernor(address account) external view returns (bool);

function isPortal(address account) external view returns (bool);

function isExecutor(address account) external view returns (bool);
}
203 changes: 107 additions & 96 deletions contracts/access/ZNSAccessController.sol
Original file line number Diff line number Diff line change
@@ -1,96 +1,107 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { IZNSAccessController } from "./IZNSAccessController.sol";
import { ZNSRoles } from "./ZNSRoles.sol";
import { ZeroAddressPassed } from "../utils/CommonErrors.sol";


/**
* @title The main module for system-wide Access Control.
* @dev ZNS Business Logic Contract access to this module is outlined in `AAccessControlled.sol`.
* Uses a role-based access control scheme with levels:
* - GOVERNOR: The highest rank, assigns Admins, new roles and Role Admins
* - ADMIN: The main maintainer role, that gets access to all system functions (managed by Governor)
* - EXECUTOR: Can be here to future proof, if we need a new role (managed by Governor)
* - REGISTRAR: This role is here specifically for the ZNSRootRegistrar.sol contract (managed by Admin)
*
* > This contract is NOT proxied. When new implementation is needed, a new contract will be deployed
* and all modules will be updated to use the new address, since they all inherit from `AAccessControlled.sol`.
*/
contract ZNSAccessController is AccessControl, ZNSRoles, IZNSAccessController {
constructor(
address[] memory governorAddresses,
address[] memory adminAddresses
) {
// give roles to all addresses
_grantRoleToMany(GOVERNOR_ROLE, governorAddresses);
_grantRoleToMany(ADMIN_ROLE, adminAddresses);

// all of the governors control admins
_setRoleAdmin(ADMIN_ROLE, GOVERNOR_ROLE);
// all of the governors control governors
_setRoleAdmin(GOVERNOR_ROLE, GOVERNOR_ROLE);
// all of the admins control registrar
_setRoleAdmin(REGISTRAR_ROLE, ADMIN_ROLE);
// all of the admins control domain token
_setRoleAdmin(DOMAIN_TOKEN_ROLE, ADMIN_ROLE);
}

// ** Access Validators **
// "check...()" functions revert with a specific message
function checkGovernor(address account) external view override {
_checkRole(GOVERNOR_ROLE, account);
}

function checkAdmin(address account) external view override {
_checkRole(ADMIN_ROLE, account);
}

function checkExecutor(address account) external view override {
_checkRole(EXECUTOR_ROLE, account);
}

function checkRegistrar(address account) external view override {
_checkRole(REGISTRAR_ROLE, account);
}

function checkDomainToken(address account) external view override {
_checkRole(DOMAIN_TOKEN_ROLE, account);
}

// "is...()" functions return a boolean
function isAdmin(address account) external view override returns (bool) {
return hasRole(ADMIN_ROLE, account);
}

function isRegistrar(address account) external view override returns (bool) {
return hasRole(REGISTRAR_ROLE, account);
}

function isDomainToken(address account) external view override returns (bool) {
return hasRole(DOMAIN_TOKEN_ROLE, account);
}

function isGovernor(address account) external view override returns (bool) {
return hasRole(GOVERNOR_ROLE, account);
}

function isExecutor(address account) external view override returns (bool) {
return hasRole(EXECUTOR_ROLE, account);
}

function setRoleAdmin(bytes32 role, bytes32 adminRole) external override onlyRole(GOVERNOR_ROLE) {
_setRoleAdmin(role, adminRole);
}

function _grantRoleToMany(bytes32 role, address[] memory addresses) internal {
uint256 length = addresses.length;
for (uint256 i = 0; i < length; ++i) {
if (addresses[i] == address(0)) revert ZeroAddressPassed();

_grantRole(role, addresses[i]);
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { IZNSAccessController } from "./IZNSAccessController.sol";
import { ZNSRoles } from "./ZNSRoles.sol";
import { ZeroAddressPassed } from "../utils/CommonErrors.sol";


/**
* @title The main module for system-wide Access Control.
* @dev ZNS Business Logic Contract access to this module is outlined in `AAccessControlled.sol`.
* Uses a role-based access control scheme with levels:
* - GOVERNOR: The highest rank, assigns Admins, new roles and Role Admins
* - ADMIN: The main maintainer role, that gets access to all system functions (managed by Governor)
* - EXECUTOR: Can be here to future proof, if we need a new role (managed by Governor)
* - REGISTRAR: This role is here specifically for the ZNSRootRegistrar.sol contract (managed by Admin)
* - PORTAL: Role for cross-chain Portal contracts that call certain functions on ZNS contracts (managed by Admin)
*
* > This contract is NOT proxied. When new implementation is needed, a new contract will be deployed
* and all modules will be updated to use the new address, since they all inherit from `AAccessControlled.sol`.
*/
contract ZNSAccessController is AccessControl, ZNSRoles, IZNSAccessController {
constructor(
address[] memory governorAddresses,
address[] memory adminAddresses
) {
// give roles to all addresses
_grantRoleToMany(GOVERNOR_ROLE, governorAddresses);
_grantRoleToMany(ADMIN_ROLE, adminAddresses);

// all of the governors control admins
_setRoleAdmin(ADMIN_ROLE, GOVERNOR_ROLE);
// all of the governors control governors
_setRoleAdmin(GOVERNOR_ROLE, GOVERNOR_ROLE);
// all of the admins control registrar
_setRoleAdmin(REGISTRAR_ROLE, ADMIN_ROLE);
// all of the admins control portals
_setRoleAdmin(PORTAL_ROLE, ADMIN_ROLE);
// all of the admins control domain token
_setRoleAdmin(DOMAIN_TOKEN_ROLE, ADMIN_ROLE);
}

// ** Access Validators **
// "check...()" functions revert with a specific message
function checkGovernor(address account) external view override {
_checkRole(GOVERNOR_ROLE, account);
}

function checkAdmin(address account) external view override {
_checkRole(ADMIN_ROLE, account);
}

function checkExecutor(address account) external view override {
_checkRole(EXECUTOR_ROLE, account);
}

function checkRegistrar(address account) external view override {
_checkRole(REGISTRAR_ROLE, account);
}

function checkDomainToken(address account) external view override {
_checkRole(DOMAIN_TOKEN_ROLE, account);
}

function checkPortal(address account) external view override {
_checkRole(PORTAL_ROLE, account);
}

// "is...()" functions return a boolean
function isAdmin(address account) external view override returns (bool) {
return hasRole(ADMIN_ROLE, account);
}

function isRegistrar(address account) external view override returns (bool) {
return hasRole(REGISTRAR_ROLE, account);
}

function isDomainToken(address account) external view override returns (bool) {
return hasRole(DOMAIN_TOKEN_ROLE, account);
}

function isGovernor(address account) external view override returns (bool) {
return hasRole(GOVERNOR_ROLE, account);
}

function isPortal(address account) external view override returns (bool) {
return hasRole(PORTAL_ROLE, account);
}

function isExecutor(address account) external view override returns (bool) {
return hasRole(EXECUTOR_ROLE, account);
}

function setRoleAdmin(bytes32 role, bytes32 adminRole) external override onlyRole(GOVERNOR_ROLE) {
_setRoleAdmin(role, adminRole);
}

function _grantRoleToMany(bytes32 role, address[] memory addresses) internal {
uint256 length = addresses.length;
for (uint256 i = 0; i < length; ++i) {
if (addresses[i] == address(0)) revert ZeroAddressPassed();

_grantRole(role, addresses[i]);
}
}
}
Loading