File size: 2,413 Bytes
02f803a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
import tempfile
import os

def scan_contract(solidity_code: str) -> str:
    if not solidity_code.strip():
        return "Paste Solidity code above"
    with tempfile.NamedTemporaryFile(suffix='.sol', delete=False, mode='w') as f:
        f.write(solidity_code)
        fname = f.name
    try:
        result = subprocess.run(
            ['slither', fname, '--print', 'human-summary'],
            capture_output=True, text=True, timeout=60
        )
        output = result.stdout or result.stderr
    except FileNotFoundError:
        output = "Slither not installed. Running pattern-based scan...\n"
        patterns = [
            ("reentrancy", "CRITICAL: Potential reentrancy vulnerability detected"),
            ("tx.origin", "HIGH: tx.origin used for authorization (phishing risk)"),
            (".call{", "HIGH: Unchecked low-level call"),
            ("selfdestruct", "CRITICAL: selfdestruct detected"),
            ("block.timestamp", "MEDIUM: Block timestamp dependency"),
            ("delegatecall", "HIGH: delegatecall usage detected"),
        ]
        findings = []
        for pattern, message in patterns:
            if pattern in solidity_code:
                findings.append(message)
        if findings:
            output += "\n".join(findings)
        else:
            output += "No obvious vulnerabilities detected by pattern scan.\nNote: Install Slither for full analysis."
    except Exception as e:
        output = f"Error: {e}"
    finally:
        os.unlink(fname)
    return output or "No issues found"

example_contract = """pragma solidity ^0.6.0;
contract Vulnerable {
    mapping(address => uint) public balances;
    
    function withdraw() public {
        uint amount = balances[msg.sender];
        (bool success,) = msg.sender.call{value: amount}("");
        require(success);
        balances[msg.sender] = 0; // state change AFTER external call = reentrancy!
    }
}"""

demo = gr.Interface(
    fn=scan_contract,
    inputs=gr.Textbox(lines=20, label="Paste Solidity Code", value=example_contract),
    outputs=gr.Textbox(label="Audit Results"),
    title="AuditorSEC Audityzer Demo",
    description="Automated smart contract vulnerability scanner. 14 vulnerability patterns. Powered by Slither + Audityzer. | GitHub: romanchaa997/Audityzer | Telegram: @audityzerbot",
    examples=[[example_contract]]
)

demo.launch()