Skip to content
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

feat(consensus): add L2 registry contract (BFT-434) #555

Merged
merged 72 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
badb7c8
Add consensus L2 contracts
moshababo Jun 27, 2024
34b571a
Add remove func
moshababo Jun 27, 2024
1924966
Update l2-contracts/contracts/AttesterRegistry.sol
moshababo Jun 27, 2024
0185b43
Update l2-contracts/contracts/ConsensusAuthority.sol
moshababo Jun 28, 2024
617eb14
Add weight segregation
moshababo Jun 28, 2024
9f9fb5b
Use nodeOwner address as a UID on registries
moshababo Jun 28, 2024
5580698
Add tests (WIP)
moshababo Jul 1, 2024
8d18140
Remove PoP verification
moshababo Jul 1, 2024
53b4d89
Remove epoch, inactivity delay and nextCommittee
moshababo Jul 3, 2024
4e16fce
Reorder struct fields for potential packing
moshababo Jul 3, 2024
b86eaee
Optimize gas: iterations
moshababo Jul 3, 2024
d1e2500
Import items explicitly
moshababo Jul 3, 2024
bce309a
Use custom errors
moshababo Jul 3, 2024
454d315
Clean delay mechanism leftovers
moshababo Jul 4, 2024
a3169ff
Add top-level setCommittee calls
moshababo Jul 9, 2024
fe60f1a
Expose committee length
moshababo Jul 9, 2024
0c2498f
Merge contracts
moshababo Jul 10, 2024
93e8cf8
Unify validator/attester structs, allow active nodes removal
moshababo Jul 11, 2024
e7fd2e6
Update l2-contracts/contracts/ConsensusRegistry.sol
moshababo Jul 12, 2024
19bfcbd
Add docs
moshababo Jul 21, 2024
07698a3
Merge branch 'main' into consensus_contracts
moshababo Jul 22, 2024
5aa42a0
Lint
moshababo Jul 22, 2024
2e5b1cb
Codespell
moshababo Jul 22, 2024
eed959e
Lint
moshababo Jul 22, 2024
9a2f49f
Prettier
moshababo Jul 22, 2024
31d42cb
Use `EfficientCall.keccak`
moshababo Jul 24, 2024
ca48a30
Use underscore prefix in function params
moshababo Jul 25, 2024
2b861ca
Update l2-contracts/contracts/ConsensusRegistry.sol
moshababo Jul 25, 2024
5d80cbc
Add docs
moshababo Jul 25, 2024
c4069e3
`IsInactive` => `active`
moshababo Jul 25, 2024
08b8dbf
Inherit `Ownable2Step`
moshababo Jul 25, 2024
6087c4f
Add requires
moshababo Jul 25, 2024
a78f7d0
Merge branch 'refs/heads/dev' into consensus_contracts
moshababo Jul 25, 2024
7895533
Add zksync-web3 to devDependencies
moshababo Jul 26, 2024
263ffce
Lint
moshababo Jul 26, 2024
8c54279
Use plain `msg.sender`
moshababo Aug 6, 2024
e04b7bb
Add custom errors for input validation
moshababo Aug 6, 2024
92b0fcc
Add events emission
moshababo Aug 6, 2024
a5b796c
Use fixed-size types
moshababo Aug 7, 2024
c13bd81
[WIP] apply latest/snapshot data modes, to be read from according to …
moshababo Aug 9, 2024
ec36993
Change nodes removal scheme
moshababo Aug 14, 2024
167bcfd
Assign latest commit number when updating
moshababo Aug 14, 2024
9137d35
Apply `_` prefix naming convention
moshababo Aug 14, 2024
3fe085f
Change Secp256k1PublicKey fields naming
moshababo Aug 14, 2024
4b717f9
Update contract doc
moshababo Aug 14, 2024
e2ea3de
Add pubKey hashes mapping for efficient lookups
moshababo Aug 14, 2024
89b4ccd
Add docs
moshababo Aug 14, 2024
f842a7d
Fix Secp256k1PublicKey struct literal
moshababo Aug 14, 2024
347229d
Unify `NodeValidatorPoPChanged` and `NodeAttesterPubKeyChanged` events
moshababo Aug 14, 2024
f90aa99
Add `IConsensusRegistry`
moshababo Aug 14, 2024
feb76be
Remove from node owners array without index finding iteration
moshababo Aug 15, 2024
8fd2100
Remove unneeded mapping
moshababo Aug 15, 2024
4157991
Add the commit counter to commit events as an arg
moshababo Aug 15, 2024
10b601a
Docs refactor
moshababo Aug 15, 2024
655f4b5
Improve pending removal inspection
moshababo Aug 16, 2024
10d7d53
`remove` to potentially trigger a deletion
moshababo Aug 16, 2024
7a2a755
Add `NodeDeleted` event
moshababo Aug 16, 2024
2c25a50
Add `_getNode` getter
moshababo Aug 16, 2024
262adb6
Add committees read functions
moshababo Aug 16, 2024
bb12557
Update existing tests
moshababo Aug 18, 2024
939e96b
Add tests
moshababo Aug 18, 2024
a973b21
pack storage (`uint256` -> `uint32`)
moshababo Aug 18, 2024
7ed0bd3
Rename function
moshababo Aug 18, 2024
e8a32b7
eslint
moshababo Aug 18, 2024
82e44f5
Merge branch 'refs/heads/dev' into consensus_contracts
moshababo Aug 18, 2024
460de55
Update l2-contracts/contracts/ConsensusRegistry.sol
RomanBrodetski Aug 19, 2024
2ebcc2d
Update l2-contracts/contracts/ConsensusRegistry.sol
RomanBrodetski Aug 19, 2024
a1ac4c3
Update l2-contracts/contracts/ConsensusRegistry.sol
RomanBrodetski Aug 19, 2024
0c4dec1
Update l2-contracts/contracts/ConsensusRegistry.sol
RomanBrodetski Aug 19, 2024
5111248
Fix the compilation
vladbochok Aug 19, 2024
43893b0
Add comment on proxy usage
vladbochok Aug 19, 2024
d4f454a
Integrate Proxy
vladbochok Aug 19, 2024
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
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* @vladbochok @StanislavBreadless
l1-contracts/deploy-scripts @Deniallugo
moshababo marked this conversation as resolved.
Show resolved Hide resolved
l1-contracts/deploy-script-config-template @Deniallugo
6 changes: 2 additions & 4 deletions gas-bound-caller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ If the call to the `_to` address succeeds, the `GasBoundCaller` will ensure that

Summing up the information from the previous chapter, the `GasBoundCaller` should be used in the following way:

TODO(EVM-585): switch `addr` with address.

```solidity
uint256 computeGasBefore = gasleft();

(bool success, bytes memory returnData) = address(this).call{gas: _gasToPass}(abi.encodeWithSelector(GasBoundCaller.gasBoundCall.selector, _to, _maxTotalGas, _data));
(bool success, bytes memory returnData) = address(0xc706EC7dfA5D4Dc87f29f859094165E8290530f5).call{gas: _gasToPass}(abi.encodeWithSelector(GasBoundCaller.gasBoundCall.selector, _to, _maxTotalGas, _data));

uint256 pubdataGasSpent;
if (success) {
Expand All @@ -48,4 +46,4 @@ Since `GasBoundCaller` would be the contract that calls the `_to` contract, the

It should be deployed via a built-in CREATE2 factory on each individual chain.

TODO(EVM-585)
The current address on both sepolia testnet and mainnet for zkSync Era is `0xc706EC7dfA5D4Dc87f29f859094165E8290530f5`.
2 changes: 1 addition & 1 deletion gas-bound-caller/canonical-bytecodes/GasBoundCaller

Large diffs are not rendered by default.

33 changes: 16 additions & 17 deletions gas-bound-caller/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
import "@matterlabs/hardhat-zksync-chai-matchers";
import "@matterlabs/hardhat-zksync-node";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";
import "@nomiclabs/hardhat-ethers";
import "hardhat-typechain";

// This version of system contracts requires a pre release of the compiler
const COMPILER_VERSION = "1.5.0";
const PRE_RELEASE_VERSION = "prerelease-a167aa3-code4rena";
function getZksolcUrl(): string {
// @ts-ignore
const platform = { darwin: "macosx", linux: "linux", win32: "windows" }[process.platform];
// @ts-ignore
const toolchain = { linux: "-musl", win32: "-gnu", darwin: "" }[process.platform];
const arch = process.arch === "x64" ? "amd64" : process.arch;
const ext = process.platform === "win32" ? ".exe" : "";

return `https://github.com/matter-labs/era-compiler-solidity/releases/download/${PRE_RELEASE_VERSION}/zksolc-${platform}-${arch}${toolchain}-v${COMPILER_VERSION}${ext}`;
}

