Skip to content

Commit 9732df2

Browse files
Apply suggestions from code review
Co-authored-by: iquerejeta <[email protected]>
1 parent a308e49 commit 9732df2

File tree

3 files changed

+13
-32
lines changed

3 files changed

+13
-32
lines changed

mithril-core/src/error.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,6 @@ pub enum RegisterError {
131131
UnregisteredInitializer,
132132
}
133133

134-
// impl From<RegisterError> for StmSignatureError {
135-
// fn from(e: RegisterError) -> Self {
136-
// match e {
137-
// RegisterError::SerializationError => Self::SerializationError,
138-
// RegisterError::KeyInvalid(e) => Self::IvkInvalid(e.vk),
139-
// RegisterError::KeyRegistered(_) => unreachable!(),
140-
// RegisterError::UnregisteredInitializer => unreachable!(),
141-
// }
142-
// }
143-
// }
144-
145134
impl<D: Digest + FixedOutput> From<MerkleTreeError<D>> for StmAggregateSignatureError<D> {
146135
fn from(e: MerkleTreeError<D>) -> Self {
147136
match e {

mithril-core/src/merkle_tree.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl<D: Digest + FixedOutput> BatchPath<D> {
173173
}
174174

175175
/// Try to convert a byte string into a `BatchPath`.
176+
// todo: We should not panic if the size of the slice is invalid (I believe `bytes[offset + i * 8..offset + (i + 1) * 8]` will panic if bytes is not large enough.
176177
pub fn from_bytes(bytes: &[u8]) -> Result<Self, MerkleTreeError<D>> {
177178
let mut u64_bytes = [0u8; 8];
178179
u64_bytes.copy_from_slice(&bytes[..8]);
@@ -268,6 +269,7 @@ impl<D: Clone + Digest> MerkleTreeCommitmentBatchCompat<D> {
268269
/// Returns an error if the proof is invalid.
269270
// todo: Update doc.
270271
// todo: Simplify the algorithm.
272+
// todo: Maybe we want more granular errors, rather than only `BatchPathInvalid`
271273
pub fn check(
272274
&self,
273275
batch_val: &Vec<MTLeaf>,
@@ -670,25 +672,22 @@ mod tests {
670672
fn test_create_batch_proof((t, values) in arb_tree(30)) {
671673
let mut mt_index_list :Vec<usize> = Vec::new();
672674
for (i, _v) in values.iter().enumerate() {
673-
let ind = Some(i as usize);
674-
mt_index_list.push(ind.unwrap());
675+
mt_index_list.push(i);
675676
}
676677
mt_index_list.sort_unstable();
677-
let batch_proof = Some(t.get_batched_path(mt_index_list));
678-
assert!(t.to_commitment_batch_compat().check(&values, &batch_proof.unwrap()).is_ok());
678+
let batch_proof = t.get_batched_path(mt_index_list);
679+
assert!(t.to_commitment_batch_compat().check(&values, &batch_proof).is_ok());
679680
}
680681

681682
#[test]
682683
fn test_bytes_batch_path((t, values) in arb_tree(30)) {
683684
let mut mt_index_list :Vec<usize> = Vec::new();
684685
for (i, _v) in values.iter().enumerate() {
685-
let ind = Some(i as usize);
686-
mt_index_list.push(ind.unwrap());
686+
mt_index_list.push(i);
687687
}
688688
mt_index_list.sort_unstable();
689689

690-
let batch_proof = Some(t.get_batched_path(mt_index_list));
691-
let bp = batch_proof.unwrap();
690+
let bp = t.get_batched_path(mt_index_list);
692691

693692
let bytes = &bp.to_bytes();
694693
let deserialized = BatchPath::from_bytes(bytes).unwrap();
@@ -752,14 +751,8 @@ mod tests {
752751
(values, proof) in values_with_invalid_proof(10)
753752
) {
754753
let t = MerkleTree::<Blake2b<U32>>::create(&values[1..]);
755-
let mut indices = Vec::with_capacity(values.len() / 2);
756-
let mut batch_values = Vec::with_capacity(values.len() / 2);
757-
758-
for _j in 0..values.len() / 2 {
759-
let ind = i % (values.len() - 1);
760-
indices.push(ind);
761-
batch_values.push(values[ind]);
762-
}
754+
let indices = vec![i % (values.len() - 1); values.len() / 2];
755+
let batch_values = vec![values[i % (values.len() - 1)]; values.len() / 2];
763756
let path = BatchPath{values: proof
764757
.iter()
765758
.map(|x| Blake2b::<U32>::digest(x).to_vec())

mithril-core/src/stm.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<D: Digest + Clone + FixedOutput> StmClerk<D> {
427427
/// Aggregate a set of signatures for their corresponding indices.
428428
///
429429
/// This function first deduplicates the repeated signatures, and if there are enough signatures, it collects the merkle tree indexes of unique signatures.
430-
/// The list of merkle tree indexes is used to create a batch proof to be checked in verify aggregate.
430+
/// The list of merkle tree indexes is used to create a batch proof, to prove that all signatures are from eligible signers.
431431
///
432432
/// It returns an instance of `StmAggrSig`.
433433
pub fn aggregate(
@@ -622,14 +622,14 @@ impl StmSig {
622622
let sigma = Signature::from_bytes(&bytes[offset + 96..offset + 144])?;
623623

624624
u64_bytes.copy_from_slice(&bytes[offset + 144..offset + 152]);
625-
let mt_index = u64::from_be_bytes(u64_bytes);
625+
let signer_index = u64::from_be_bytes(u64_bytes);
626626

627627
Ok(StmSig {
628628
sigma,
629629
pk,
630630
stake,
631631
indexes,
632-
signer_index: mt_index,
632+
signer_index,
633633
})
634634
}
635635

@@ -1176,8 +1176,7 @@ mod tests {
11761176
})
11771177
}
11781178
#[test]
1179-
fn test_invalid_proof_path(tc in arb_proof_setup(10), _i in any::<usize>()) {
1180-
let _n = tc.n;
1179+
fn test_invalid_proof_path(tc in arb_proof_setup(10)) {
11811180
with_proof_mod(tc, |aggr, _, _msg| {
11821181
let p = aggr.batch_proof.clone();
11831182
let mut index_list = p.indices.clone();

0 commit comments

Comments
 (0)