Skip to content

Bump synedrion to 0.3.0 and use manul for protocol session loop #1392

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

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from

Conversation

ameba23
Copy link
Collaborator

@ameba23 ameba23 commented Apr 7, 2025

Synedrion 0.3.0 and manul 0.2.0 have been released - this PR updates to using the new versions.

manul now gives as a function which implements the protocol execution loop. Which means we can move it out of entropy-protocol and use the manul-provided one. This is good as less code for us to maintain. However there are a couple of reasons why it is not a drop-in replacement:

  • manul's par_run_session function takes a tokio::sync::mpsc::unbounded::Sender but we have a tokio::sync::broadcast::Sender
  • Our ProtocolMessage needs to be replaced with manul::session::tokio::MessageIn and manul::session::tokio::MessageOut - but we would lose the extra bits protocol message gives us (eg: being able to pass the verifying key)

We get around this by using extra tasks/channels to pass messages into the manul execution loop. This feels a bit ugly but i don't think it has a big performance cost, so i am happy with it for now.

Other issues:

  • I had issues with using the TestParams and switched to always using the production parameters in tests. This will increase our CI time - but i think not by much as many of our tests already used production parameters. If people think its important i can make a followup putting back the test params - i think we just to add elliptic-curve as a dependency to entropy-protocol.
  • Manul now gives us a SessionReport with more details about protocol errors which are useful for slashing. But we don't yet do anything with it. I propose to do that in a follow up.

@ameba23 ameba23 marked this pull request as draft April 7, 2025 09:52
@ameba23 ameba23 changed the title Bump synedrion to unreleased git version Bump synedrion to 0.3.0 and use manul for protocol session loop Apr 7, 2025
@ameba23
Copy link
Collaborator Author

ameba23 commented Apr 14, 2025

@fjarri @dvdplm i am a bit stuck on how to do the serialization of the protocol messages.

manul::session::Message does not implement serde::Serialize or serde::Deserialize and has private fields preventing me from implementing them myself on a wrapper type.

I have tried my best to copy what you did with the serializer for postcard in the examples, with the serialization format we are using (bincode):

My code:

impl manul::session::SessionParameters for EntropySessionParameters {
type Signer = execute_protocol::PairWrapper;
type Verifier = PartyId;
type Signature = sr25519::Signature;
type Digest = Blake2s256;
type WireFormat = BincodeWireFormat;
}
#[derive(Debug)]
pub struct BincodeWireFormat;
impl manul::session::WireFormat for BincodeWireFormat {
fn serialize<T: Serialize>(value: T) -> Result<Box<[u8]>, manul::protocol::LocalError> {
Ok(bincode::serialize(&value).unwrap().into())
}
type Deserializer<'de> = PersistentDeserializer<BincodeDeserializer<'de>>;
fn deserializer(bytes: &[u8]) -> Self::Deserializer<'_> {
PersistentDeserializer::new(BincodeDeserializer(bincode::de::Deserializer::from_slice(
bytes,
bincode::config::DefaultOptions::new(),
)))
}
}
/// A wrapper for a bincode deserializer.
#[allow(missing_debug_implementations)]
pub struct BincodeDeserializer<'de>(
bincode::de::Deserializer<bincode::de::read::SliceReader<'de>, bincode::config::DefaultOptions>,
);
impl<'de> AsTransientDeserializer<'de> for BincodeDeserializer<'de> {
type Error = bincode::Error;
fn as_transient_deserializer<'a>(
&'a mut self,
) -> impl serde::Deserializer<'de, Error = Self::Error> {
&mut self.0
}
}

Your code: https://github.com/entropyxyz/manul/blob/4f269080775aa6359d0d26d8b56940b4429882f7/manul/src/dev/wire_format.rs#L10-L38

But it seems to me like i don't have a example of how the serialization is used - in the examples messages don't actually go over the wire so they never need to be serialized / deserialized: https://github.com/entropyxyz/manul/blob/4f269080775aa6359d0d26d8b56940b4429882f7/manul/src/dev/run_sync.rs#L192-L221

@fjarri
Copy link
Member

fjarri commented Apr 27, 2025

