Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce non-zero capacity #13

Open
michaelsproul opened this issue Jun 26, 2023 · 0 comments
Open

Enforce non-zero capacity #13

michaelsproul opened this issue Jun 26, 2023 · 0 comments

Comments

@michaelsproul
Copy link
Member

The SSZ spec states that lists and vectors should not have 0 capacity. The ssz_generic test suite from the EF tests checks this.

One way to enforce a non-zero capacity is at runtime, although this is a bit annoying in that it makes some previously infallible functions like List::empty() return a Result. This makes traits like Default impossible to implement without unwrap. I've got a WIP version of this change here: 6bcb9ba

Alternatively, we could use typenum's NonZero trait to enforce non-zero lengths at compile-time (dependent types!). This has the advantage of not adding any new Result types, but is a bit more complicated from an interface PoV. I've got a WIP version of this change here: d1eed1a. Integrating it into lighthouse would be a little more involved, we'd need to update EthSpec to add NonZero bounds to all typenum lengths. We could possibly use a new trait defined in milhouse to minimise the churn (e.g. use milhouse::Unsigned rather than use typenume::{Unsigned, NonZero}).

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

No branches or pull requests

1 participant