Spaces:
Sleeping
Sleeping
| 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() |