Skip to content

Commit d611838

Browse files
authored
refactor(consensus): Deprecate attesters and prepare for validator committee rotation in ZKStack CLI (#3845)
## What ❔ Continuation of #3775. It refactors the current consensus CLI commands to set/get the validator committee instead of the attester committee. Attesters are being deprecated. Commands will work with current ConsensusRegistry contract but don't have any functionality. It will made to work in a future PR after matter-labs/era-contracts#1365 is merged. Part of PLA-1112 and PLA-1113 ## Is this a breaking change? - [X] Yes - [ ] No ## Operational changes Any chains that currently use attester commands in any capacity need to stop using them. Should be trivial as attesters were never used in any critical capacity. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent b71c167 commit d611838

File tree

17 files changed

+526
-546
lines changed

17 files changed

+526
-546
lines changed

core/lib/mini_merkle_tree/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn hash_of_empty_tree_with_single_item() {
4141
fn hash_of_large_empty_tree_with_multiple_items() {
4242
for len in [50, 64, 100, 128, 256, 512, 1_000, 1_024] {
4343
println!("checking tree with {len} items");
44-
let leaves = iter::repeat([0_u8; 88]).take(len);
44+
let leaves = std::iter::repeat_n([0_u8; 88], len);
4545
let tree_size = len.next_power_of_two();
4646

4747
let tree = MiniMerkleTree::new(leaves.clone(), Some(tree_size));
@@ -375,7 +375,7 @@ fn pushing_new_leaves() {
375375

376376
#[test]
377377
fn trim_all_and_grow() {
378-
let mut tree = MiniMerkleTree::new(iter::repeat([1; 88]).take(4), None);
378+
let mut tree = MiniMerkleTree::new(std::iter::repeat_n([1; 88], 4), None);
379379
tree.trim_start(4);
380380
tree.push([1; 88]);
381381
let expected_root = "0xfa4c924185122254742622b10b68df8de89d33f685ee579f37a50c552b0d245d"
@@ -387,13 +387,13 @@ fn trim_all_and_grow() {
387387
#[test]
388388
fn trim_all_and_check_root() {
389389
for len in 1..=50 {
390-
let mut tree = MiniMerkleTree::new(iter::repeat([1; 88]).take(len), None);
390+
let mut tree = MiniMerkleTree::new(std::iter::repeat_n([1; 88], len), None);
391391
let root = tree.merkle_root();
392392
tree.trim_start(len);
393393
assert_eq!(tree.merkle_root(), root);
394394

395395
let mut tree = MiniMerkleTree::new(
396-
iter::repeat([1; 88]).take(len),
396+
std::iter::repeat_n([1; 88], len),
397397
Some(len.next_power_of_two() * 2),
398398
);
399399
let root = tree.merkle_root();

core/lib/multivm/src/versions/testonly/get_used_contracts.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::iter;
2-
31
use assert_matches::assert_matches;
42
use ethabi::Token;
53
use zk_evm_1_3_1::zkevm_opcode_defs::decoding::{EncodingModeProduction, VmEncodingMode};
@@ -86,9 +84,7 @@ pub(crate) fn test_get_used_contracts<VM: TestedVm>() {
8684
fn inflated_counter_bytecode() -> Vec<u8> {
8785
let mut counter_bytecode = TestContract::counter().bytecode.to_vec();
8886
counter_bytecode.extend(
89-
iter::repeat(EncodingModeProduction::nop_encoding().to_be_bytes())
90-
.take(10_000)
91-
.flatten(),
87+
std::iter::repeat_n(EncodingModeProduction::nop_encoding().to_be_bytes(), 10_000).flatten(),
9288
);
9389
counter_bytecode
9490
}

core/node/api_server/src/testonly.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Test utils shared among multiple modules.
22
3-
use std::{collections::HashMap, iter};
3+
use std::collections::HashMap;
44

55
use assert_matches::assert_matches;
66
use zk_evm_1_5_0::zkevm_opcode_defs::decoding::{EncodingModeProduction, VmEncodingMode};
@@ -55,9 +55,11 @@ const MULTICALL3_CONTRACT_PATH: &str =
5555
/// Inflates the provided bytecode by appending the specified amount of NOP instructions at the end.
5656
fn inflate_bytecode(bytecode: &mut Vec<u8>, nop_count: usize) {
5757
bytecode.extend(
58-
iter::repeat(EncodingModeProduction::nop_encoding().to_be_bytes())
59-
.take(nop_count)
60-
.flatten(),
58+
std::iter::repeat_n(
59+
EncodingModeProduction::nop_encoding().to_be_bytes(),
60+
nop_count,
61+
)
62+
.flatten(),
6163
);
6264
}
6365

core/node/node_sync/src/tree_data_fetcher/provider/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ impl EthereumParameters {
157157

158158
let l1_block_number = U64::from(l1_block_number);
159159
let last_commit = self.batches_and_sl_blocks_for_commits.last().copied();
160-
let is_increasing = last_commit.map_or(true, |last| {
161-
last.0 <= l1_batch_number && last.1 <= l1_block_number
162-
});
160+
let is_increasing =
161+
last_commit.is_none_or(|last| last.0 <= l1_batch_number && last.1 <= l1_block_number);
163162
assert!(
164163
is_increasing,
165164
"Invalid batch number or L1 block number for commit"

zkstack_cli/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zkstack_cli/crates/config/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ zksync_basic_types.workspace = true
2828
zksync_system_constants.workspace = true
2929
zkstack_cli_common.workspace = true
3030
zkstack_cli_types.workspace = true
31+
zksync_consensus_roles.workspace = true
32+
zksync_consensus_crypto.workspace = true

zkstack_cli/crates/config/src/consensus.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ impl Weighted {
2020
pub struct ConsensusGenesisSpecs {
2121
pub chain_id: L2ChainId,
2222
pub validators: Vec<Weighted>,
23-
pub attesters: Vec<Weighted>,
2423
pub leader: String,
2524
}
2625

zkstack_cli/crates/config/src/general.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,9 @@ impl GeneralConfigPatch {
189189
self.0
190190
.insert("consensus.genesis_spec.chain_id", specs.chain_id.as_u64())?;
191191
self.0
192-
.insert("consensus.genesis_spec.protocol_version", 1_u64)?;
192+
.insert("consensus.genesis_spec.protocol_version", 1u64)?;
193193
self.0
194194
.insert_yaml("consensus.genesis_spec.validators", specs.validators)?;
195-
self.0
196-
.insert_yaml("consensus.genesis_spec.attesters", specs.attesters)?;
197195
self.0
198196
.insert("consensus.genesis_spec.leader", specs.leader)?;
199197
Ok(())

zkstack_cli/crates/config/src/secrets.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::path::PathBuf;
33
use url::Url;
44
use xshell::Shell;
55
use zkstack_cli_common::db::DatabaseConfig;
6+
use zksync_consensus_crypto::TextFmt;
7+
use zksync_consensus_roles::{node, validator};
68

79
use crate::{
810
da::AvailSecrets,
@@ -11,9 +13,24 @@ use crate::{
1113

1214
#[derive(Debug)]
1315
pub struct RawConsensusKeys {
14-
pub validator: String,
15-
pub attester: String,
16-
pub node: String,
16+
pub validator_public: String,
17+
pub node_public: String,
18+
pub validator_secret: String,
19+
pub node_secret: String,
20+
}
21+
22+
impl RawConsensusKeys {
23+
pub fn generate() -> Self {
24+
let validator = validator::SecretKey::generate();
25+
let node = node::SecretKey::generate();
26+
27+
Self {
28+
validator_public: validator.public().encode(),
29+
node_public: node.public().encode(),
30+
validator_secret: validator.encode(),
31+
node_secret: node.encode(),
32+
}
33+
}
1734
}
1835

1936
#[derive(Debug)]
@@ -82,10 +99,9 @@ impl SecretsConfigPatch {
8299

83100
pub fn set_consensus_keys(&mut self, consensus_keys: RawConsensusKeys) -> anyhow::Result<()> {
84101
self.0
85-
.insert("consensus.validator_key", consensus_keys.validator)?;
102+
.insert("consensus.validator_key", consensus_keys.validator_secret)?;
86103
self.0
87-
.insert("consensus.attester_key", consensus_keys.attester)?;
88-
self.0.insert("consensus.node_key", consensus_keys.node)
104+
.insert("consensus.node_key", consensus_keys.node_secret)
89105
}
90106

91107
pub fn set_consensus_node_key(&mut self, raw_key: &str) -> anyhow::Result<()> {

zkstack_cli/crates/zkstack/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ This document contains the help content for the `zk_inception` command-line prog
2121
- [`zk_inception chain deploy-multicall3`](#zk_inception-chain-deploy-multicall3)
2222
- [`zk_inception chain deploy-paymaster`](#zk_inception-chain-deploy-paymaster)
2323
- [`zk_inception chain update-token-multiplier-setter`](#zk_inception-chain-update-token-multiplier-setter)
24-
- [`zk_inception consensus set-attester-committee`](#zk_inception-consensus-set-attester-committee)
25-
- [`zk_inception consensus get-attester-committee`](#zk_inception-consensus-get-attester-committee)
24+
- [`zk_inception consensus set-validator-committee`](#zk_inception-consensus-set-validator-committee)
25+
- [`zk_inception consensus get-validator-committee`](#zk_inception-consensus-get-validator-committee)
2626
- [`zk_inception prover`](#zk_inception-prover)
2727
- [`zk_inception prover init`](#zk_inception-prover-init)
2828
- [`zk_inception prover setup-keys`](#zk_inception-prover-setup-keys)
@@ -438,37 +438,37 @@ Consensus related commands
438438

439439
###### **Subcommands:**
440440

441-
- `set-attester-committee` — Set attester committee
442-
- `get-attester-committee` — Get attester committee
441+
- `set-validator-committee` — Set validator committee
442+
- `get-validator-committee` — Get validator committee
443443

444-
## `zk_inception consensus set-attester-committee`
444+
## `zk_inception consensus set-validator-committee`
445445

446-
Set attester committee in the consensus registry smart contract. Requires `consensus_registry` and `multicall3`
446+
Set validator committee in the consensus registry smart contract. Requires `consensus_registry` and `multicall3`
447447
contracts to be deployed.
448448

449-
**Usage:** `zk_inception consensus set-attester-committee [OPTIONS]`
449+
**Usage:** `zk_inception consensus set-validator-committee [OPTIONS]`
450450

451451
###### **Options:**
452452

453-
- `--from-genesis` — Set attester committee to `consensus.genesis_spec.attesters` in general.yaml Mutually exclusive
454-
with `--from-file`.
455-
- `--from-file <PATH>` — Set attester committee to committee specified in yaml file at `PATH`. Mutually exclusive with
456-
`--from-genesis`. File format is specified in `zk_inception/src/commands/consensus/proto/mod.proto`. Example:
453+
- `--from-file <PATH>` — Set validator committee to committee specified in yaml file at `PATH`. File format is as in
454+
this example:
457455

458456
```yaml
459-
attesters:
460-
- key: attester:public:secp256k1:0339d4b0cdd9896d3929631a4e5e9a5b4919f52592bec571d70bb0e50a3a824714
461-
weight: 1
462-
- key: attester:public:secp256k1:024897d8c10d7a57d108cfe2a724d7824c657f219ef5d9f7674810a6746c19fa7b
457+
validators:
458+
- key: validator:public:bls12_381:????
459+
pop: validator:pop:bls12_381:????
460+
weight: 3
461+
- key: validator:public:bls12_381:????
462+
pop: validator:pop:bls12_381:????
463463
weight: 1
464464
```
465465
466-
## `zk_inception consensus get-attester-committee`
466+
## `zk_inception consensus get-validator-committee`
467467

468-
Requires `consensus_registry` and `multicall3` contracts to be deployed. Fetches attester committee from the consensus
468+
Requires `consensus_registry` and `multicall3` contracts to be deployed. Fetches validator committee from the consensus
469469
registry contract and prints it.
470470

471-
**Usage:** `zk_inception consensus get-attester-committee`
471+
**Usage:** `zk_inception consensus get-validator-committee`
472472

473473
## `zk_inception prover`
474474

0 commit comments

Comments
 (0)