File size: 3,243 Bytes
b0498a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import requests
import yaml
import os
import sys

def validate_environment(space_url, repo_url):
    print(f"Starting Validation for: {space_url}\n")
    results = {}

    # 1. Ping Check (Must return 200)
    try:
        r = requests.get(space_url, timeout=10)
        results["HF Space Ping (200)"] = r.status_code == 200
    except Exception as e:
        results[f"HF Space Ping (200) - Error: {str(e)}"] = False

    # 2. Reset Check (Must return AuditObservation)
    try:
        r = requests.post(f"{space_url}/reset", json={"task_id": "easy_reentrancy"}, timeout=10)
        data = r.json()
        results["reset() returns AuditObservation"] = "contract_code" in data and "task_id" in data
    except Exception as e:
        results[f"reset() returns AuditObservation - Error: {str(e)}"] = False

    # 3. Step Check (Must return scored result)
    try:
        # Note: We send a "buggy" action even though the contract is "fixed" 
        # to ensure the grader runs and returns a score (even if 0.0)
        action = {
            "analysis": "Testing validation",
            "vulnerabilities": [{"type": "reentrancy", "line": 14, "severity": "high", "description": "test"}],
            "suggested_fixes": ["test"]
        }
        r = requests.post(f"{space_url}/step", json=action, timeout=10)
        data = r.json()
        reward = data.get("reward", -1)
        results["step() returns scored result (0.0-1.0)"] = 0.0 <= reward <= 1.0
    except Exception as e:
        results[f"step() returns scored result - Error: {str(e)}"] = False

    # 4. State Check (Must return AuditState)
    try:
        r = requests.get(f"{space_url}/state", timeout=10)
        data = r.json()
        results["state() returns AuditState"] = "current_task" in data
    except Exception as e:
        results[f"state() returns AuditState - Error: {str(e)}"] = False

    # 5. Local File Checks
    results["openenv.yaml exists"] = os.path.exists("openenv.yaml")
    results["Dockerfile exists"] = os.path.exists("Dockerfile")
    results["inference.py exists"] = os.path.exists("inference.py")
    results["README.md exists"] = os.path.exists("README.md")

    # 6. Task Count Check
    try:
        with open("openenv.yaml", "r") as f:
            cfg = yaml.safe_load(f)
            tasks = cfg.get("tasks", [])
            results["openenv.yaml has 3+ tasks"] = len(tasks) >= 3
    except:
        results["openenv.yaml has 3+ tasks"] = False

    print("--- Final Checklist ---")
    all_passed = True
    for task, passed in results.items():
        status = "[PASS]" if passed else "[FAIL]"
        if not passed: all_passed = False
        print(f"{status} | {task}")

    print("-" * 25)
    if all_passed:
        print("\n✨ EVERYTHING IS PERFECT! You are ready to submit.")
        print(f"Space URL: {space_url}")
        print(f"Repo URL:  {repo_url}")
    else:
        print("\nSOME CHECKS FAILED. Please ensure your Space is 'Running' on Hugging Face before submitting.")

if __name__ == "__main__":
    # Detect Space URL from repo name if possible, else use provided
    url = "https://ismail131-smart-contract-audit-env.hf.space"
    repo = "https://github.com/Sayyed23/ET-hackethon"
    validate_environment(url, repo)