Skip to content

Commit

Permalink
[feature] hyperledger#4285: Verifiable Random Function in Sumeragi
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
  • Loading branch information
SamHSmith committed Apr 8, 2024
1 parent 3772c56 commit 853e131
Show file tree
Hide file tree
Showing 31 changed files with 285 additions and 144 deletions.
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cli/src/lib.rs
Expand Up @@ -622,14 +622,15 @@ mod tests {

use assertables::{assert_contains, assert_contains_as_result};
use iroha_config::parameters::user::RootPartial as PartialUserConfig;
use iroha_crypto::KeyPair;
use iroha_crypto::{Algorithm, KeyPair};
use iroha_primitives::addr::socket_addr;
use path_absolutize::Absolutize as _;

use super::*;

fn config_factory() -> PartialUserConfig {
let (pubkey, privkey) = KeyPair::random().into_parts();
let (pubkey, privkey) =
KeyPair::random_with_algorithm(Algorithm::Secp256k1).into_parts();

let mut base = PartialUserConfig::default();

Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/extra_functional/offline_peers.rs
Expand Up @@ -7,7 +7,7 @@ use iroha_client::{
},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_crypto::KeyPair;
use iroha_crypto::{Algorithm, KeyPair};
use iroha_primitives::addr::socket_addr;
use test_network::*;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -53,7 +53,7 @@ fn register_offline_peer() -> Result<()> {
check_status(&peer_clients, 1);

let address = socket_addr!(128.0.0.2:8085);
let key_pair = KeyPair::random();
let key_pair = KeyPair::random_with_algorithm(Algorithm::Secp256k1);
let public_key = key_pair.public_key().clone();
let peer_id = PeerId::new(address, public_key);
let register_peer = Register::peer(DataModelPeer::new(peer_id));
Expand Down
12 changes: 6 additions & 6 deletions config/iroha_test_config.toml
@@ -1,6 +1,6 @@
chain_id = "00000000-0000-0000-0000-000000000000"
public_key = "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"
private_key = { algorithm = "ed25519", payload = "282ED9F3CF92811C3818DBC4AE594ED59DC1A2F78E4241E31924E101D6B1FB831C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B" }
public_key = "e70121039B861E76EBC90B3348142E3ED6C82DE4F6223A003E19159397D93008CEDB2CF3"
private_key = { algorithm = "secp256k1", payload = "D9CAA39CD8DF8E20BDE9E21CB2A8DFF3DC3F152954E651D96F03E1EC94DFE581" }

[network]
address = "127.0.0.1:1337"
Expand All @@ -15,19 +15,19 @@ address = "127.0.0.1:8080"

[[sumeragi.trusted_peers]]
address = "127.0.0.1:1337"
public_key = "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"
public_key = "e7012102E7A461547D04FF0EA7E9A473D67B51A58C41E53F7D9583096052492ABDB430D4"

[[sumeragi.trusted_peers]]
address = "127.0.0.1:1338"
public_key = "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"
public_key = "e7012103F8DE33E3B492CE14346BCD330A0044FE8C03BFCA03168B513722CCB00BE42734"

[[sumeragi.trusted_peers]]
address = "127.0.0.1:1339"
public_key = "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"
public_key = "e701210390292D847084F39975E805DF70CEEBDF1FEC61C1547C77DC0B2A353C29DD3B97"

[[sumeragi.trusted_peers]]
address = "127.0.0.1:1340"
public_key = "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"
public_key = "e701210360E53577CDA472A8873ABFF96376E0A82A5123D718F91499D284A45D57A322EC"

[logger]
format = "pretty"
Expand Down
11 changes: 11 additions & 0 deletions config/src/parameters/user.rs
Expand Up @@ -142,6 +142,12 @@ impl Root {
let key_pair =
KeyPair::new(self.public_key, self.private_key)
.wrap_err("failed to construct a key pair from `iroha.public_key` and `iroha.private_key` configuration parameters")
.map(|key| {
if key.algorithm() != iroha_crypto::Algorithm::Secp256k1 {
emitter.emit(eyre!("Peer key pair must use algorithm Secp256k1. Problematic public key = {}", key.public_key()));
}
key
})
.map_or_else(|err| {
emitter.emit(err);
None
Expand Down Expand Up @@ -426,6 +432,11 @@ impl Sumeragi {
} = self;

let trusted_peers = construct_unique_vec(trusted_peers.unwrap_or(vec![]))?;
for peer in &trusted_peers {
if peer.public_key.algorithm() != iroha_crypto::Algorithm::Secp256k1 {
return Err(eyre!("Only Secp256k1 key pairs are allowed in the trusted peers. Problematic public key = {}", peer.public_key));
}
}

Ok(actual::Sumeragi {
trusted_peers,
Expand Down
36 changes: 18 additions & 18 deletions config/tests/fixtures.rs
Expand Up @@ -59,20 +59,20 @@ fn minimal_config_snapshot() -> Result<()> {
),
key_pair: KeyPair {
public_key: PublicKey(
ed25519(
"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
secp256k1(
"e701210309DC6B5DFAB2603E5577DF96D34314CED6A07389A047E772649FA877BCCA17B2",
),
),
private_key: ed25519(
"8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
private_key: secp256k1(
"7D7175A0C3F141A482C3DE3D23225686B6896C66D6430BBBC05867834DE3FA48",
),
},
p2p_address: 127.0.0.1:1337,
},
genesis: Partial {
public_key: PublicKey(
ed25519(
"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
secp256k1(
"e701210309DC6B5DFAB2603E5577DF96D34314CED6A07389A047E772649FA877BCCA17B2",
),
),
},
Expand All @@ -91,8 +91,8 @@ fn minimal_config_snapshot() -> Result<()> {
PeerId {
address: 127.0.0.1:1338,
public_key: PublicKey(
ed25519(
"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
secp256k1(
"e701210309DC6B5DFAB2603E5577DF96D34314CED6A07389A047E772649FA877BCCA17B2",
),
),
},
Expand Down Expand Up @@ -303,27 +303,27 @@ fn full_envs_set_is_consumed() -> Result<()> {
),
public_key: Some(
PublicKey(
ed25519(
"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
secp256k1(
"e701210309DC6B5DFAB2603E5577DF96D34314CED6A07389A047E772649FA877BCCA17B2",
),
),
),
private_key: Some(
ed25519(
"8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
secp256k1(
"7D7175A0C3F141A482C3DE3D23225686B6896C66D6430BBBC05867834DE3FA48",
),
),
genesis: GenesisPartial {
public_key: Some(
PublicKey(
ed25519(
"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
secp256k1(
"e701210309DC6B5DFAB2603E5577DF96D34314CED6A07389A047E772649FA877BCCA17B2",
),
),
),
private_key: Some(
ed25519(
"8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB",
secp256k1(
"7D7175A0C3F141A482C3DE3D23225686B6896C66D6430BBBC05867834DE3FA48",
),
),
file: None,
Expand All @@ -350,8 +350,8 @@ fn full_envs_set_is_consumed() -> Result<()> {
port: 1339,
},
public_key: PublicKey(
ed25519(
"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4",
secp256k1(
"e701210309DC6B5DFAB2603E5577DF96D34314CED6A07389A047E772649FA877BCCA17B2",
),
),
},
Expand Down
6 changes: 3 additions & 3 deletions config/tests/fixtures/base.toml
@@ -1,7 +1,7 @@
chain_id = "0"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key.algorithm = "ed25519"
private_key.payload = "8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb"
public_key = "e7012103DD678497624AF3F3A3F59F4F0AD3861751E7F3B16CA402E864A1499DD6358C55"
private_key.algorithm = "secp256k1"
private_key.payload = "BB52C74DC56A2E9028F3BC5B42ECEC6CDDF19DBD3CD11F2A23A0477670944E52"

[network]
address = "127.0.0.1:1337"
Expand Down
2 changes: 1 addition & 1 deletion config/tests/fixtures/base_trusted_peers.toml
@@ -1,3 +1,3 @@
[[sumeragi.trusted_peers]]
address = "127.0.0.1:1338"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
public_key = "e7012103756A6D80129A39E94D40E91826D96FE9DAE6F0EE153ADE3BE1246E019394F445"
6 changes: 3 additions & 3 deletions config/tests/fixtures/full.env
@@ -1,7 +1,7 @@
CHAIN_ID=0-0
PUBLIC_KEY=ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB
PRIVATE_KEY_ALGORITHM=ed25519
PRIVATE_KEY_PAYLOAD=8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb
PUBLIC_KEY=e7012103DD678497624AF3F3A3F59F4F0AD3861751E7F3B16CA402E864A1499DD6358C55
PRIVATE_KEY_ALGORITHM=secp256k1
PRIVATE_KEY_PAYLOAD=BB52C74DC56A2E9028F3BC5B42ECEC6CDDF19DBD3CD11F2A23A0477670944E52
P2P_ADDRESS=127.0.0.1:5432
GENESIS_PUBLIC_KEY=ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB
GENESIS_PRIVATE_KEY_ALGORITHM=ed25519
Expand Down
6 changes: 3 additions & 3 deletions config/tests/fixtures/full.toml
@@ -1,8 +1,8 @@
# This config has ALL fields specified (except `extends`)

chain_id = "0"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key = { algorithm = "ed25519", payload = "8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb" }
public_key = "e7012103DD678497624AF3F3A3F59F4F0AD3861751E7F3B16CA402E864A1499DD6358C55"
private_key = { algorithm = "secp256k1", payload = "BB52C74DC56A2E9028F3BC5B42ECEC6CDDF19DBD3CD11F2A23A0477670944E52" }

[genesis]
file = "genesis.json"
Expand Down Expand Up @@ -30,7 +30,7 @@ output_new_blocks = true

[[sumeragi.trusted_peers]]
address = "localhost:8081"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
public_key = "e7012103DD678497624AF3F3A3F59F4F0AD3861751E7F3B16CA402E864A1499DD6358C55"

[sumeragi.debug]
force_soft_fork = true
Expand Down
8 changes: 4 additions & 4 deletions config/tests/fixtures/minimal_file_and_env.toml
@@ -1,14 +1,14 @@
extends = "base_trusted_peers.toml"

chain_id = "0"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key.algorithm = "ed25519"
private_key.payload = "8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb"
public_key = "e7012103756A6D80129A39E94D40E91826D96FE9DAE6F0EE153ADE3BE1246E019394F445"
private_key.algorithm = "secp256k1"
private_key.payload = "1D39F2378F01F87F32AA830B7ABC4262EFEB44C67D7EA7BE277F1EA97C470CAE"

[network]
address = "127.0.0.1:1337"

[genesis]
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
public_key = "e7012103756A6D80129A39E94D40E91826D96FE9DAE6F0EE153ADE3BE1246E019394F445"

# `torii.address` should be in ENV

0 comments on commit 853e131

Please sign in to comment.