Skip to content

Commit

Permalink
refactor: split bls and secp256k1 private key
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Oct 11, 2023
1 parent cf935f6 commit 02bf649
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 27 deletions.
5 changes: 4 additions & 1 deletion common/config-parser/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub const DEFAULT_CACHE_SIZE: usize = 100;
pub struct Config {
// crypto
#[serde(deserialize_with = "deserialize_256bits_key")]
pub privkey: Key256Bits,
pub net_privkey: Key256Bits,
#[serde(deserialize_with = "deserialize_256bits_key")]
pub bls_privkey: Key256Bits,

// db config
pub data_path: PathBuf,

Expand Down
2 changes: 1 addition & 1 deletion core/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl NetworkConfig {
.collect(),
)
.listen_addr(config.network.listening_address.clone())
.secio_keypair(config.privkey.as_ref())?
.secio_keypair(config.net_privkey.as_ref())?
.chain_id(chain_id)
.max_connections(config.network.max_connected_peers)
}
Expand Down
9 changes: 6 additions & 3 deletions core/run/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use common_config_parser::types::spec::{ChainSpec, InitialAccount};
use common_config_parser::types::{Config, ConfigMempool};
use common_crypto::{
BlsPrivateKey, BlsPublicKey, Secp256k1, Secp256k1PrivateKey, Secp256k1RecoverablePrivateKey,
ToPublicKey,
ToBlsPublicKey, ToPublicKey,
};

