Skip to content

Commit

Permalink
chore(clippy): fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Jun 17, 2024
1 parent 66684bb commit 716215f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
17 changes: 13 additions & 4 deletions lib/src/builder/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ impl BlockFinalizeStrategy<MemDb> for MemDbBlockFinalizeStrategy {
fn finalize(mut block_builder: BlockBuilder<MemDb>) -> Result<(AlloyConsensusHeader, MptNode)> {
let db: MemDb = block_builder.db.take().expect("DB not initialized");

let mut account_touched = 0;
let mut storage_touched = 0;
#[cfg(feature = "sp1-cycle-tracker")]
{
let mut account_touched = 0;
let mut storage_touched = 0;
}

// apply state updates
let mut state_trie = mem::take(&mut block_builder.input.parent_state_trie);
Expand All @@ -62,7 +65,10 @@ impl BlockFinalizeStrategy<MemDb> for MemDbBlockFinalizeStrategy {
continue;
}

account_touched += 1;
#[cfg(feature = "sp1-cycle-tracker")]
{
account_touched += 1;
}

// otherwise, compute the updated storage root for that account
let state_storage = &account.storage;
Expand All @@ -88,7 +94,10 @@ impl BlockFinalizeStrategy<MemDb> for MemDbBlockFinalizeStrategy {
storage_trie.insert_rlp(&storage_trie_index, *value)?;
}

storage_touched += 1;
#[cfg(feature = "sp1-cycle-tracker")]
{
storage_touched += 1;
}
}

storage_trie.hash()
Expand Down
30 changes: 24 additions & 6 deletions lib/src/builder/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
.map(|bytes| (keccak(&bytes).into(), bytes))
.collect();

let mut account_touched = 0;
let mut storage_touched = 0;
#[cfg(all(
all(target_os = "zkvm", target_vendor = "succinct"),
feature = "sp1-cycle-tracker"
))]
{
let mut account_touched = 0;
let mut storage_touched = 0;
}

// Load account data into db
let mut accounts = HashMap::with_capacity(block_builder.input.parent_storage.len());
Expand All @@ -85,7 +91,13 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
storage_trie.hash()
);
}
account_touched += 1;
#[cfg(all(
all(target_os = "zkvm", target_vendor = "succinct"),
feature = "sp1-cycle-tracker"
))]
{
account_touched += 1;
}

// load the corresponding code
let code_hash = state_account.code_hash;
Expand All @@ -106,7 +118,13 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
.get_rlp(&keccak(slot.to_be_bytes::<32>()))?
.unwrap_or_default();
storage.insert(slot, value);
storage_touched += 1;
#[cfg(all(
all(target_os = "zkvm", target_vendor = "succinct"),
feature = "sp1-cycle-tracker"
))]
{
storage_touched += 1;
}
}

let mem_account = DbAccount {
Expand All @@ -129,8 +147,8 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
feature = "sp1-cycle-tracker"
))]
{
println!("initialize_db Account touch {:?}", account_touched);
println!("initialize_db Storage touch {:?}", storage_touched);
println!("initialize_db Account touch {account_touched:?}");
println!("initialize_db Storage touch {storage_touched:?}");
}

// prepare block hash history
Expand Down
1 change: 1 addition & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ mod time {
}

pub struct CycleTracker {
#[allow(dead_code)]
title: String,
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ProtocolInstance {
let aligned_data_size = (data_size + 3) / 4 * 4;
let layout = Layout::from_size_align(aligned_data_size, 4).unwrap();
// Allocate aligned memory
let raw_ptr = unsafe { alloc(layout) as *mut u8 };
let raw_ptr = unsafe { alloc(layout) };
if raw_ptr.is_null() {
panic!("Failed to allocate memory with aligned pointer");
}
Expand Down
4 changes: 2 additions & 2 deletions provers/sgx/guest/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn recover_signer_unchecked(sig: &[u8; 65], msg: &[u8; 32]) -> Result<Addres
RecoveryId::from_i32(sig[64] as i32 - 27)?,
)?;

let public = SECP256K1.recover_ecdsa(&Message::from_slice(&msg[..32])?, &sig)?;
let public = SECP256K1.recover_ecdsa(&Message::from_digest_slice(&msg[..32])?, &sig)?;
Ok(public_key_to_address(&public))
}

Expand All @@ -34,7 +34,7 @@ pub fn recover_signer_unchecked(sig: &[u8; 65], msg: &[u8; 32]) -> Result<Addres
pub fn sign_message(secret_key: &SecretKey, message: B256) -> Result<[u8; 65], Error> {
let secret = B256::from_slice(&secret_key.secret_bytes()[..]);
let sec = SecretKey::from_slice(secret.as_ref())?;
let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_slice(&message[..])?, &sec);
let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_digest_slice(&message[..])?, &sec);
let (rec_id, data) = s.serialize_compact();
let signature = Signature::from_bytes_and_parity(&data, (rec_id.to_i32() != 0) as u64).unwrap();
Ok(signature.as_bytes())
Expand Down

0 comments on commit 716215f

Please sign in to comment.