From 04c98a7f5a39cf11a005ff7b3d4038ef229460a6 Mon Sep 17 00:00:00 2001 From: Xiangyi Zheng Date: Mon, 28 Oct 2024 14:27:42 -0700 Subject: [PATCH] use receipt_id: [u8; 32] for general signature request structs --- chain-signatures/node/src/protocol/message.rs | 2 +- .../node/src/protocol/signature.rs | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/chain-signatures/node/src/protocol/message.rs b/chain-signatures/node/src/protocol/message.rs index f6a89666..f9532622 100644 --- a/chain-signatures/node/src/protocol/message.rs +++ b/chain-signatures/node/src/protocol/message.rs @@ -135,7 +135,7 @@ impl MpcMessageQueue { .entry(message.epoch) .or_default() .entry(SignRequestIdentifier::new( - message.receipt_id, + message.receipt_id.0, message.epsilon, message.request.payload, )) diff --git a/chain-signatures/node/src/protocol/signature.rs b/chain-signatures/node/src/protocol/signature.rs index 5584c3a2..a6e32e67 100644 --- a/chain-signatures/node/src/protocol/signature.rs +++ b/chain-signatures/node/src/protocol/signature.rs @@ -149,7 +149,7 @@ pub struct SignatureGenerator { pub presignature_id: PresignatureId, pub request: ContractSignRequest, pub epsilon: Scalar, - pub receipt_id: CryptoHash, + pub receipt_id: [u8; 32], pub entropy: [u8; 32], pub sign_request_timestamp: Instant, pub generator_timestamp: Instant, @@ -166,7 +166,7 @@ impl SignatureGenerator { presignature_id: PresignatureId, request: ContractSignRequest, epsilon: Scalar, - receipt_id: CryptoHash, + receipt_id: [u8; 32], entropy: [u8; 32], sign_request_timestamp: Instant, cfg: &ProtocolConfig, @@ -211,20 +211,20 @@ pub struct GenerationRequest { pub proposer: Participant, pub request: ContractSignRequest, pub epsilon: Scalar, - pub receipt_id: CryptoHash, + pub receipt_id: [u8; 32], pub entropy: [u8; 32], pub sign_request_timestamp: Instant, } #[derive(Debug, Clone, Eq, Hash, PartialEq)] pub struct SignRequestIdentifier { - pub receipt_id: ReceiptId, + pub receipt_id: [u8; 32], pub epsilon: Vec, pub payload: Vec, } impl SignRequestIdentifier { - pub fn new(receipt_id: ReceiptId, epsilon: Scalar, payload: Scalar) -> Self { + pub fn new(receipt_id: [u8; 32], epsilon: Scalar, payload: Scalar) -> Self { Self { receipt_id, epsilon: borsh::to_vec(&SerializableScalar { scalar: epsilon }).unwrap(), @@ -322,7 +322,7 @@ impl SignatureManager { sign_request_timestamp, } = req; let PresignOutput { big_r, k, sigma } = presignature.output; - let delta = derive_delta(receipt_id, entropy, big_r); + let delta = derive_delta(CryptoHash(receipt_id), entropy, big_r); // TODO: Check whether it is okay to use invert_vartime instead let output: PresignOutput = PresignOutput { big_r: (big_r * delta).to_affine(), @@ -394,7 +394,7 @@ impl SignatureManager { cfg: &ProtocolConfig, ) -> Result<(), (Presignature, InitializationError)> { let sign_request_identifier = - SignRequestIdentifier::new(receipt_id, epsilon, request.payload); + SignRequestIdentifier::new(receipt_id.0, epsilon, request.payload); tracing::info!( ?sign_request_identifier, me = ?self.me, @@ -411,7 +411,7 @@ impl SignatureManager { proposer: self.me, request, epsilon, - receipt_id, + receipt_id: receipt_id.0, entropy, sign_request_timestamp, }, @@ -434,7 +434,7 @@ impl SignatureManager { pub fn get_or_generate( &mut self, participants: &Participants, - receipt_id: ReceiptId, + receipt_id: [u8; 32], proposer: Participant, presignature_id: PresignatureId, request: &ContractSignRequest, @@ -487,7 +487,7 @@ impl SignatureManager { Ok(generator) => generator, Err((presignature, err @ InitializationError::BadParameters(_))) => { presignature_manager.insert_mine(presignature); - tracing::warn!(%receipt_id, presignature_id, ?err, "failed to start signature generation"); + tracing::warn!(sign_request = ?sign_request_identifier, presignature_id, ?err, "failed to start signature generation"); return Err(GenerationError::CaitSithInitializationError(err)); } }; @@ -553,7 +553,7 @@ impl SignatureManager { messages.push(( *p, SignatureMessage { - receipt_id: sign_request_identifier.receipt_id, + receipt_id: CryptoHash(sign_request_identifier.receipt_id), proposer: generator.proposer, presignature_id: generator.presignature_id, request: generator.request.clone(), @@ -570,7 +570,7 @@ impl SignatureManager { Action::SendPrivate(p, data) => messages.push(( p, SignatureMessage { - receipt_id: sign_request_identifier.receipt_id, + receipt_id: CryptoHash(sign_request_identifier.receipt_id), proposer: generator.proposer, presignature_id: generator.presignature_id, request: generator.request.clone(), @@ -598,7 +598,7 @@ impl SignatureManager { }; if generator.proposer == self.me { self.signatures - .push(ToPublish::new(sign_request_identifier.receipt_id, request, generator.sign_request_timestamp, output)); + .push(ToPublish::new(CryptoHash(sign_request_identifier.receipt_id), request, generator.sign_request_timestamp, output)); } // Do not retain the protocol return false;