Skip to content

Commit

Permalink
Improve get_descriptor() (#380)
Browse files Browse the repository at this point in the history
* Fix log in get_descriptor

* Change formatting

* Apply comments

* Remove clones in get_descriptor
  • Loading branch information
LindaGuiga authored Jul 11, 2024
1 parent 288828a commit 312cb60
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions zero_bin/ops/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,20 @@ struct SegmentProofSpan {
impl SegmentProofSpan {
/// Get a unique id for the transaction proof.
fn get_id(ir: &GenerationInputs, segment_index: usize) -> String {
format!(
"b{} - {}_{} ({})",
ir.block_metadata.block_number,
ir.txn_number_before,
ir.txn_number_before + ir.signed_txns.len(),
segment_index
)
if ir.signed_txns.len() == 1 {
format!(
"b{} - {} ({})",
ir.block_metadata.block_number, ir.txn_number_before, segment_index
)
} else {
format!(
"b{} - {}_{} ({})",
ir.block_metadata.block_number,
ir.txn_number_before,
ir.txn_number_before + ir.signed_txns.len(),
segment_index
)
}
}

/// Get a textual descriptor for the transaction proof.
Expand All @@ -132,18 +139,25 @@ impl SegmentProofSpan {
fn get_descriptor(ir: &GenerationInputs) -> String {
if ir.signed_txns.is_empty() {
"Dummy".to_string()
} else if ir.signed_txns.len() == 1 {
format!(
"{:x?}",
u64::from_be_bytes(keccak(&ir.signed_txns[0][..])[0..8].try_into().unwrap())
)
} else {
let first_encoding: [u8; 8] =
keccak(ir.signed_txns[0].clone())[..8].try_into().unwrap();
let last_encoding: [u8; 8] = keccak(
ir.signed_txns
.last()
.expect("the vector of transactions is not empty")
.clone(),
)[..8]
.try_into()
.unwrap();
format!("{:x?}..{:x?}", first_encoding, last_encoding)
let first_encoding =
u64::from_be_bytes(keccak(&ir.signed_txns[0][..])[0..8].try_into().unwrap());
let last_encoding = u64::from_be_bytes(
keccak(
ir.signed_txns
.last()
.expect("the vector of transactions is not empty"),
)[0..8]
.try_into()
.unwrap(),
);

format!("[0x{:x?}..0x{:x?}]", first_encoding, last_encoding)
}
}

Expand Down

0 comments on commit 312cb60

Please sign in to comment.