starknet-devnet-rs icon indicating copy to clipboard operation
starknet-devnet-rs copied to clipboard

Remove Copy trait from Felt

Open marioiordanov opened this issue 1 year ago • 12 comments

Copy trait must be removed from

#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
pub struct Felt(pub(crate) [u8; 32]);

marioiordanov avatar Feb 12 '24 09:02 marioiordanov

What is the motivation for this? I see that FieldElement of starknet-rs has Copy implemented

FabijanC avatar Mar 29 '24 07:03 FabijanC

To avoid copying 32 bytes of data when the idea is just to move the element

marioiordanov avatar Mar 29 '24 08:03 marioiordanov

this looks interesting! i would love to work on this

g4titanx avatar Apr 22 '24 06:04 g4titanx

@g4titanx please report frequently on progress!

ivpavici avatar Apr 22 '24 09:04 ivpavici

okay

g4titanx avatar Apr 22 '24 11:04 g4titanx

hello @ivpavici, as expected removing the copy trait from Felt led to a chain of issues. some of the errors I got during compilation were from the custom types that implemented the copy trait with the Felt type in their field. i had to remove their copy traits tho.

now one error I am stuck with is "type mismatch resolving <Iter<'_, Felt> as IntoIterator>::Item == Felt " in this section of transaction.rs https://github.com/0xSpaceShard/starknet-devnet-rs/blob/9162df948ffc444520ba1c7397d9e8564e8dc576/crates/starknet-devnet-types/src/rpc/transactions.rs#L692-L693

g4titanx avatar Apr 22 '24 20:04 g4titanx

Of course, using a Vec<&Felt> for calldata_to_hash can be a solution, but it caused a series errors in the program, just like adding the cloned() method on line 693. I'm currently stuck on this issue, and I feel like I'm missing something important. i would be so glad if you can offer an helping hand

g4titanx avatar Apr 22 '24 20:04 g4titanx

Hello @ivpavici, any update on this

g4titanx avatar Apr 24 '24 06:04 g4titanx

@g4titanx in fact this issue is not an easy one the idea is to remove the copying of 32 bytes, where moving of the variable was intended.

marioiordanov avatar Apr 24 '24 11:04 marioiordanov

i agree. it's not as easy as I thought. but, I will give it all I can

g4titanx avatar Apr 24 '24 16:04 g4titanx

hello @ivpavici, as expected removing the copy trait from Felt led to a chain of issues. some of the errors I got during compilation were from the custom types that implemented the copy trait with the Felt type in their field. i had to remove their copy traits tho.

now one error I am stuck with is "type mismatch resolving <Iter<'_, Felt> as IntoIterator>::Item == Felt " in this section of transaction.rs

https://github.com/0xSpaceShard/starknet-devnet-rs/blob/9162df948ffc444520ba1c7397d9e8564e8dc576/crates/starknet-devnet-types/src/rpc/transactions.rs#L692-L693

tried different approach to fixing this issue. i am open to ideas how I can advance.

g4titanx avatar Apr 24 '24 18:04 g4titanx

@g4titanx can you open a PR with your approach? It's hard to tell like this what you tried

ivpavici avatar Apr 25 '24 09:04 ivpavici

Closing as this doesn't give any significant improvements

marioiordanov avatar Jun 04 '24 07:06 marioiordanov