CoolFace
Apppublic

vaishnavi0905/solidityguard-env

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

SolidityGuard-Env ๐Ÿ›ก๏ธ

![openenv](https://openenv.dev) ![domain]() ![difficulty]()

The first OpenEnv environment for smart contract security auditing. An AI agent reads vulnerable Solidity contracts, identifies security flaws, classifies severity, and proposes patches โ€” exactly what a human auditor does before a protocol goes live.

Why This Matters

Smart contract vulnerabilities have caused over $3 billion in losses โ€” The DAO hack, Ronin Bridge, Euler Finance. Every contract needs a security audit before deployment. This environment trains and benchmarks AI agents to perform that audit automatically.


Environment Overview

The agent receives a Solidity contract and must:

  1. 1.Detect vulnerabilities (reentrancy, access control, oracle manipulation, etc.)
  2. 2.Classify severity: critical / high / medium / low
  3. 3.Locate the vulnerable function
  4. 4.Patch โ€” suggest a concrete fix

Action Space

ActionParamsDescription
report_vulnerabilityname, severity, location, descriptionSubmit a found vulnerability
suggest_patchvuln_id, patchPropose a fix for a vulnerability
request_hintnoneGet a hint (โˆ’0.1 score penalty)
finalizenoneDeclare audit complete (+0.05 bonus)
noopnoneDo nothing

Observation Space

FieldTypeDescription
task_idstrCurrent task identifier
task_descriptionstrWhat the agent must do
contract_namestrName of the Solidity contract
source_codestrFull Solidity source
abi_summarylistFunction signatures
known_findingslistVulnerabilities reported so far
step_numberintCurrent step
doneboolEpisode over?
hints_usedintHints consumed

Tasks

Task 1 โ€” Easy: SimpleBank (1 vulnerability)

  • โ€”Contract: A minimal ETH bank with deposit/withdraw
  • โ€”Vuln: Classic reentrancy in withdraw() โ€” state updated after external call
  • โ€”Inspiration: The DAO hack, 2016 ($60M lost)

Task 2 โ€” Medium: VaultManager (3 vulnerabilities)

  • โ€”Contract: Multi-user ETH vault with pause mechanism
  • โ€”Vulns: tx.origin authentication flaw, reentrancy in withdraw(), missing access control on emergencyDrain()
  • โ€”Challenge: Must find all three with correct severity classification

Task 3 โ€” Hard: LendingPool (4 vulnerabilities)

  • โ€”Contract: DeFi lending pool with ERC-20 tokens, flash loans, collateral
  • โ€”Vulns: Flash loan reentrancy, integer precision loss, price oracle manipulation, admin rug pull
  • โ€”Challenge: Find all 4 AND suggest correct patches for each

Task 4 โ€” Medium: NFTMint (3 vulnerabilities)

  • โ€”Contract: NFT minting contract with whitelist and 1000 max supply
  • โ€”Vulns: Weak randomness via block.timestamp, front-running in whitelist mint, locked ETH with no withdrawal
  • โ€”Challenge: Find all 3 including the subtle locked ETH issue

Task 5 โ€” Hard: VulnToken ERC-20 (4 vulnerabilities)

  • โ€”Contract: ERC-20 token with EIP-2612 permit, about to list on DEX
  • โ€”Vulns: Approval race condition, cross-chain permit replay, unrestricted mint, fee-on-transfer inconsistency
  • โ€”Challenge: Find all 4 including the subtle cross-chain replay attack

Reward Function

score = detection(0.60) + patch(0.35) + finalize_bonus(0.05)
      - hint_penalty(0.10 each)
      - false_positive_penalty(0.05 each)
  • โ€”Detection: keyword + severity + location matching against ground truth
  • โ€”Patch: patch text matched against accepted fix patterns
  • โ€”Partial credit: incorrect severity = 0.5x detection score
  • โ€”Score range: 0.0 - 1.0

Setup

Local

bash
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 7860

Docker

bash
docker build -t solidityguard-env .
docker run -p 7860:7860 solidityguard-env

API Usage

bash
curl -X POST "http://localhost:7860/reset?task_id=task1"

curl -X POST "http://localhost:7860/step?task_id=task1" \
  -H "Content-Type: application/json" \
  -d '{"action_type": "report_vulnerability", "params": {"name": "Reentrancy", "severity": "critical", "location": "withdraw", "description": "External call before state update"}}'

Running the Baseline

bash
export API_BASE_URL="https://router.huggingface.co/v1"
export MODEL_NAME="meta-llama/Llama-3.3-70B-Instruct"
export HF_TOKEN="your_token_here"
export ENV_URL="http://localhost:7860"

python inference.py

Baseline Scores

TaskContractVulnsDifficultyBaseline
task1SimpleBank1Easy~0.82
task2VaultManager3Medium~0.61
task3LendingPool4Hard~0.40
task4NFTMint3Medium~0.58
task5VulnToken4Hard~0.38

Project Structure

solidityguard-env/
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ openenv.yaml
โ”œโ”€โ”€ inference.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ app.py
โ””โ”€โ”€ env/
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ models.py
    โ”œโ”€โ”€ contracts.py
    โ”œโ”€โ”€ grader.py
    โ””โ”€โ”€ environment.py

Team

MindBloom โ€” Built for OpenEnv Hackathon Round 1

Cybersecurity x Blockchain x AI agents