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

refactor substrate-common to entropy-shared #272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .circleci/then.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ workflows:
# # - crypto-centralized-keygen
# - crypto-server
# # - crypto-kvdb
# # - crypto-substrate-common
# # - crypto-entropy-shared
node:
when:
or: [ << pipeline.parameters.node >>, << pipeline.parameters.pallets >>, << pipeline.parameters.runtime >>, pipeline.parameters.crypto ]
Expand Down Expand Up @@ -97,13 +97,13 @@ jobs:
# steps:
# - install-dependencies-and-checkout
# - run: cd crypto/kvdb
# crypto-substrate-common:
# crypto-entropy-shared:
# machine:
# image: "ubuntu-2004:202201-02"
# resource_class: "xlarge"
# steps:
# - install-dependencies-and-checkout
# - run: cd crypto/substrate-common
# - run: cd crypto/shared
node-test:
machine:
image: "ubuntu-2004:202201-02"
Expand Down
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'substrate-common'",
"name": "Debug unit tests in library 'entropy-shared'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=substrate-common"
"--package=entropy-shared"
],
"filter": {
"name": "substrate-common",
"name": "entropy-shared",
"kind": "lib"
}
},
Expand Down
40 changes: 20 additions & 20 deletions Cargo.lock

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

28 changes: 19 additions & 9 deletions crypto/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# Crypto

This document serves as a partial spec of this repo.

The major actors in this repo are:

- `server`:
- `signing-client` - HTTP endpoints run by all nodes for signing protocols
- `communication-manager` (TO BE DEPRECATED, see note below) - AKA, the previous block's proposer. The CM is run by the previous block-proposer, and is responsible for choosing and notifying signing parties for each user signing-tx in the previous block.
- Currently, each node must notify the communication manager what shares they hold (`send_ip_address`), after which, the CM chooses the parties.
- After implementing Partitions, all info about which nodes hold which shares will be stored on-chain, and this call will be eliminated.
- `partition` - (unimpl) Entropy nodes are partitioned into one of $N$ Partitions. Nodes from the same Partition have equivalent secret keyshare information.
- After implementing Partitions, all info about which nodes hold which shares will be stored on-chain, and this call will be eliminated.
- `partition` - (unimpl) Entropy nodes are partitioned into one of $N$ Partitions. Nodes from the same Partition have equivalent secret keyshare information.
- To be deprecated 2022-08-26: Each Partition has a Partition Leader, who broadcasts messages to the Partition, eg., when receiving shares from new users.
- instead: `new_user`: user contacts all nodes in the network directly with a message containing that node's share
- why: reduces complexity, avoids issue of malicious committee leader

The utility crates in this repo are:

- `kvdb` - An encrypted key-value datastore
- `substrate-common` - Common no-std types, which Substrate requires
- `entropy-shared` - Common no-std types, which Substrate requires
- `testing-utils` - testing utility methods shared across the workspace
- `constraints` - A `whitelist` feature. On Thor's chopping block, to be integrated into `server`

## Documentation of major APIs

At the moment, these two APIs are in progress:

- `sign` (in progress)
- `new_user` (to impl after sign, includes changes to Partition)

Expand All @@ -29,22 +34,27 @@ Eventually these will also be implemented:
- `delete_user` - remove a user's information from all nodes

## `new_user` - create a new user (todo)

deprecated 2022-08-26:

1. deprecate: Each Partition Leader is informed of a new user's secret keyshare by the User. User calls `partition_leader::new_user` on each CL.
2. Partition Leaders validate that each other CL received a valid keyshare.
3. Each CL broadcasts the user's secret keyshare (by calling `new_user`) to each node in their Partition.

Instead:
1. The user sends each node in the network containing a share.

1. The user sends each node in the network containing a share.
2. Nodes validate that each other node in their Partition received an identical keyshare.
3. Test the share validity: one node from each partition is selected to construct a signature.
- If the signature is valid, end, post (todo: what data) new-user data on chain
- If the signature is invalid, and no node faulted, user is at fault, fail
- If the signature is invalid, and a node faulted, slash node, retry with new node from that partition
3. Test the share validity: one node from each partition is selected to construct a signature.

- If the signature is valid, end, post (todo: what data) new-user data on chain
- If the signature is invalid, and no node faulted, user is at fault, fail
- If the signature is invalid, and a node faulted, slash node, retry with new node from that partition

## `sign` - construct a signature to return to the user

1. User submits a transaction (`pallets::relayer::prep_transaction`) to the chain, containing a message including their substrate address and their (hashed) message.
2. A set of transactions is picked up by the next block proposer (substrate: TODO). The proposed block contains the proposed signing party information (`server/sign_init`).
2. A set of transactions is picked up by the next block proposer (substrate: TODO). The proposed block contains the proposed signing party information (`server/sign_init`).
3. Upon block finalization, signers read the block (substrate: TODO), containing the IP addresses of nodes who must now execute signing protocols. If a node is in a signing party, it advances to the next step.
<!-- 2. In the next block, an offchain worker is created (`pallet::propagation::offchain_worker`) -->
<!-- - currently: by each node. The communication manager waits for calls from each other node about node party information. -->
Expand Down
14 changes: 9 additions & 5 deletions crypto/constraints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ edition="2021"
thiserror="1.0"