use protocol::tokio::{
Expand Down Expand Up @@ -224,7 +224,7 @@ async fn start<K: KeyProvider>(

// Init overlord consensus and synchronization
let lock = Arc::new(AsyncMutex::new(()));
let crypto = init_crypto(config.privkey.as_ref(), &metadata.verifier_list)?;
let crypto = init_crypto(config.bls_privkey.as_ref(), &metadata.verifier_list)?;
let consensus_adapter = OverlordConsensusAdapter::<_, _, _, _>::new(
Arc::new(network_service.handle()),
Arc::clone(&mempool),
Expand All @@ -238,11 +238,14 @@ async fn start<K: KeyProvider>(
let hardfork_info = storage.hardfork_proposal(Default::default()).await?;
let overlord_consensus = {
let consensus_wal_path = config.data_path_for_consensus_wal();
let node_info = Secp256k1PrivateKey::try_from(config.privkey.as_ref())
let bls_priv_key =
BlsPrivateKey::try_from(config.bls_privkey.as_ref()).map_err(MainError::Crypto)?;
let node_info = Secp256k1PrivateKey::try_from(config.net_privkey.as_ref())
.map(|privkey| {
NodeInfo::new(
current_block.header.chain_id,
privkey.pub_key(),
bls_priv_key.pub_key(&Default::default()),
hardfork_info,
)
})
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d"
net_privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d"
bls_privkey = "0x4179b05f5ad5bdd46ca98a9e8b435b00a504562dfe02687895edf747ddf5de18"

# db config
data_path = "./devtools/chain/data"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/k8s/node_1.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d"
net_privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d"
bls_privkey = "0x4179b05f5ad5bdd46ca98a9e8b435b00a504562dfe02687895edf747ddf5de18"

# db config
data_path = "./devtools/chain/data1"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/k8s/node_2.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32"
net_privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32"
bls_privkey = "0x422951d5ac7ddbe86cae7d2d4c82af713785b3177043ac6feb50eda7e360b860"

# db config
data_path = "./devtools/chain/data2"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/k8s/node_3.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936"
net_privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936"
bls_privkey = "0x51a04542786ca3bae046d1c7451b6a0745efdcc66c39ede37827172f964d5fdf"

# db config
data_path = "./devtools/chain/data3"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/k8s/node_4.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e"
net_privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e"
bls_privkey = "0x67fc8772fdcff8140564e9c4ed693fffd0929c68f24529ee2fb2adfbe9c453fe"

# db config
data_path = "./devtools/chain/data4"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/nodes/node_1.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d"
net_privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d"
bls_privkey = "0x4179b05f5ad5bdd46ca98a9e8b435b00a504562dfe02687895edf747ddf5de18"

# db config
data_path = "./devtools/chain/data/node_1"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/nodes/node_2.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32"
net_privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32"
bls_privkey = "0x422951d5ac7ddbe86cae7d2d4c82af713785b3177043ac6feb50eda7e360b860"

# db config
data_path = "./devtools/chain/data/node_2"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/nodes/node_3.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936"
net_privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936"
bls_privkey = "0x51a04542786ca3bae046d1c7451b6a0745efdcc66c39ede37827172f964d5fdf"

# db config
data_path = "./devtools/chain/data/node_3"
Expand Down
3 changes: 2 additions & 1 deletion devtools/chain/nodes/node_4.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# crypto
privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e"
net_privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e"
bls_privkey = "0x67fc8772fdcff8140564e9c4ed693fffd0929c68f24529ee2fb2adfbe9c453fe"

# db config
data_path = "./devtools/chain/data/node_4"
Expand Down
8 changes: 4 additions & 4 deletions devtools/chain/specs/multi_nodes/chain-spec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,28 @@ gas_limit = 4294967295000
interval = 3000

[[params.verifier_list]]
bls_pub_key = "0xac85bbb40347b6e06ac2dc2da1f75eece029cdc0ed2d456c457d27e288bfbfbcd4c5c19716e9b250134a0e76ce50fa22"
bls_pub_key = "0xa26e3fe1cf51bd4822072c61bdc315ac32e3d3c2e2484bb92942666399e863b4bf56cf2926383cc706ffc15dfebc85c6"
pub_key = "0x031ddc35212b7fc7ff6685b17d91f77c972535aee5c7ae5684d3e72b986f08834b"
address = "0x8ab0cf264df99d83525e9e11c7e4db01558ae1b1"
propose_weight = 1
vote_weight = 1

[[params.verifier_list]]
bls_pub_key = "0x91ed9f3c51c580e56948b1bda9d00c2159665f8a6e284191ab816ee64ef2487d78453a547a0f14efbf842bba5b5a3b4f"
bls_pub_key = "0x80310fa9df724b5603d283b472ed3bf85254a8a4ceda8a274b421f6cf2be1d9184267cdfe9a199d36ff14e57668a55d0"
pub_key = "0x02b77c74eb68af3d4d6cc7884ed6709f1a2a1af0f713382a4438ec2ea3a70d4d7f"
address = "0xf386573563c3a75dbbd269fce9782620826ddac2"
propose_weight = 1
vote_weight = 1

[[params.verifier_list]]
bls_pub_key = "0x92e5d0856fb20ea9cb5ab5da2d3331c38d32cc96507f6ad902fa3da9400096a485fb4e09834bc93de55db224f26c229c"
bls_pub_key = "0x897721e9016864141a8b982a48217f66ef318ce598aa31842cddaaebe3cd7feab17050022afa6c2123aba39938fe4142"
pub_key = "0x027ffd6a6a231561f2afe5878b1c743323b34263d16787130b1815fe35649b0bf5"
address = "0x8af204ac5d7cb8815a6c53a50b72d01e729d3b22"
propose_weight = 1
vote_weight = 1

[[params.verifier_list]]
bls_pub_key = "0xa694f4e48a5a173b61731998f8f1204342dc5c8eb1e32cdae37415c20d11ae035ddac4a39f105e9c2d4d3691024d385d"
bls_pub_key = "0x98eef09a3927acb225191101a1d9aa85775fdcdc87b9ba36898f6c132b485d66aef91c0f51cda331be4f985c3be6761c"
pub_key = "0x0232c489c23b1207107e9a24648c1e4754a8c1c0b38db96df57a526201035058cb"
address = "0xf4cc1652dcec2e5de9ce6fb1b6f9fa9456e957f1"
propose_weight = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,28 @@ gas_limit = 4294967295000
interval = 3000

[[params.verifier_list]]
bls_pub_key = "0xac85bbb40347b6e06ac2dc2da1f75eece029cdc0ed2d456c457d27e288bfbfbcd4c5c19716e9b250134a0e76ce50fa22"
bls_pub_key = "0xa26e3fe1cf51bd4822072c61bdc315ac32e3d3c2e2484bb92942666399e863b4bf56cf2926383cc706ffc15dfebc85c6"
pub_key = "0x031ddc35212b7fc7ff6685b17d91f77c972535aee5c7ae5684d3e72b986f08834b"
address = "0x8ab0cf264df99d83525e9e11c7e4db01558ae1b1"
propose_weight = 1
vote_weight = 1

[[params.verifier_list]]
bls_pub_key = "0x91ed9f3c51c580e56948b1bda9d00c2159665f8a6e284191ab816ee64ef2487d78453a547a0f14efbf842bba5b5a3b4f"
bls_pub_key = "0x80310fa9df724b5603d283b472ed3bf85254a8a4ceda8a274b421f6cf2be1d9184267cdfe9a199d36ff14e57668a55d0"
pub_key = "0x02b77c74eb68af3d4d6cc7884ed6709f1a2a1af0f713382a4438ec2ea3a70d4d7f"
address = "0xf386573563c3a75dbbd269fce9782620826ddac2"
propose_weight = 1
vote_weight = 1

[[params.verifier_list]]
bls_pub_key = "0x92e5d0856fb20ea9cb5ab5da2d3331c38d32cc96507f6ad902fa3da9400096a485fb4e09834bc93de55db224f26c229c"
bls_pub_key = "0x897721e9016864141a8b982a48217f66ef318ce598aa31842cddaaebe3cd7feab17050022afa6c2123aba39938fe4142"
pub_key = "0x027ffd6a6a231561f2afe5878b1c743323b34263d16787130b1815fe35649b0bf5"
address = "0x8af204ac5d7cb8815a6c53a50b72d01e729d3b22"
propose_weight = 1
vote_weight = 1

[[params.verifier_list]]
bls_pub_key = "0xa694f4e48a5a173b61731998f8f1204342dc5c8eb1e32cdae37415c20d11ae035ddac4a39f105e9c2d4d3691024d385d"
bls_pub_key = "0x98eef09a3927acb225191101a1d9aa85775fdcdc87b9ba36898f6c132b485d66aef91c0f51cda331be4f985c3be6761c"
pub_key = "0x0232c489c23b1207107e9a24648c1e4754a8c1c0b38db96df57a526201035058cb"
address = "0xf4cc1652dcec2e5de9ce6fb1b6f9fa9456e957f1"
propose_weight = 1
Expand Down
2 changes: 1 addition & 1 deletion devtools/chain/specs/single_node/chain-spec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ gas_limit = 4294967295000
interval = 3000

[[params.verifier_list]]
bls_pub_key = "0xac85bbb40347b6e06ac2dc2da1f75eece029cdc0ed2d456c457d27e288bfbfbcd4c5c19716e9b250134a0e76ce50fa22"
bls_pub_key = "0xa26e3fe1cf51bd4822072c61bdc315ac32e3d3c2e2484bb92942666399e863b4bf56cf2926383cc706ffc15dfebc85c6"
pub_key = "0x031ddc35212b7fc7ff6685b17d91f77c972535aee5c7ae5684d3e72b986f08834b"
address = "0x8ab0cf264df99d83525e9e11c7e4db01558ae1b1"
propose_weight = 1
Expand Down
11 changes: 7 additions & 4 deletions protocol/src/traits/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
sync::{Arc, RwLock},
};

use common_crypto::Secp256k1PublicKey;
use common_crypto::{BlsPublicKey, Secp256k1PublicKey};

use crate::types::{
Address, Block, BlockNumber, Bytes, ExecResp, HardforkInfoInner, Hash, Header, Hex, MerkleRoot,
Expand All @@ -21,20 +21,23 @@ pub enum MessageTarget {
pub struct NodeInfo {
pub chain_id: u64,
pub self_pub_key: Secp256k1PublicKey,
pub self_bls_pub_key: BlsPublicKey,
pub self_address: Address,
pub hardfork_proposals: Arc<RwLock<Option<HardforkInfoInner>>>,
}

impl NodeInfo {
pub fn new(
chain_id: u64,
pubkey: Secp256k1PublicKey,
pub_key: Secp256k1PublicKey,
bls_pub_key: BlsPublicKey,
hardfork_info: Option<HardforkInfoInner>,
) -> Self {
let address = Address::from_pubkey(&pubkey);
let address = Address::from_pubkey(&pub_key);
Self {
chain_id,
self_pub_key: pubkey,
self_pub_key: pub_key,
self_bls_pub_key: bls_pub_key,
self_address: address,
hardfork_proposals: Arc::new(RwLock::new(hardfork_info)),
}
Expand Down

0 comments on commit 02bf649

Please sign in to comment.