starkware-libs / cairo

Cairo is the first Turing-complete language for creating provable programs for general computation.
Apache License 2.0
1.6k stars 491 forks source link

feat: prevent usage of enums without a default variant in storage #6422

Closed enitrat closed 1 month ago

enitrat commented 1 month ago

I think enums without a default variant should throw an error at compile time if they try to derive starknet::Store - otherwise, attempting a storage read on an uninitialized slot will cause a runtime panic.

See description in https://github.com/cairo-book/cairo-book/issues/990

orizi commented 1 month ago

But why is that an issue specifically? it is the decision of the contract writer to know they only are reading valid values.

adding a diagnostic now may even be more confusing - even possibly marking any of the existing keys as #[default] causing a storage layout change.

(not saying no - just want to make sure the cure is better than the disease)

enitrat commented 1 month ago

it is the decision of the contract writer to know they only are reading valid values.

I consider it an issue because I don't think reading a value from storage should default to a panic if that value is not set. By ensuring a default variant exists, you are leveraging the compiler so that: