code: def compute_difficulty(
          bomb_delay: int,
          parent_header: BlockHeader,
          timestamp: int) -> int:
      
      parent_timestamp = parent_header.timestamp
      validate_gt(timestamp, parent_timestamp, title="Header.timestamp")
  
      parent_difficulty = parent_header.difficulty
      offset = parent_difficulty // DIFFICULTY_ADJUSTMENT_DENOMINATOR
  
      has_uncles = parent_header.uncles_hash != EMPTY_UNCLE_HASH
      adj_factor = max(
          (
              (2 if has_uncles else 1) -
              ((timestamp - parent_timestamp) // BYZANTIUM_DIFFICULTY_ADJUSTMENT_CUTOFF)
          ),
          -99,
      )
      difficulty = max(
          parent_difficulty + offset * adj_factor,
          min(parent_header.difficulty, DIFFICULTY_MINIMUM)
      )
      num_bomb_periods = (
          max(
              0,
              parent_header.block_number + 1 - bomb_delay,
          ) // BOMB_EXPONENTIAL_PERIOD
      ) - BOMB_EXPONENTIAL_FREE_PERIODS
  
      if num_bomb_periods >= 0:
          return max(difficulty + 2**num_bomb_periods, DIFFICULTY_MINIMUM)
      else:
          return difficulty
docs: https://github.com/ethereum/EIPs/issues/100