Skip to content

Commit

Permalink
use receipt_id: [u8; 32] for general signature request structs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppca committed Oct 28, 2024
1 parent c93431c commit 04c98a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion chain-signatures/node/src/protocol/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
))
Expand Down
26 changes: 13 additions & 13 deletions chain-signatures/node/src/protocol/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<u8>,
pub payload: Vec<u8>,
}

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(),
Expand Down Expand Up @@ -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<Secp256k1> = PresignOutput {
big_r: (big_r * delta).to_affine(),
Expand Down Expand Up @@ -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,
Expand All @@ -411,7 +411,7 @@ impl SignatureManager {
proposer: self.me,
request,
epsilon,
receipt_id,
receipt_id: receipt_id.0,
entropy,
sign_request_timestamp,
},
Expand All @@ -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,
Expand Down Expand Up @@ -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));
}
};
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 04c98a7

Please sign in to comment.