Skip to content

Commit 332d8e4

Browse files
committed
fix: update device fingerprinting overview and clean up code formatting
1 parent cfbc5e5 commit 332d8e4

6 files changed

Lines changed: 32 additions & 29 deletions

File tree

docs/challenges/dev_fingerprinter/deprecated/device_fingerprinting_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The Device Fingerprinting challenge (dev_fingerprinter_v1) tests your ability to
4141
"ts_name": "my-iphone.tail123.ts.net",
4242
"ts_ip": "100.64.0.1",
4343
"pushcut_id": "my-iphone",
44-
"pushcut_api_key": "jPH2Lacs7ygioCEX",
44+
"pushcut_api_key": "jPH2Lacs7ygioCEX", # pragma: allowlist secret
4545
"pushcut_server_id": "12345678-1234-1234-1234-123456789012",
4646
"device_model": "my-iphone-model",
4747
"fingerprint": null,

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from setuptools import setup
42

53
setup()

src/redteam_core/challenge_pool/active_challenges.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ historical_fingerprinter_v2:
2626
privileged: true
2727
environment:
2828
ENV: "PRODUCTION"
29+
HFP_API_LOGS_DIR: "/var/log/historical_fingerprinter"
30+
HFP_API_DATA_DIR: "/var/lib/historical_fingerprinter"
2931
HFP_CHALLENGE_API_KEY: "${RT_CHALLENGE_API_KEY}"
30-
HFP_CHALLENGE_API_LOGS_DIR: "/var/log/historical_fingerprinter"
31-
HFP_CHALLENGE_API_DATA_DIR: "/var/lib/historical_fingerprinter"
3232
HFP_CHALLENGE_ACCEPTABLE_MISS_COUNT: "${HFP_CHALLENGE_ACCEPTABLE_MISS_COUNT}"
3333
HFP_CHALLENGE_SINGLE_REQUEST_TIMEOUT: "${HFP_CHALLENGE_SINGLE_REQUEST_TIMEOUT}"
3434
HFP_CHALLENGE_FINGERPRINTER_PORT: "${HFP_CHALLENGE_FINGERPRINTER_PORT}"

src/redteam_core/challenge_pool/active_challenges_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import yaml
12
import importlib
23
import os
34
import json
@@ -13,9 +14,8 @@
1314
WORKSPACE_DIR = str(workspace_dir)
1415
os.environ["RT_WORKSPACE_DIR"] = WORKSPACE_DIR
1516

16-
import yaml
1717

18-
from redteam_core.validator.challenge_manager import ChallengeManager
18+
from redteam_core.validator.challenge_manager import ChallengeManager # noqa: E402
1919

2020
current_dir = Path(__file__).parent.resolve()
2121
ACTIVE_CHALLENGES_FILE = os.getenv(

src/redteam_core/challenge_pool/controller.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import copy
33
import time
44
import traceback
5-
from typing import Union
65

76
import bittensor as bt
87
import requests
@@ -141,7 +140,8 @@ def start_challenge(self):
141140
_max_comparison_score = self._check_comparison_score(miner_commit)
142141
if _max_comparison_score >= 0.6:
143142
bt.logging.info(
144-
f"[CONTROLLER] Max comparison score {_max_comparison_score} >= 0.6, skipping comparison validation."
143+
f"[CONTROLLER] Max comparison score {_max_comparison_score} >= 0.6,\
144+
skipping comparison validation."
145145
)
146146
miner_commit.comparison_logs = {
147147
"skipped": [
@@ -181,7 +181,7 @@ def start_challenge(self):
181181
)
182182

183183
bt.logging.debug(
184-
f"[CONTROLLER] Challenge completed, cleaning up challenge container"
184+
"[CONTROLLER] Challenge completed, cleaning up challenge container"
185185
)
186186

187187
docker_utils.remove_container(
@@ -301,7 +301,8 @@ def _run_reference_comparison_inputs(self, miner_commit: MinerChallengeCommit):
301301
or miner_commit.scoring_logs[0].miner_output is None
302302
):
303303
bt.logging.warning(
304-
f"[CONTROLLER] Skipping comparison with {reference_commit.docker_hub_id} for miner because the reference log is missing input or output."
304+
f"[CONTROLLER] Skipping comparison with {reference_commit.docker_hub_id} for miner because \
305+
the reference log is missing input or output."
305306
)
306307
continue
307308

@@ -321,7 +322,8 @@ def _run_reference_comparison_inputs(self, miner_commit: MinerChallengeCommit):
321322
and _similarity_score < self.max_self_comparison_score
322323
):
323324
bt.logging.warning(
324-
f"[CONTROLLER] Skipping self-comparison for {miner_commit.miner_hotkey} with {reference_commit.miner_hotkey} due to low similarity score {_similarity_score}"
325+
f"[CONTROLLER] Skipping self-comparison for {miner_commit.miner_hotkey}\
326+
with {reference_commit.miner_hotkey} due to low similarity score {_similarity_score}"
325327
)
326328
continue
327329

@@ -340,7 +342,8 @@ def _run_reference_comparison_inputs(self, miner_commit: MinerChallengeCommit):
340342
"min_acceptable_score", 0.6
341343
):
342344
bt.logging.warning(
343-
f"[CONTROLLER] Stopping comparison because of high similarity threshold is reached, similarity score {_similarity_score}"
345+
f"[CONTROLLER] Stopping comparison because of high similarity threshold is reached,\
346+
similarity score {_similarity_score}"
344347
)
345348
return
346349

@@ -380,15 +383,15 @@ def _validate_miner_submission(self, miner_commit: MinerChallengeCommit) -> bool
380383
_internal_services_url = str(constants.INTERNAL_SERVICES.API_URL).rstrip(
381384
"/"
382385
)
383-
_validator_endpoint = f"{_internal_services_url}/check/challenge/{self.challenge_info.get('challenge_type', 'default')}/"
386+
_validator_endpoint = f"{_internal_services_url}/check/challenge/{self.challenge_info.get('challenge_type', 'default')}/" # noqa: E501
384387
headers = {
385388
"Content-Type": "application/json",
386389
"X-API-KEY": constants.INTERNAL_SERVICES.API_KEY,
387390
}
388391
response = requests.post(
389392
_validator_endpoint,
390393
timeout=self.challenge_info.get("challenge_compare_timeout", 240),
391-
verify=False,
394+
verify=False, # nosec
392395
json=payload,
393396
headers=headers,
394397
)
@@ -414,7 +417,8 @@ def _generate_scoring_logs(
414417

415418
if miner_output is None or error_message:
416419
bt.logging.warning(
417-
f"[CONTROLLER - ABSController] Miner {miner_commit.miner_hotkey} failed to produce output for reference comparison: {error_message}"
420+
f"[CONTROLLER - ABSController] Miner {miner_commit.miner_hotkey} \
421+
failed to produce output for reference comparison: {error_message}"
418422
)
419423
miner_commit.scoring_logs.insert(
420424
0,
@@ -473,12 +477,12 @@ def _compare_outputs(
473477
response = requests.post(
474478
f"{constants.INTERNAL_SERVICES.API_URL}/compare",
475479
timeout=self.challenge_info.get("challenge_compare_timeout", 300),
476-
verify=False,
480+
verify=False, # nosec
477481
json=payload,
478482
headers=headers,
479483
)
480484
if response.status_code == 404:
481-
bt.logging.warning(f"No accepted submission to compare against.")
485+
bt.logging.warning("No accepted submission to compare against.")
482486
return None
483487

484488
response_data = response.json()
@@ -500,7 +504,8 @@ def _compare_outputs(
500504
def same_score_comparison(self, miner_commit: MinerChallengeCommit) -> None:
501505
if not miner_commit.scoring_logs:
502506
bt.logging.warning(
503-
f"[CONTROLLER] No scoring logs found for miner {miner_commit.miner_hotkey}, skipping same score comparison."
507+
f"[CONTROLLER] No scoring logs found for miner {miner_commit.miner_hotkey}, \
508+
skipping same score comparison."
504509
)
505510
_scoring_log = miner_commit.scoring_logs[0]
506511
_commit_score = _scoring_log.score
@@ -517,7 +522,8 @@ def same_score_comparison(self, miner_commit: MinerChallengeCommit) -> None:
517522
reference_commits_in_range.append(ref_commit)
518523
if not reference_commits_in_range:
519524
bt.logging.info(
520-
f"[CONTROLLER] No reference commits found with score in range for miner {miner_commit.miner_hotkey}, skipping same score comparison."
525+
f"[CONTROLLER] No reference commits found with score in range for miner {miner_commit.miner_hotkey}, \
526+
skipping same score comparison."
521527
)
522528
return
523529
for ref_commit in reference_commits_in_range:
@@ -587,12 +593,12 @@ def _compare_same_score_outputs(
587593
response = requests.post(
588594
f"{constants.INTERNAL_SERVICES.API_URL}/compare/same-score",
589595
timeout=self.challenge_info.get("challenge_compare_timeout", 300),
590-
verify=False,
596+
verify=False, # nosec
591597
json=payload,
592598
headers=headers,
593599
)
594600
if response.status_code == 404:
595-
bt.logging.warning(f"No accepted submission to compare against.")
601+
bt.logging.warning("No accepted submission to compare against.")
596602
return None
597603

598604
response_data = response.json()
@@ -646,7 +652,7 @@ def _check_comparison_score(self, miner_commit: MinerChallengeCommit) -> float:
646652
compare_url,
647653
json=payload,
648654
timeout=100,
649-
verify=False,
655+
verify=False, # nosec
650656
headers=headers,
651657
)
652658
response.raise_for_status()
@@ -689,7 +695,7 @@ def _compare_with_baseline(self, miner_commit: MinerChallengeCommit):
689695
response = requests.post(
690696
f"{_internal_service_url}/compare/baseline-scripts",
691697
timeout=self.challenge_info.get("challenge_compare_timeout", 240),
692-
verify=False,
698+
verify=False, # nosec
693699
json=payload,
694700
headers=headers,
695701
)
@@ -852,9 +858,7 @@ def _get_current_commits_to_compare(
852858
_all_current_commits.append(commit)
853859
return _all_current_commits
854860

855-
def _check_protocol(
856-
self, is_challenger: bool = True
857-
) -> tuple[str, Union[bool, None]]:
861+
def _check_protocol(self, is_challenger: bool = True) -> tuple[str, bool | None]:
858862
"""Check the protocol scheme and SSL/TLS verification for the challenger or miner.
859863
860864
Args:
@@ -865,7 +869,7 @@ def _check_protocol(
865869
"""
866870

867871
_protocol = "http"
868-
_ssl_verify: Union[bool, None] = None
872+
_ssl_verify: bool | None = None
869873

870874
if "protocols" in self.challenge_info:
871875
_protocols = self.challenge_info["protocols"]

src/redteam_core/challenge_pool/docker_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def run_container(
3333
_miner_pat = _miner_docker_info.get("personal_access_token", None)
3434
if not _miner_username or not _miner_pat:
3535
raise ValueError(
36-
"Miner Docker image requires authentication. Please provide 'dockerhub_username' and 'personal_access_token'."
36+
"Miner Docker image requires authentication. \
37+
Please provide 'dockerhub_username' and 'personal_access_token'."
3738
)
3839
_auth_config = {
3940
"username": _miner_username,

0 commit comments

Comments
 (0)