kkrt-labs/kakarot-ssj

dev: use range operator in for loop

Closed this issue · 3 comments

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;
};
SetTrait::from_array(precompile_addresses)
}

In this function, we use a while loop with a manual increment of the counter i.
A more idiomatic approach would be to simply use the range operator documented in the Cairo Book

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a Blockchain Developer

How I plan on tackling this issue

I will:

  • Locate the while loop in the function from the given link.
  • Replace the while loop with the range operator, as documented in the Cairo Book, for a cleaner and more idiomatic approach.
  • Ensure that the modified loop behaves as expected by running existing tests or adding new ones if necessary.

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

My name is Fabricio Robles, I work as a full stack dev since 3 years ago. Also I have been involved in web3 where I have contributed successfully to projects like dojo engine, Concrete and this great project creating some testings. I have experience working with Rust, Cairo, Go, Python and Javascript, I am sure that experience would help me delivering a quality solution for this project

How I plan on tackling this issue

  • I would do a control + find in cairo files searching for while loops
  • Understand the context of those loops and analyze if they can be refactored with new for loop syntax using ranges (for i in 0..N)
  • Apply the refactor
  • Run test suite to make sure everything is working.
  • PR

I estimate this would take me 1 day to complete

superceded by #978