From 509354582c5d381b1cad38b211f0c97a182de00f Mon Sep 17 00:00:00 2001 From: protolambda Date: Wed, 10 Apr 2019 11:14:22 +1000 Subject: [PATCH 1/2] limit bit-length of justification bitfield to strict 64, prevent SSZ encoding crash due to too large integer size --- specs/core/0_beacon-chain.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 1d68eae52..c3161c8c0 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1819,6 +1819,8 @@ def update_justification_and_finalization(state: BeaconState) -> None: # Rotate the justification bitfield up one epoch to make room for the current epoch state.justification_bitfield <<= 1 + # Python var length integers: justification bitfield is 64 bits, and may not be bigger (for SSZ serialization) + state.justification_bitfield &= (1 << 64) - 1 # If the previous epoch gets justified, fill the second last bit previous_boundary_attesting_balance = get_attesting_balance(state, get_previous_epoch_boundary_attestations(state)) if previous_boundary_attesting_balance * 3 >= get_previous_total_balance(state) * 2: From 7ffcdcfd7c6ac131c00a67e8d7f3b6850750f700 Mon Sep 17 00:00:00 2001 From: protolambda Date: Fri, 12 Apr 2019 09:12:37 +1000 Subject: [PATCH 2/2] bitfield length limit style improvement --- specs/core/0_beacon-chain.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index c3161c8c0..9ff2c29cb 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1817,10 +1817,8 @@ def update_justification_and_finalization(state: BeaconState) -> None: new_justified_epoch = state.current_justified_epoch new_finalized_epoch = state.finalized_epoch - # Rotate the justification bitfield up one epoch to make room for the current epoch - state.justification_bitfield <<= 1 - # Python var length integers: justification bitfield is 64 bits, and may not be bigger (for SSZ serialization) - state.justification_bitfield &= (1 << 64) - 1 + # Rotate the justification bitfield up one epoch to make room for the current epoch (and limit to 64 bits) + state.justification_bitfield = (state.justification_bitfield << 1) % 2**64 # If the previous epoch gets justified, fill the second last bit previous_boundary_attesting_balance = get_attesting_balance(state, get_previous_epoch_boundary_attestations(state)) if previous_boundary_attesting_balance * 3 >= get_previous_total_balance(state) * 2: