-
Notifications
You must be signed in to change notification settings - Fork 20
Description
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}).