Skip to content

Commit 85c2e95

Browse files
committed
basic signer uncomplete
1 parent 5b71041 commit 85c2e95

File tree

1 file changed

+20
-12
lines changed
  • mithril-stm/src/protocol/participant

1 file changed

+20
-12
lines changed

mithril-stm/src/protocol/participant/signer.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Signer<D: Digest> {
2222
params: Parameters,
2323
sk: BlsSigningKey,
2424
vk: VerificationKey,
25-
closed_reg: Option<ClosedKeyRegistration<D>>,
25+
closed_reg: ClosedKeyRegistration<D>,
2626
}
2727

2828
impl<D: Clone + Digest + FixedOutput> Signer<D> {
@@ -41,7 +41,7 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
4141
params,
4242
sk,
4343
vk,
44-
closed_reg: Some(closed_reg),
44+
closed_reg,
4545
}
4646
}
4747

@@ -72,7 +72,7 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
7272
params,
7373
sk,
7474
vk,
75-
closed_reg: None,
75+
closed_reg: todo!(),
7676
}
7777
}
7878

@@ -95,18 +95,26 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
9595
/// If it wins at least one lottery, it stores the signer's merkle tree index. The proof of membership
9696
/// will be handled by the aggregator.
9797
pub fn sign(&self, msg: &[u8]) -> Option<SingleSignature> {
98-
let closed_reg = self.closed_reg.as_ref().expect("Closed registration not found! Cannot produce SingleSignatures. Use core_sign to produce core signatures (not valid for an StmCertificate).");
99-
let msgp = closed_reg
98+
// let closed_reg = self.closed_reg.as_ref().expect("Closed registration not found! Cannot produce SingleSignatures. Use core_sign to produce core signatures (not valid for an StmCertificate).");
99+
let msgp = self
100+
.closed_reg
100101
.merkle_tree
101102
.to_merkle_tree_batch_commitment()
102103
.concatenate_with_message(msg);
103-
let signature = self.basic_sign(&msgp, closed_reg.total_stake)?;
104+
let sigma = self.sk.sign(&msgp);
104105

105-
Some(SingleSignature {
106-
sigma: signature.sigma,
107-
signer_index: self.signer_index,
108-
indexes: signature.indexes,
109-
})
106+
let indexes = self.check_lottery(&msgp, &sigma, self.closed_reg.total_stake);
107+
108+
// let signature = self.basic_sign(&msgp, closed_reg.total_stake)?;
109+
if !indexes.is_empty() {
110+
Some(SingleSignature {
111+
sigma,
112+
signer_index: self.signer_index,
113+
indexes,
114+
})
115+
} else {
116+
None
117+
}
110118
}
111119

112120
/// Extract the verification key.
@@ -184,7 +192,7 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
184192

185193
/// Get closed key registration
186194
pub(crate) fn get_closed_key_registration(&self) -> Option<ClosedKeyRegistration<D>> {
187-
self.closed_reg.clone()
195+
Some(self.closed_reg.clone())
188196
}
189197

190198
/// Get closed key registration

0 commit comments

Comments
 (0)