Should be fixed by entropyxyz/manul#98

@ameba23
Copy link
Collaborator Author

ameba23 commented Apr 28, 2025

Thanks @fjarri that works - as in things now compile (tests not yet passing).

@ameba23
Copy link
Collaborator Author

ameba23 commented Apr 28, 2025

It seems that for both the 'key init' and 'reshare' protocols, messages do get exchanged but then the session hangs before the round is finalized.

Eg: Here is the key init protocol running with two parties (the first stage of a DKG with 3 parties):

2025-04-28T10:58:06.830113Z DEBUG execute_dkg: entropy_protocol::execute_protocol: Executing DKG
2025-04-28T10:58:06.830334Z DEBUG execute_dkg: entropy_protocol::execute_protocol: Executing DKG
2025-04-28T10:58:06.830350Z DEBUG execute_dkg: entropy_protocol::execute_protocol: Executing DKG
2025-04-28T10:58:06.830631Z DEBUG execute_dkg: entropy_protocol::execute_protocol: Session starting
2025-04-28T10:58:06.830646Z DEBUG execute_dkg: manul::session::tokio: PartyId(AccountId32([208, 139, 181, 149, 207, 194, 199, 205, 52, 230, 2, 226, 50, 174, 189, 144, 20, 77, 65, 104, 216, 189, 155, 61, 133, 190, 124, 33, 30, 145, 43, 24])): *** starting round RoundId { round_nums: [1], is_echo: false } ***
2025-04-28T10:58:06.830733Z DEBUG execute_dkg: entropy_protocol::execute_protocol: Session starting
2025-04-28T10:58:06.830745Z DEBUG execute_dkg: manul::session::tokio: PartyId(AccountId32([76, 94, 254, 229, 66, 181, 20, 80, 20, 240, 21, 163, 237, 36, 116, 129, 134, 66, 26, 57, 48, 71, 122, 38, 221, 130, 178, 187, 170, 182, 73, 38])): *** starting round RoundId { round_nums: [1], is_echo: false } ***
2025-04-28T10:58:06.830919Z DEBUG manul::session::tokio: PartyId(AccountId32([208, 139, 181, 149, 207, 194, 199, 205, 52, 230, 2, 226, 50, 174, 189, 144, 20, 77, 65, 104, 216, 189, 155, 61, 133, 190, 124, 33, 30, 145, 43, 24])): Sending a message to PartyId(AccountId32([76, 94, 254, 229, 66, 181, 20, 80, 20, 240, 21, 163, 237, 36, 116, 129, 134, 66, 26, 57, 48, 71, 122, 38, 221, 130, 178, 187, 170, 182, 73, 38]))
2025-04-28T10:58:06.830945Z DEBUG manul::session::tokio: PartyId(AccountId32([76, 94, 254, 229, 66, 181, 20, 80, 20, 240, 21, 163, 237, 36, 116, 129, 134, 66, 26, 57, 48, 71, 122, 38, 221, 130, 178, 187, 170, 182, 73, 38])): Sending a message to PartyId(AccountId32([208, 139, 181, 149, 207, 194, 199, 205, 52, 230, 2, 226, 50, 174, 189, 144, 20, 77, 65, 104, 216, 189, 155, 61, 133, 190, 124, 33, 30, 145, 43, 24]))

At this point it hangs.

@ameba23
Copy link
Collaborator Author

ameba23 commented Apr 29, 2025

entropy-protocol tests now pass - still need to update entropy-tss

@ameba23
Copy link
Collaborator Author

ameba23 commented Apr 30, 2025

Current state - most tests passing - but the entropy-tss jumpstart and reshare tests fail.

use crate::{protocol_message::ProtocolMessage, KeyParams, PartyId};

#[derive(Debug, Error)]
pub enum GenericProtocolError<Res: ProtocolResult> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get rid of this error type and just use ProtocolExecutionErr (below) - as things are simpler now.


/// This is used to run the synedrion protocols - it is mostly copied from the synedrion integration
/// tests
mod synedrion_test_environment {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully we don't need this anymore as we can now use manul::dev::run_sync which gives us the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants