Enforce FROST StateMachine progression via the type system

A comment on the matter was made in 
https://github.com/serai-dex/serai/issues/12. While I do believe the API 
is slightly worse, I appreciate the explicitness.
This commit is contained in:
Luke Parker
2022-06-24 08:40:14 -04:00
parent 462d0e74ce
commit 1caa6a9606
9 changed files with 276 additions and 351 deletions

View File

@@ -1,7 +1,6 @@
use std::sync::Arc;
use async_trait::async_trait;
use rand_core::OsRng;
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar};

View File

@@ -3,7 +3,7 @@ use std::{marker::Send, sync::Arc, collections::HashMap};
use async_trait::async_trait;
use thiserror::Error;
use frost::{Curve, FrostError, MultisigKeys, sign::StateMachine};
use frost::{Curve, FrostError, MultisigKeys, sign::PreprocessMachine};
pub(crate) use monero_serai::frost::Transcript;
@@ -57,7 +57,7 @@ pub trait Coin {
type Output: Output;
type SignableTransaction;
type TransactionMachine: StateMachine<Signature = Self::Transaction>;
type TransactionMachine: PreprocessMachine<Signature = Self::Transaction>;
type Address: Send;

View File

@@ -4,7 +4,7 @@ use rand_core::OsRng;
use transcript::Transcript as TranscriptTrait;
use frost::{Curve, MultisigKeys, sign::StateMachine};
use frost::{Curve, MultisigKeys, sign::{PreprocessMachine, SignMachine, SignatureMachine}};
use crate::{Transcript, CoinError, SignError, Output, Coin, Network};
@@ -344,17 +344,17 @@ impl<D: CoinDb, C: Coin> Wallet<D, C> {
prepared: C::SignableTransaction,
included: Vec<u16>
) -> Result<(Vec<u8>, Vec<<C::Output as Output>::Id>), SignError> {
let mut attempt = self.coin.attempt_send(
let attempt = self.coin.attempt_send(
prepared,
&included
).await.map_err(|e| SignError::CoinError(e))?;
let commitments = network.round(
attempt.preprocess(&mut OsRng).unwrap()
).await.map_err(|e| SignError::NetworkError(e))?;
let shares = network.round(
attempt.sign(commitments, b"").map_err(|e| SignError::FrostError(e))?
).await.map_err(|e| SignError::NetworkError(e))?;
let (attempt, commitments) = attempt.preprocess(&mut OsRng);
let commitments = network.round(commitments).await.map_err(|e| SignError::NetworkError(e))?;
let (attempt, share) = attempt.sign(commitments, b"").map_err(|e| SignError::FrostError(e))?;
let shares = network.round(share).await.map_err(|e| SignError::NetworkError(e))?;
let tx = attempt.complete(shares).map_err(|e| SignError::FrostError(e))?;
self.coin.publish_transaction(&tx).await.map_err(|e| SignError::CoinError(e))