# parsing
serde ="1.0.147"
serde_json ="1.0"
serde_derive ="1.0.147"
substrate-common={ path="../substrate-common", default-features=false }
sp-core ={ git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.30" }
serde ="1.0.147"
serde_json ="1.0"
serde_derive ="1.0.147"
entropy-shared={ path="../shared", default-features=false }
sp-core ={ git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.30", default-features=false }

# EVM
web3={ version="0.17.0", default-features=false }

[features]
default=["std"]
std =["serde/std", "serde_json/std", "entropy-shared/std", "sp-core/std"]
2 changes: 1 addition & 1 deletion crypto/constraints/src/constraint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use substrate_common::{Acl, AclKind, Architecture, BasicTransaction};
use entropy_shared::{Acl, AclKind, Architecture, BasicTransaction};
use thiserror::Error;

/// Constraint errors.
Expand Down
2 changes: 1 addition & 1 deletion crypto/constraints/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use substrate_common::{Acl, AclKind, Architecture};
use entropy_shared::{Acl, AclKind, Architecture};

use crate::{
constraint::Constraint,
Expand Down
2 changes: 1 addition & 1 deletion crypto/constraints/src/tx/evm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This includes all EVM-architecture related types and functions.
use entropy_shared::{Arch, Architecture, HasArch, HasReceiver, HasSender};
use serde_derive::{Deserialize, Serialize};
use substrate_common::{Arch, Architecture, HasArch, HasReceiver, HasSender};
use web3::types::Address;
pub use web3::types::TransactionRequest as EvmTransactionRequest;

Expand Down
2 changes: 1 addition & 1 deletion crypto/constraints/src/tx/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use entropy_shared::{Architecture, BasicTransaction, HasReceiver, HasSender};
use serde_json::from_value;
use substrate_common::{Architecture, BasicTransaction, HasReceiver, HasSender};
use thiserror::Error;

/// Errors related to parsing raw transactions
Expand Down
2 changes: 1 addition & 1 deletion crypto/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sp-core ={ package="sp-core", git="https://github.com/paritytech/subst
tofn ={ git="https://github.com/entropyxyz/tofn", branch="main" }

# Entropy
substrate-common ={ path="../substrate-common" }
entropy-shared ={ path="../shared" }
kvdb ={ path="../kvdb", default-features=false }
entropy-constraints={ path="../constraints" }

Expand Down
Binary file modified crypto/server/entropy_metadata.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion crypto/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ extern crate rocket;
use std::{string::String, thread, time::Duration};

use clap::Parser;
use entropy_shared::{MIN_BALANCE, SIGNING_PARTY_SIZE};
use kvdb::kv_manager::{error::KvError, KeyReservation, KvManager};
use rocket::routes;
use sp_keyring::AccountKeyring;
use substrate_common::{MIN_BALANCE, SIGNING_PARTY_SIZE};
use subxt::ext::sp_core::{crypto::AccountId32, sr25519, Pair};

use self::{
Expand Down
2 changes: 1 addition & 1 deletion crypto/server/src/sign_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl SignInit {

// TODO: remove when we have a real implementation
// Generate temporary data for API testing.
pub(crate) fn temporary_data(message: substrate_common::Message) -> Self {
pub(crate) fn temporary_data(message: entropy_shared::Message) -> Self {
let digest: MessageDigest = message.sig_request.sig_hash.as_slice().try_into().unwrap();
let raw_address = &message.account;
let address_slice: &[u8; 32] =
Expand Down
2 changes: 1 addition & 1 deletion crypto/server/src/signing_client/api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{io, str};

use entropy_shared::OCWMessage;
use kvdb::kv_manager::KvManager;
use parity_scale_codec::Decode;
use rocket::{http::Status, response::stream::EventStream, serde::json::Json, Shutdown, State};
use substrate_common::OCWMessage;
use subxt::ext::sp_runtime::AccountId32;
use tracing::instrument;

Expand Down
2 changes: 1 addition & 1 deletion crypto/server/src/signing_client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
};

use bincode::Options;
use entropy_shared::{Message, SigRequest};
use kvdb::{
clean_tests, encrypted_sled::PasswordMethod, get_db_path, kv_manager::value::KvManager,
};
Expand All @@ -20,7 +21,6 @@ use rocket::{
use serial_test::serial;
use sp_core::{crypto::AccountId32, sr25519::Pair as Sr25519Pair, Pair as Pair2};
use sp_keyring::AccountKeyring;
use substrate_common::{Message, SigRequest};
use subxt::{ext::sp_core::sr25519, tx::PairSigner};
use testing_utils::context::{test_context, test_context_stationary};
use tofn::{
Expand Down
8 changes: 4 additions & 4 deletions crypto/server/src/user/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use bip39::{Language, Mnemonic};
use entropy_constraints::tx::evm::Evm;
use entropy_shared::{
types::{Acl, AclKind, Architecture, BasicTransaction},
SIGNING_PARTY_SIZE,
};
use kvdb::kv_manager::{
error::{InnerKvError, KvError},
value::PartyInfo,
Expand All @@ -14,10 +18,6 @@ use rocket::{
};
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize as DeserializeDerive, Serialize as SerializeDerive};
use substrate_common::{
types::{Acl, AclKind, Architecture, BasicTransaction},
SIGNING_PARTY_SIZE,
};
use subxt::{
ext::{
sp_core::{sr25519, Pair},
Expand Down
2 changes: 1 addition & 1 deletion crypto/server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
message::{derive_static_secret, mnemonic_to_pair, new_mnemonic, SignedMessage},
setup_mnemonic,
user::{
tests::entropy::runtime_types::substrate_common::constraints::acl::Acl,
tests::entropy::runtime_types::entropy_shared::constraints::acl::Acl,
unsafe_api::UnsafeQuery,
},
utils,
Expand Down
Loading