From 237b41df5b41a37972c66c51d5acd551134189b5 Mon Sep 17 00:00:00 2001 From: Dankrad Feist Date: Fri, 28 Jun 2019 00:18:54 +0100 Subject: [PATCH] Slice notation for justification_bitfield shift --- specs/core/0_beacon-chain.md | 5 +++-- .../pyspec/eth2spec/utils/ssz/ssz_typing.py | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index f596da520..0ea24a255 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1292,8 +1292,9 @@ def process_justification_and_finalization(state: BeaconState) -> None: # Process justifications state.previous_justified_epoch = state.current_justified_epoch state.previous_justified_root = state.current_justified_root - state.justification_bitfield = Bitvector[JUSTIFICATION_BITVECTOR_LENGTH]( - *([0b0] + state.justification_bitfield[0:JUSTIFICATION_BITVECTOR_LENGTH - 1])) + state.justification_bitfield[1:JUSTIFICATION_BITVECTOR_LENGTH] = \ + state.justification_bitfield[0:JUSTIFICATION_BITVECTOR_LENGTH - 1] + state.justification_bitfield[0] = 0b0 previous_epoch_matching_target_balance = get_attesting_balance( state, get_matching_target_attestations(state, previous_epoch) ) diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py index 53ab42743..ba773b443 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py @@ -324,12 +324,18 @@ class BaseList(list, Elements): return super().__getitem__(k) def __setitem__(self, k, v): - if k < 0: - raise IndexError(f"cannot set item in type {self.__class__} at negative index {k} (to {v})") - if k > len(self): - raise IndexError(f"cannot set item in type {self.__class__}" - f" at out of bounds index {k} (to {v}, bound: {len(self)})") - super().__setitem__(k, coerce_type_maybe(v, self.__class__.elem_type, strict=True)) + if type(k) == slice: + if k.start < 0 or k.stop > len(self): + raise IndexError(f"cannot set item in type {self.__class__}" + f" at out of bounds slice {k} (to {v}, bound: {len(self)})") + super().__setitem__(k, [coerce_type_maybe(x, self.__class__.elem_type) for x in v]) + else: + if k < 0: + raise IndexError(f"cannot set item in type {self.__class__} at negative index {k} (to {v})") + if k > len(self): + raise IndexError(f"cannot set item in type {self.__class__}" + f" at out of bounds index {k} (to {v}, bound: {len(self)})") + super().__setitem__(k, coerce_type_maybe(v, self.__class__.elem_type, strict=True)) def append(self, v): super().append(coerce_type_maybe(v, self.__class__.elem_type, strict=True))