Skip to content

Commit

Permalink
Generalize the cached effect hash in coordinator state
Browse files Browse the repository at this point in the history
  • Loading branch information
plaidfinch committed Mar 22, 2024
1 parent 94cd843 commit 8b97a81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 10 additions & 6 deletions crates/custody/src/threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ where
/// interface, but it can also be plugged in with more general backends.
#[async_trait]
pub trait Terminal {
/// Have a user confirm that they want to sign this transaction.
/// Have a user confirm that they want to sign this transaction or other data (e.g. validator
/// definition, validator vote).
///
/// In an actual terminal, this should display the transaction in a human readable
/// In an actual terminal, this should display the data to be signed in a human readable
/// form, and then get feedback from the user.
async fn confirm_request(&self, request: &SigningRequest) -> Result<bool>;

Expand Down Expand Up @@ -587,21 +588,24 @@ mod test {
pre_authorizations: Vec::new(),
})
.await?;
let tx_authorization_data = match authorization_data {
AuthorizationData::Transaction(tx) => tx,
_ => panic!("expected transaction authorization data"),
};
assert_eq!(
plan.effect_hash(&fvk)?,
authorization_data
tx_authorization_data
.effect_hash
.expect("effect hash not present")
);
// The transaction plan only has spends
for (randomizer, sig) in plan
.spend_plans()
.into_iter()
.map(|x| x.randomizer)
.zip(authorization_data.spend_auths)
.zip(tx_authorization_data.spend_auths)
{
fvk.spend_verification_key().randomize(&randomizer).verify(
authorization_data
tx_authorization_data
.effect_hash
.expect("effect hash not present")
.as_bytes(),
Expand Down
16 changes: 13 additions & 3 deletions crates/custody/src/threshold/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,16 @@ pub struct CoordinatorState1 {
pub struct CoordinatorState2 {
request: SigningRequest,
my_round2_reply: FollowerRound2,
effect_hash: EffectHash,
to_be_signed: ToBeSigned,
signing_packages: Vec<frost::SigningPackage>,
}

enum ToBeSigned {
EffectHash(EffectHash),
ValidatorDefinitionBytes(Vec<u8>),
ValidatorVoteBytes(Vec<u8>),
}

pub struct FollowerState {
request: SigningRequest,
nonces: Vec<frost::round1::SigningNonces>,
Expand Down Expand Up @@ -404,7 +410,7 @@ pub fn coordinator_round2(
let state = CoordinatorState2 {
request: state.request,
my_round2_reply,
effect_hash,
to_be_signed: ToBeSigned::EffectHash(effect_hash),
signing_packages,
};
Ok((reply, state))
Expand Down Expand Up @@ -432,9 +438,13 @@ pub fn coordinator_round3(
}
}

// TODO: generalize this to handle the other kinds of signing requests
let SigningRequest::TransactionPlan(plan) = state.request else {
todo!("effect hash for non-transaction requests");
};
let ToBeSigned::EffectHash(effect_hash) = state.to_be_signed else {
todo!("missing effect hash for transaction request");
};

let mut spend_auths = plan
.spend_plans()
Expand All @@ -454,7 +464,7 @@ pub fn coordinator_round3(
let delegator_vote_auths = spend_auths.split_off(plan.spend_plans().count());
Ok(AuthorizationData::Transaction(
TransactionAuthorizationData {
effect_hash: Some(state.effect_hash),
effect_hash: Some(effect_hash),
spend_auths,
delegator_vote_auths,
},
Expand Down

0 comments on commit 8b97a81

Please sign in to comment.