py-ssz icon indicating copy to clipboard operation
py-ssz copied to clipboard

Clean up homogeneous composite sedes length pre-conditions

Open hwwhww opened this issue 5 years ago • 3 comments

updated the issue: 2020, June 18th

What was wrong?

As https://github.com/ethereum/eth2.0-specs/issues/1863 pointed out, it seems

https://github.com/ethereum/py-ssz/blob/7e9c1079dc503902484003fa6f46f4b8c69c8e1e/ssz/sedes/basic.py#L177-L180

is only for Vector, and then override it in List. It made the illegal condition unclear.

How can it be fixed?

~~1. Use illegal condition max_length < 0 for HomogeneousProperCompositeSedes (wow it's so long)~~ ~~2. Override vector types' (Vector and Bitvector) __init__() with illegal condition max_length < 1.~~

  1. Remove HomogeneousProperCompositeSedes.__init_()
  2. Update vector types' (Vector and Bitvector) __init__() with illegal condition max_length < 1.
  3. Add list types' (List and Bitlist) __init__() with illegal condition max_length < 0.

hwwhww avatar Jun 03 '20 04:06 hwwhww

@hwwhww I think the __inti__()s for Bitvector and Vector have the override mentioned in 2. above? :)

https://github.com/ethereum/py-ssz/blob/7e9c1079dc503902484003fa6f46f4b8c69c8e1e/ssz/sedes/bitvector.py#L19-L22

https://github.com/ethereum/py-ssz/blob/7e9c1079dc503902484003fa6f46f4b8c69c8e1e/ssz/sedes/vector.py#L25-L32

booleanfunction avatar Jun 18 '20 01:06 booleanfunction

@booleanfunction

You're right, sorry! Fixing the suggested proposal:

  1. ~~Replace HomogeneousProperCompositeSedes.__init_() with abstractmethod.~~ Remove HomogeneousProperCompositeSedes.__init_()
  2. Update vector types' (Vector and Bitvector) __init__() with illegal condition max_length < 1.
  3. Add list types' (List and Bitlist) __init__() with illegal condition max_length < 0.

I think this is more clear than overriding?

hwwhww avatar Jun 18 '20 04:06 hwwhww

@hwwhww that seems like a good way to do it :)

booleanfunction avatar Jun 18 '20 06:06 booleanfunction