Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

stop using usize in public types #1684

Open
tdelabro opened this issue Mar 19, 2024 · 0 comments
Open

stop using usize in public types #1684

tdelabro opened this issue Mar 19, 2024 · 0 comments

Comments

@tdelabro
Copy link
Contributor

tdelabro commented Mar 19, 2024

Types that are publics are part of the protocol.
Using usize in such types means that the protocol accepts different max values depending on the machine on which it is executed.

Example:

pub struct EventSizeLimit {
    pub max_data_length: usize,
    pub max_keys_length: usize,
    pub max_n_emitted_events: usize,
}

On a 32 bit machine, the max_n_emitted_events maximum value will be u32::MAX, on a 64 bit machine the max_n_emitted_events maximum value will be u64::MAX. Meaning that a block produced on a 64 bits machine, could in theory be invalid for all the u32 machines. They will overflow and end up with a different value.

The values exposed by the protocol should always be defined unequivocally, otherwise, we expose a decentralized network of machines to the possibility of a hard fork and loss of consensus.

same issue on the cairo-vm: lambdaclass/cairo-vm#1498
It should be enforced across the starknet rust ecosystem.
Ideally, in a perfect world, some SNIP should decide for each value, if we want it to be a u8, u16, u32, u64, u128, u256, felt252, or something else. But letting the hardware decide for us is never ok.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant