github.com/prysmaticlabs/prysm@v1.4.4/tools/specs-checker/data/specs/phase0/weak-subjectivity.md (about)

     1  ```python
     2  def compute_weak_subjectivity_period(state: BeaconState) -> uint64:
     3      """
     4      Returns the weak subjectivity period for the current ``state``. 
     5      This computation takes into account the effect of:
     6          - validator set churn (bounded by ``get_validator_churn_limit()`` per epoch), and 
     7          - validator balance top-ups (bounded by ``MAX_DEPOSITS * SLOTS_PER_EPOCH`` per epoch).
     8      A detailed calculation can be found at:
     9      https://github.com/runtimeverification/beacon-chain-verification/blob/master/weak-subjectivity/weak-subjectivity-analysis.pdf
    10      """
    11      ws_period = MIN_VALIDATOR_WITHDRAWABILITY_DELAY
    12      N = len(get_active_validator_indices(state, get_current_epoch(state)))
    13      t = get_total_active_balance(state) // N // ETH_TO_GWEI
    14      T = MAX_EFFECTIVE_BALANCE // ETH_TO_GWEI
    15      delta = get_validator_churn_limit(state)
    16      Delta = MAX_DEPOSITS * SLOTS_PER_EPOCH
    17      D = SAFETY_DECAY
    18  
    19      if T * (200 + 3 * D) < t * (200 + 12 * D):
    20          epochs_for_validator_set_churn = (
    21              N * (t * (200 + 12 * D) - T * (200 + 3 * D)) // (600 * delta * (2 * t + T))
    22          )
    23          epochs_for_balance_top_ups = (
    24              N * (200 + 3 * D) // (600 * Delta)
    25          )
    26          ws_period += max(epochs_for_validator_set_churn, epochs_for_balance_top_ups)
    27      else:
    28          ws_period += (
    29              3 * N * D * t // (200 * Delta * (T - t))
    30          )
    31      
    32      return ws_period
    33  ```
    34  ```python
    35  def is_within_weak_subjectivity_period(store: Store, ws_state: BeaconState, ws_checkpoint: Checkpoint) -> bool:
    36      # Clients may choose to validate the input state against the input Weak Subjectivity Checkpoint
    37      assert ws_state.latest_block_header.state_root == ws_checkpoint.root
    38      assert compute_epoch_at_slot(ws_state.slot) == ws_checkpoint.epoch
    39  
    40      ws_period = compute_weak_subjectivity_period(ws_state)
    41      ws_state_epoch = compute_epoch_at_slot(ws_state.slot)
    42      current_epoch = compute_epoch_at_slot(get_current_slot(store))
    43      return current_epoch <= ws_state_epoch + ws_period
    44  ```