Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Clean commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrobles92 committed Sep 28, 2024
1 parent 53777d7 commit 4ad5c75
Show file tree
Hide file tree
Showing 23 changed files with 1 addition and 410 deletions.
12 changes: 0 additions & 12 deletions crates/contracts/src/storage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ impl StoreBytecode of Store<StorageBytecode> {
// afterwards.
let base: felt252 = 0;
let mut packed_bytecode = array![];
// let mut i = 0;
// while i != (chunks_count + 1) {
// let storage_address: StorageAddress = (base + i.into()).try_into().unwrap();
// let chunk = storage_read_syscall(address_domain, storage_address).unwrap();
// packed_bytecode.append(chunk);
// i += 1;
// };
for i in 0..chunks_count + 1 {
let storage_address: StorageAddress = (base + i.into()).try_into().unwrap();
let chunk = storage_read_syscall(address_domain, storage_address).unwrap();
Expand Down Expand Up @@ -136,11 +129,6 @@ mod tests {
fn test_store_bytecode_multiple_chunks() {
let mut state = account_contract_state();
let mut bytecode_array = array![];
// let mut i = 0;
// while i != 100 {
// bytecode_array.append(i);
// i += 1;
// };
for i in 0..100_u8 {
bytecode_array.append(i);
};
Expand Down
14 changes: 0 additions & 14 deletions crates/evm/src/backend/starknet_backend.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ pub fn fetch_balance(self: @Address) -> u256 {
/// `Ok(())` if the commit was successful, otherwise an `EVMError`.
fn commit_accounts(ref state: State) -> Result<(), EVMError> {
let mut account_keys = state.accounts.keyset.to_span();
// while let Option::Some(evm_address) = account_keys.pop_front() {
// let account = state.accounts.changes.get(*evm_address).deref();
// commit_account(@account, ref state);
// };
for evm_address in account_keys {
let account = state.accounts.changes.get(*evm_address).deref();
commit_account(@account, ref state);
Expand Down Expand Up @@ -235,16 +231,6 @@ fn emit_events(ref self: State) -> Result<(), EVMError> {
/// commit_storage MUST be called after commit_accounts.
fn commit_storage(ref self: State) -> Result<(), EVMError> {
let mut storage_keys = self.accounts_storage.keyset.to_span();
// while let Option::Some(state_key) = storage_keys.pop_front() {
// let (evm_address, key, value) = self.accounts_storage.changes.get(*state_key).deref();
// let mut account = self.get_account(evm_address);
// // @dev: EIP-6780 - If selfdestruct on an account created, dont commit data
// if account.is_selfdestruct() && account.is_created() {
// continue;
// }
// IAccountDispatcher { contract_address: account.starknet_address() }
// .write_storage(key, value);
// };
for state_key in storage_keys {
let (evm_address, key, value) = self.accounts_storage.changes.get(*state_key).deref();
let mut account = self.get_account(evm_address);
Expand Down
10 changes: 0 additions & 10 deletions crates/evm/src/instructions/duplication_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,13 @@ mod tests {
return;
}

// while idx != to {
// assert(stack.peek_at(idx).unwrap() == 0x00, 'should be zero');
// idx += 1;
// };

for idx in from..to {
assert(stack.peek_at(idx).unwrap() == 0x00, 'should be zero');
};
}

// push `n` number of `0x0` to the stack
fn push_zeros(ref stack: Stack, n: u8) {
// let mut i = 0;
// while i != n {
// stack.push(0x0).unwrap();
// i += 1;
// }
for _ in 0..n {
stack.push(0x0).unwrap();
};
Expand Down
31 changes: 0 additions & 31 deletions crates/evm/src/instructions/environmental_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ pub impl EnvironmentInformationImpl of EnvironmentInformationTrait {

// Fill the rest of the data to load with zeros
// TODO: optimize once we have dw-based exponentiation
// let mut i = 32 - bytes_len;
// while i != 0 {
// data_to_load *= 256;
// i -= 1;
// };
for _ in 0..32 - bytes_len {
data_to_load *= 256;
};
Expand Down Expand Up @@ -655,21 +650,6 @@ mod tests {
// Memory initialization with a value to verify that if the offset + size is out of the
// bound bytes, 0's have been copied.
// Otherwise, the memory value would be 0, and we wouldn't be able to check it.
// let mut i = 0;
// while i != (size / 32) + 1 {
// vm
// .memory
// .store(
// 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
// dest_offset + (i * 32)
// );

// let initial: u256 = vm.memory.load_internal(dest_offset + (i * 32)).into();

// assert_eq!(initial, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);

// i += 1;
// };
for i in 0..(size / 32) + 1 {
vm
.memory
Expand Down Expand Up @@ -790,17 +770,6 @@ mod tests {
let result: u256 = vm.memory.load_internal(dest_offset).into();
let mut results: Array<u8> = u256_to_bytes_array(result);

// let mut i = 0;
// while i != size {
// // For out of bound bytes, 0s will be copied.
// if (i + offset >= bytecode.len()) {
// assert_eq!(*results[i], 0);
// } else {
// assert_eq!(*results[i], *bytecode[i + offset]);
// }

// i += 1;
// };
for i in 0..size {
// For out of bound bytes, 0s will be copied.
if (i + offset >= bytecode.len()) {
Expand Down
4 changes: 0 additions & 4 deletions crates/evm/src/instructions/push_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,6 @@ mod tests {
fn get_n_0xFF(mut n: u8) -> Span<u8> {
let mut array: Array<u8> = ArrayTrait::new();
array.append(0x00);
// while n != 0 {
// array.append(0xFF);
// n -= 1;
// };
for _ in 0..n {
array.append(0xFF);
};
Expand Down
11 changes: 0 additions & 11 deletions crates/evm/src/instructions/sha3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,6 @@ fn compute_memory_words_amount(size: u32, offset: u32, mem_len: u32) -> (u32, u3
fn fill_array_with_memory_words(
ref self: VM, ref to_hash: Array<u64>, mut offset: u32, mut amount: u32
) -> u32 {
// while amount != 0 {
// let loaded = self.memory.load(offset);
// let ((high_h, low_h), (high_l, low_l)) = loaded.split_into_u64_le();
// to_hash.append(low_h);
// to_hash.append(high_h);
// to_hash.append(low_l);
// to_hash.append(high_l);

// offset += 32;
// amount -= 1;
// };
for _ in 0..amount {
let loaded = self.memory.load(offset);
let ((high_h, low_h), (high_l, low_l)) = loaded.split_into_u64_le();
Expand Down
11 changes: 0 additions & 11 deletions crates/evm/src/memory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,6 @@ pub(crate) impl InternalMemoryMethods of InternalMemoryTrait {
fn load_aligned_words(
ref self: Memory, mut chunk_index: usize, final_chunk: usize, ref elements: Array<u8>
) {
// while chunk_index != final_chunk {
// let value = self.items.get(chunk_index.into());
// // Pushes 16 items to `elements`
// helpers::split_word_128(value.into(), ref elements);
// chunk_index += 1;
// }
for i in chunk_index..final_chunk {
let value = self.items.get(i.into());
// Pushes 16 items to `elements`
Expand Down Expand Up @@ -815,11 +809,6 @@ mod tests {
memory.load_n_internal(16, ref results, 0);

assert(results.len() == 16, 'error');
// let mut i = 0;
// while i != results.len() {
// assert(*results[i] == 0xFF, 'byte value loaded not correct');
// i += 1;
// }
for result in results {
assert(result == 0xFF, 'byte value loaded not correct');
}
Expand Down
6 changes: 0 additions & 6 deletions crates/evm/src/precompiles.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ pub const FIRST_ROLLUP_PRECOMPILE_ADDRESS: u256 = 0x100;
/// * `Set<EthAddress>` - A set containing all Ethereum precompile addresses.
pub fn eth_precompile_addresses() -> Set<EthAddress> {
let mut precompile_addresses: Array<EthAddress> = array![];
//TODO(2.8) use range operator
// let mut i = FIRST_ETHEREUM_PRECOMPILE_ADDRESS;
// while i <= LAST_ETHEREUM_PRECOMPILE_ADDRESS {
// precompile_addresses.append(i.try_into().unwrap());
// i = i + 1;
// };
for i in FIRST_ETHEREUM_PRECOMPILE_ADDRESS..LAST_ETHEREUM_PRECOMPILE_ADDRESS + 0x01 {
precompile_addresses.append(i.try_into().unwrap());
};
Expand Down
21 changes: 0 additions & 21 deletions crates/evm/src/precompiles/blake2f.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,14 @@ pub impl Blake2f of Precompile {
let mut h: Array<u64> = Default::default();
let mut m: Array<u64> = Default::default();

// let mut i = 0;
let mut pos = 4;
// while i != 8 {
// // safe unwrap, because we have made sure of the input length to be 213
// h.append(input.slice(pos, 8).from_le_bytes().unwrap());
// i += 1;
// pos += 8;
// };
for _ in 0..8_u8 {
// safe unwrap, because we have made sure of the input length to be 213
h.append(input.slice(pos, 8).from_le_bytes().unwrap());
pos += 8;
};

// let mut i = 0;
let mut pos = 68;
// while i != 16 {
// // safe unwrap, because we have made sure of the input length to be 213
// m.append(input.slice(pos, 8).from_le_bytes().unwrap());
// i += 1;
// pos += 8;
// };
for _ in 0..16_u8 {
// safe unwrap, because we have made sure of the input length to be 213
m.append(input.slice(pos, 8).from_le_bytes().unwrap());
Expand All @@ -78,13 +64,6 @@ pub impl Blake2f of Precompile {

let mut return_data: Array<u8> = Default::default();

// let mut i = 0;
// while i != res.len() {
// let bytes = (*res[i]).to_le_bytes_padded();
// return_data.append_span(bytes);

// i += 1;
// };
for result in res {
let bytes = (*result).to_le_bytes_padded();
return_data.append_span(bytes);
Expand Down
11 changes: 0 additions & 11 deletions crates/evm/src/precompiles/ec_operations/ec_mul.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,6 @@ fn get_bits_little(s: u256) -> Array<felt252> {
fn ec_mul_inner(pt: (u384, u384), mut bits: Array<felt252>) -> Option<(u384, u384)> {
let (mut temp_x, mut temp_y) = pt;
let mut result: Option<(u384, u384)> = Option::None;
// while let Option::Some(bit) = bits.pop_front() {
// if bit != 0 {
// match result {
// Option::Some((xr, yr)) => result = ec_safe_add(temp_x, temp_y, xr, yr),
// Option::None => result = Option::Some((temp_x, temp_y)),
// };
// };
// let (_temp_x, _temp_y) = double_ec_point_unchecked(temp_x, temp_y);
// temp_x = _temp_x;
// temp_y = _temp_y;
// };
for bit in bits {
if bit != 0 {
match result {
Expand Down
9 changes: 0 additions & 9 deletions crates/evm/src/stack.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ impl StackImpl of StackTrait {
fn pop_n(ref self: Stack, mut n: usize) -> Result<Array<u256>, EVMError> {
ensure(!(n > self.len()), EVMError::StackUnderflow)?;
let mut popped_items = ArrayTrait::<u256>::new();
// while n != 0 {
// popped_items.append(self.pop().unwrap());
// n -= 1;
// };
for _ in 0..n {
popped_items.append(self.pop().unwrap());
};
Expand Down Expand Up @@ -349,13 +345,8 @@ mod tests {
fn test_should_fail_when_overflow() {
// Given
let mut stack = StackTrait::new();
// let mut i = 0;

// When
// while i != constants::STACK_MAX_DEPTH {
// i += 1;
// stack.push(1).unwrap();
// };
for _ in 0..constants::STACK_MAX_DEPTH {
stack.push(1).unwrap();
};
Expand Down
4 changes: 0 additions & 4 deletions crates/evm/src/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ impl StateChangeLogImpl<T, +Drop<T>, +Copy<T>> of StateChangeLogTrait<T> {
fn clone(ref self: StateChangeLog<T>) -> StateChangeLog<T> {
let mut cloned_changes = Default::default();
let mut keyset_span = self.keyset.to_span();
// while let Option::Some(key) = keyset_span.pop_front() {
// let value = self.changes.get(*key).deref();
// cloned_changes.insert(*key, NullableTrait::new(value));
// };
for key in keyset_span {
let value = self.changes.get(*key).deref();
cloned_changes.insert(*key, NullableTrait::new(value));
Expand Down
56 changes: 1 addition & 55 deletions crates/snforge_utils/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -216,36 +216,7 @@ pub mod snforge_utils {
fn build(self: @EventsFilter) -> ContractEvents {
let events = (*self.events.events).span();
let mut filtered_events = array![];
// let mut i = 0;

// while i < events.len() {
// let (from, event) = events.at(i).clone();
// let mut include = true;

// if let Option::Some(addr) = self.contract_address {
// if from != *addr {
// include = false;
// }
// }

// if include && self.key_filter.is_some() {
// if !(event.keys.span() == (*self.key_filter).unwrap()) {
// include = false;
// }
// }

// if include && self.data_filter.is_some() {
// if !event.data.includes((*self.data_filter).unwrap()) {
// include = false;
// }
// }

// if include {
// filtered_events.append(event.clone());
// }

// i += 1;
// };

for i in 0..events.len() {
let (from, event) = events.at(i).clone();
let mut include = true;
Expand Down Expand Up @@ -294,16 +265,7 @@ pub mod snforge_utils {
let mut expected_data = array![];
event.append_keys_and_data(ref expected_keys, ref expected_data);

// let mut i = 0;
let mut found = false;
// while i < self.events.len() {
// let event = self.events.at(i);
// if event.keys == @expected_keys && event.data == @expected_data {
// found = true;
// break;
// }
// i += 1;
// };
for i in 0..self.events.len() {
let event = self.events.at(i);
if event.keys == @expected_keys && event.data == @expected_data {
Expand All @@ -322,15 +284,6 @@ pub mod snforge_utils {
let mut expected_data = array![];
event.append_keys_and_data(ref expected_keys, ref expected_data);

// let mut i = 0;
// while i < self.events.len() {
// let event = self.events.at(i);
// assert(
// event.keys != @expected_keys || event.data != @expected_data,
// 'Unexpected event was emitted'
// );
// i += 1;
// };
for i in 0..self.events.len() {
let event = self.events.at(i);
assert(
Expand All @@ -345,13 +298,6 @@ pub mod snforge_utils {
pub fn store_evm(target: Address, evm_key: u256, evm_value: u256) {
let storage_address = compute_storage_key(target.evm, evm_key);
let serialized_value = [evm_value.low.into(), evm_value.high.into()].span();
// let mut offset: usize = 0;
// while offset != serialized_value.len() {
// store_felt252(
// target.starknet, storage_address + offset.into(), *serialized_value.at(offset)
// );
// offset += 1;
// }
for offset in 0..serialized_value.len() {
store_felt252(
target.starknet, storage_address + offset.into(), *serialized_value.at(offset)
Expand Down
5 changes: 0 additions & 5 deletions crates/utils/src/crypto/blake2_compress.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ fn rotate_right(value: u64, n: u32) -> u64 {
/// updated state vector
pub fn compress(rounds: usize, h: Span<u64>, m: Span<u64>, t: Span<u64>, f: bool) -> Span<u64> {
let mut v = VecTrait::<Felt252Vec, u64>::new();
// let mut i = 0;
// while i != 16 {
// v.push(0);
// i += 1;
// };
for _ in 0..16_u8 {
v.push(0);
};
Expand Down
Loading

0 comments on commit 4ad5c75

Please sign in to comment.