console.log(`Using zksolc from ${getZksolcUrl()}`);

export default {
zksolc: {
version: "1.5.0",
compilerSource: "binary",
settings: {
compilerPath: getZksolcUrl(),
isSystem: true,
},
},
Expand Down Expand Up @@ -55,6 +40,20 @@ export default {
ethNetwork: "localhost",
zksync: true,
},
zkSyncTestnet: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
// contract verification endpoint
verifyURL: "https://explorer.sepolia.era.zksync.dev/contract_verification",
},
zkSyncMainnet: {
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
// contract verification endpoint
verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
},
},
paths: {
sources: "./contracts",
Expand Down
3 changes: 3 additions & 0 deletions gas-bound-caller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"@matterlabs/hardhat-zksync-chai-matchers": "^0.2.0",
"@matterlabs/hardhat-zksync-node": "^0.0.1-beta.7",
"@matterlabs/hardhat-zksync-verify": "0.6.1",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.3",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@typechain/ethers-v5": "^2.0.0",
Expand Down Expand Up @@ -53,6 +54,8 @@
"clean": "yarn clean:bootloader && yarn clean:system-contracts",
"test": "yarn build && hardhat test --network zkSyncTestNode",
"test-node": "hardhat node-zksync --tag v0.0.1-vm1.5.0",
"check-canonical-bytecode": "ts-node ./scripts/check-canonical-bytecode.ts",
"verify": "hardhat run scripts/verify.ts",
"deploy-on-hyperchain": "ts-node ./scripts/deploy-on-hyperchain.ts",
"deploy-on-localhost": "hardhat deploy --network localhost"
}
Expand Down
31 changes: 31 additions & 0 deletions gas-bound-caller/scripts/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// hardhat import should be the first import in the file
import * as hardhat from "hardhat";

const EXPECTED_ADDRESS = "0xc706EC7dfA5D4Dc87f29f859094165E8290530f5";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function verifyPromise(address: string, constructorArguments?: Array<any>, libraries?: object): Promise<any> {
return new Promise((resolve, reject) => {
hardhat
.run("verify:verify", { address, constructorArguments, libraries })
.then(() => resolve(`Successfully verified ${address}`))
.catch((e) => reject(`Failed to verify ${address}\nError: ${e.message}`));
});
}

async function main() {
if (process.env.CHAIN_ETH_NETWORK == "localhost") {
console.log("Skip contract verification on localhost");
return;
}

const message = await verifyPromise(EXPECTED_ADDRESS);
console.log(message.status == "fulfilled" ? message.value : message.reason);
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Error:", err.message || err);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
additional_addresses_for_minting = []

[tokens.DAI]
name = "DAI"
symbol = "DAI"
Expand Down
Loading
Loading