Skip to content

Commit

Permalink
Merge branch 'master' into subxt-client
Browse files Browse the repository at this point in the history
* master:
  Integration test for validator joining network (#493)
  Add `ENTROPY_NODE` environment variable (#497)
  Change `SocketAddr` type for `String` (#496)
  Allow big protocol messages (#495)
  Add test for `EncryptedConnection` (#494)
  Use bincode rather than JSON for protocol and subscribe messages (#492)
  Remark on possible need to address TSS server from the Docker host. (#490)
  no proactive refresh on private key visibility (#485)
  Auxiliary data for program evaluation (#475)
  Validate proactive refresh endpoint (#483)
  • Loading branch information
ameba23 committed Nov 14, 2023
2 parents f698f96 + 46a3602 commit 77377d6
Show file tree
Hide file tree
Showing 47 changed files with 912 additions and 452 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ At the moment this project **does not** adhere to

## [Unreleased]

### Breaking Changes

- In the JSON body of the `/sign_tx` endpoint, the `preimage` field has been renamed to `message`. It remains a hex-encoded `string`. [#475](https://github.com/entropyxyz/entropy-core/pull/475/)

### Added
- Auxiliary data for program evaluation ([#475](https://github.com/entropyxyz/entropy-core/pull/475/))

## [0.0.8](https://github.com/entropyxyz/entropy-core/compare/v0.0.7..v0.0.8) - 2023-11-06

### Breaking Changes
Expand Down
20 changes: 16 additions & 4 deletions Cargo.lock

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

29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ This repository provides a [Docker Compose](https://docs.docker.com/compose/) co
```sh
docker compose up --detach # Detaching is optional.
```
```sh
docker compose up --detach # Detaching is optional.
```
1. Once running, if you have `--detach`ed your terminal from the containers' output streams, you can view them again like so:
```sh
docker compose logs --follow # Following is also optional.
```
1. If you need to communicate directly with the threshold signature scheme server from your Docker host machine, you may also need to include its address in your local `/etc/hosts` file:
```sh
echo "127.0.0.1 alice-tss-server bob-tss-server" | sudo tee -a /etc/hosts
```
### Building from source
Expand Down Expand Up @@ -66,12 +67,26 @@ RUST_BACKTRACE=1 ./target/release/entropy -ldebug --dev --rpc-external
### Testing
Testing is done via `cargo test`. When testing `server`, ensure the `entropy` **release** binary exists and is up to date; run `cargo build --release -p entropy` when in doubt.
Testing is done via `cargo test`.
An Entropy node binary is required in order to succesfully run the server tests.
You can manually provide a binary using the `ENTROPY_NODE` environment variable.
```sh
ENTROPY_NODE="/path/to/entropy" cargo test -p server
```
Or, if no path is specified using `ENTROPY_NODE`, then the test suite will search in the `target`
folder for a binary. A debug or release binary will be chosen based on how the test suite is built.
For example, running `cargo test -p server --release` will expect a release binary of the Entropy
node, which you can build in the following way: `cargo build -p entropy --release`.
Because of `clap`, running individual tests require using the `--test` flag as a program argument for the `server` binary when using `cargo test`. For example, to run the `test_new_party` test in `crypto/server/src/user/tests.rs`, you would run something similar to:
To run individual tests you can specify the test in the following way:
```sh
cargo test --release -p server --features unsafe -- --test user::tests::test_unsigned_tx_endpoint --nocapture
cargo test -p server --features unsafe -- test_sign_tx_no_chain --nocapture
```
### Connect with Polkadot-JS Apps Front-end
Expand Down Expand Up @@ -124,4 +139,4 @@ to interact with your chain. [Click here](https://polkadot.js.org/apps/#/explore
## Pulling Metadata
Everytime a change to the chain's interface happens, metadata needs to be pulled. You'll need to install Subxt using `cargo install subxt-cli`. Then [run a development chain](#getting-started-with-docker) and then invoke [the `./scripts/pull_entropy_metadata.sh` script](./scripts/pull_entropy_metadata.sh).
Everytime a change to the chain's interface happens, metadata needs to be pulled. You'll need to install Subxt using `cargo install subxt-cli`. Then [run a development chain](#getting-started-with-docker) and then invoke [the `./scripts/pull_entropy_metadata.sh` script](./scripts/pull_entropy_metadata.sh).
13 changes: 10 additions & 3 deletions crypto/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition ='2021'

[dependencies]
async-trait ="0.1.73"
serde_json ="1.0"
entropy-shared ={ path="../shared", default-features=false }
synedrion ={ git="ssh://git@github.com/entropyxyz/synedrion.git", tag="v0.0.9" }
serde ={ version="1.0", features=["derive"], default-features=false }
Expand All @@ -27,11 +26,19 @@ snow ="0.9.2"
getrandom ={ version="0.2", features=["js"] }
rand_core ={ version="0.6.4", features=["getrandom"] }
tracing ="0.1.37"
bincode ="1.3.3"

# Used only with the `server` feature to implement the WsConnection trait
axum ={ version="0.6.18", features=["ws"], optional=true }
tokio-tungstenite={ version="0.19.0", optional=true }

[features]
server=["dep:axum", "dep:tokio-tungstenite", "entropy-shared/std", "subxt/substrate-compat"]
wasm =["entropy-shared/wasm", "subxt-signer/web"]
default=["server"]
server=[
"dep:axum",
"dep:tokio-tungstenite",
"entropy-shared/std",
"subxt/substrate-compat",
"subxt/native",
]
wasm=["entropy-shared/wasm", "subxt-signer/web"]
4 changes: 2 additions & 2 deletions crypto/protocol/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub enum UserRunningProtocolErr {
EncryptedConnection(#[from] EncryptedConnectionErr),
#[error("Protocol Execution Error {0}")]
ProtocolExecution(#[from] ProtocolExecutionErr),
#[error("Serde Json error: {0}")]
SerdeJson(#[from] serde_json::Error),
#[error("Serialization Error: {0:?}")]
Serialization(#[from] bincode::Error),
#[error("Bad Subscribe Message: {0}")]
BadSubscribeMessage(String),
#[error("Connection Error: {0}")]
Expand Down
4 changes: 2 additions & 2 deletions crypto/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod protocol_message;
pub mod protocol_transport;
pub mod user;

use std::{fmt, net::SocketAddr};
use std::fmt;

use entropy_shared::X25519PublicKey;
pub use protocol_message::ProtocolMessage;
Expand Down Expand Up @@ -94,6 +94,6 @@ impl RecoverableSignature {
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct ValidatorInfo {
pub x25519_public_key: X25519PublicKey,
pub ip_address: SocketAddr,
pub ip_address: String,
pub tss_account: AccountId32,
}
6 changes: 3 additions & 3 deletions crypto/protocol/src/protocol_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub struct ProtocolMessage {
pub payload: SignedMessage<SignatureWrapper>,
}

impl TryFrom<&String> for ProtocolMessage {
impl TryFrom<&[u8]> for ProtocolMessage {
type Error = ProtocolMessageErr;

fn try_from(value: &String) -> Result<Self, Self::Error> {
let parsed_msg: ProtocolMessage = serde_json::from_str(value)?;
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
let parsed_msg: ProtocolMessage = bincode::deserialize(value)?;
Ok(parsed_msg)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/protocol/src/protocol_transport/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum WsError {
#[error("Error parsing Signing Message")]
ProtocolMessage(#[from] super::errors::ProtocolMessageErr),
#[error("Serialization Error: {0:?}")]
Serialization(#[from] serde_json::Error),
Serialization(#[from] bincode::Error),
#[error("Received bad subscribe message")]
BadSubscribeMessage,
}
Expand All @@ -33,7 +33,7 @@ pub enum ProtocolMessageErr {
#[error("Utf8Error: {0:?}")]
Utf8(#[from] std::str::Utf8Error),
#[error("Deserialization Error: {0:?}")]
Deserialization(#[from] serde_json::Error),
Deserialization(#[from] bincode::Error),
}

/// Errors relating to encrypted WS connections / noise handshaking
Expand Down
6 changes: 3 additions & 3 deletions crypto/protocol/src/protocol_transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub async fn ws_to_channels<T: WsConnection>(
// Incoming message from remote peer
signing_message_result = connection.recv() => {
let serialized_signing_message = signing_message_result.map_err(|e| WsError::EncryptedConnection(e.to_string()))?;
let msg = ProtocolMessage::try_from(&serialized_signing_message)?;
let msg = ProtocolMessage::try_from(&serialized_signing_message[..])?;
ws_channels.tx.send(msg).await.map_err(|_| WsError::MessageAfterProtocolFinish)?;
}
// Outgoing message (from signing protocol to remote peer)
Expand All @@ -103,10 +103,10 @@ pub async fn ws_to_channels<T: WsConnection>(
continue;
}
}
let message_string = serde_json::to_string(&msg)?;
let message_vec = bincode::serialize(&msg)?;
// TODO if this fails, the ws connection has been dropped during the protocol
// we should inform the chain of this.
connection.send(message_string).await.map_err(|e| WsError::EncryptedConnection(e.to_string()))?;
connection.send(message_vec).await.map_err(|e| WsError::EncryptedConnection(e.to_string()))?;
}
}
}
Expand Down
Loading

0 comments on commit 77377d6

Please sign in to comment.