From 595cd6d4040e247858acc1159dc20f5ab9a38dcb Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 17 Apr 2023 02:09:29 -0400 Subject: [PATCH] Rename transaction file to tributary, add function for genesis --- coordinator/src/tests/mod.rs | 2 +- .../src/tests/{transaction.rs => tributary.rs} | 2 +- .../src/{transaction.rs => tributary.rs} | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) rename coordinator/src/tests/{transaction.rs => tributary.rs} (97%) rename coordinator/src/{transaction.rs => tributary.rs} (91%) diff --git a/coordinator/src/tests/mod.rs b/coordinator/src/tests/mod.rs index 8d760e2a..a21e73aa 100644 --- a/coordinator/src/tests/mod.rs +++ b/coordinator/src/tests/mod.rs @@ -1 +1 @@ -mod transaction; +mod tributary; diff --git a/coordinator/src/tests/transaction.rs b/coordinator/src/tests/tributary.rs similarity index 97% rename from coordinator/src/tests/transaction.rs rename to coordinator/src/tests/tributary.rs index aa6882ae..21e5b87e 100644 --- a/coordinator/src/tests/transaction.rs +++ b/coordinator/src/tests/tributary.rs @@ -7,7 +7,7 @@ use frost::Participant; use tributary::{ReadWrite, tests::random_signed}; -use crate::transaction::{SignData, Transaction}; +use crate::tributary::{SignData, Transaction}; fn random_u32(rng: &mut R) -> u32 { u32::try_from(rng.next_u64() >> 32).unwrap() diff --git a/coordinator/src/transaction.rs b/coordinator/src/tributary.rs similarity index 91% rename from coordinator/src/transaction.rs rename to coordinator/src/tributary.rs index cc418a79..9618bb15 100644 --- a/coordinator/src/transaction.rs +++ b/coordinator/src/tributary.rs @@ -1,14 +1,29 @@ use std::{io, collections::HashMap}; use blake2::{Digest, Blake2s256}; +use transcript::{Transcript, RecommendedTranscript}; use frost::Participant; +use serai_client::validator_sets::primitives::ValidatorSet; + #[rustfmt::skip] use tributary::{ - ReadWrite, Signed, TransactionError, TransactionKind, Transaction as TransactionTrait + ReadWrite, Signed, TransactionError, TransactionKind, Transaction as TransactionTrait, }; +pub fn genesis(serai_block: [u8; 32], set: ValidatorSet) -> [u8; 32] { + // Calculate the genesis for this Tributary + let mut genesis = RecommendedTranscript::new(b"Serai Tributary Genesis"); + // This locks it to a specific Serai chain + genesis.append_message(b"serai_block", serai_block); + genesis.append_message(b"session", set.session.0.to_le_bytes()); + genesis.append_message(b"network", set.network.0.to_le_bytes()); + let genesis = genesis.challenge(b"genesis"); + let genesis_ref: &[u8] = genesis.as_ref(); + genesis_ref[.. 32].try_into().unwrap() +} + #[derive(Clone, PartialEq, Eq, Debug)] pub struct SignData { pub plan: [u8; 32],