mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Make a trait out of sign::StateMachine for more complex Transaction flows
This commit is contained in:
@@ -7,7 +7,7 @@ use monero_serai::{random_scalar, Commitment, frost::MultisigError, key_image, c
|
||||
#[cfg(feature = "multisig")]
|
||||
mod frost;
|
||||
#[cfg(feature = "multisig")]
|
||||
use crate::frost::{generate_keys, sign};
|
||||
use crate::frost::{THRESHOLD, generate_keys, sign};
|
||||
|
||||
const RING_INDEX: u8 = 3;
|
||||
const RING_LEN: u64 = 11;
|
||||
@@ -86,17 +86,21 @@ fn test_multisig() -> Result<(), MultisigError> {
|
||||
ring.push([&dest * &ED25519_BASEPOINT_TABLE, Commitment::new(mask, amount).calculate()]);
|
||||
}
|
||||
|
||||
let mut algorithms = Vec::with_capacity(t);
|
||||
for _ in 1 ..= t {
|
||||
algorithms.push(
|
||||
clsag::InputMultisig::new(
|
||||
clsag::Input::new(ring.clone(), RING_INDEX, Commitment::new(randomness, AMOUNT)).unwrap(),
|
||||
Msg(msg)
|
||||
let mut machines = Vec::with_capacity(t);
|
||||
for i in 1 ..= t {
|
||||
machines.push(
|
||||
sign::AlgorithmMachine::new(
|
||||
clsag::InputMultisig::new(
|
||||
clsag::Input::new(ring.clone(), RING_INDEX, Commitment::new(randomness, AMOUNT)).unwrap(),
|
||||
Msg(msg)
|
||||
).unwrap(),
|
||||
keys[i - 1].clone(),
|
||||
&(1 ..= THRESHOLD).collect::<Vec<usize>>()
|
||||
).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
let mut signatures = sign(algorithms, keys);
|
||||
let mut signatures = sign(&mut machines, keys);
|
||||
let signature = signatures.swap_remove(0);
|
||||
for s in 0 .. (t - 1) {
|
||||
// Verify the commitments and the non-decoy s scalar are identical to every other signature
|
||||
|
||||
@@ -8,7 +8,7 @@ use rand::rngs::OsRng;
|
||||
use ff::Field;
|
||||
use dalek_ff_group::{ED25519_BASEPOINT_TABLE, Scalar, EdwardsPoint};
|
||||
|
||||
use frost::{
|
||||
pub use frost::{
|
||||
FrostError, MultisigParams, MultisigKeys,
|
||||
key_gen, algorithm::Algorithm, sign::{self, lagrange}
|
||||
};
|
||||
@@ -113,26 +113,16 @@ pub fn generate_keys() -> (Vec<Rc<MultisigKeys<Ed25519>>>, Scalar) {
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // Currently has some false positive
|
||||
pub fn sign<S, A: Algorithm<Ed25519, Signature = S>>(
|
||||
algorithms: Vec<A>,
|
||||
pub fn sign<S, M: sign::StateMachine<Signature = S>>(
|
||||
machines: &mut Vec<M>,
|
||||
keys: Vec<Rc<MultisigKeys<Ed25519>>>
|
||||
) -> Vec<S> {
|
||||
assert!(algorithms.len() >= THRESHOLD);
|
||||
assert!(keys.len() >= algorithms.len());
|
||||
assert!(machines.len() >= THRESHOLD);
|
||||
assert!(keys.len() >= machines.len());
|
||||
|
||||
let mut machines = vec![];
|
||||
let mut commitments = Vec::with_capacity(PARTICIPANTS + 1);
|
||||
commitments.resize(PARTICIPANTS + 1, None);
|
||||
for i in 1 ..= THRESHOLD {
|
||||
machines.push(
|
||||
sign::StateMachine::new(
|
||||
sign::Params::new(
|
||||
algorithms[i - 1].clone(),
|
||||
keys[i - 1].clone(),
|
||||
&(1 ..= THRESHOLD).collect::<Vec<usize>>()
|
||||
).unwrap()
|
||||
)
|
||||
);
|
||||
commitments[i] = Some(machines[i - 1].preprocess(&mut OsRng).unwrap());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user