CoolFace
Apppublic

pujitha909/smart-contract-auditor

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

Smart Contract Auditor Environment

An OpenEnv benchmark where an agent audits Solidity contracts and reports vulnerabilities with type, location, severity, and fix suggestions.

Environment Summary

PropertyValue
Environment Namesmart_contract_auditor
RuntimeDocker
App Entryserver/app.py
Default Port7860
Tasksbasic_audit, intermediate_audit, advanced_audit
Model AccessOpenAI-compatible client over Hugging Face router

What This Environment Does

The environment provides Solidity contract code and accepts one finding per action. The agent can continue submitting findings or send done to finish the audit episode.

Action Space

Actions are represented by AuditAction.

FieldTypeDescription
vulnerability_typestrVulnerability label or done
locationstrFunction name where issue exists
severitystrcritical / high / medium / low
fix_suggestionstrRemediation text

Supported vulnerability labels:

reentrancy, integer_overflow, access_control, unchecked_return, tx_origin, selfdestruct, timestamp_dependence, front_running, delegatecall, denial_of_service, precision_loss, flash_loan, oracle_manipulation, uninitialized_storage, done

Observation Space

Observations are represented by AuditObservation.

FieldTypeDescription
doneboolWhether episode ended
reward`floatnull`Step reward or final reward
contract_codestrSolidity code under review
contract_namestrCurrent contract name
task_namestrActive task id
findings_so_farlist[dict]Submitted findings
remaining_stepsintStep budget left
total_vulnerabilities_hintintHint count of vulnerabilities
valid_vulnerability_typeslist[str]Allowed labels (excluding done)
messagestrFeedback after each action

Tasks

Easy - basic_audit

  • Single vulnerability in a short contract.

Medium - intermediate_audit

  • Two vulnerabilities with mixed patterns.

Hard - advanced_audit

  • Three vulnerabilities with subtle bugs and red herrings.

Reward Function

Per-finding scoring:

  • type match: +0.4
  • location match: +0.3
  • severity match: +0.1
  • quality fix suggestion: +0.2

Final episode score:

  • normalized by number of target vulnerabilities
  • false-positive penalty: 0.05 per unmatched finding
  • clipped to [0.0, 1.0]

Quick Start

1) Install dependencies

bash
pip install -r requirements.txt

2) Run from source

bash
python -m server.app

Open in browser:

text
http://127.0.0.1:7860

3) Run the baseline scripts

bash
python inference.py
python inference_rl.py --task basic_audit --num-runs 5

Baseline Scores

TaskExpected Score
basic_audit~0.85
intermediate_audit~0.65
advanced_audit~0.40

Expected Inference Log Format

inference.py prints these line types:

text
[START] task=<task_name> env=smart_contract_auditor model=<model_name>
[STEP]  step=<n> action=<action_str> reward=<0.00> done=<true|false> error=<msg|null>
[END]   success=<true|false> steps=<n> score=<score> rewards=<r1,r2,...,rn>

Environment Variables

VariableRequiredDescription
HF_TOKENYesHugging Face API token
API_BASE_URLYesOpenAI-compatible API base URL
MODEL_NAMEYesLLM model id
LOCAL_IMAGE_NAMENoLocal Docker image tag
GRADIO_SERVER_PORTNoOverride local port
PORTNoHosted runtime port

Example .env:

env
HF_TOKEN=hf_your_token_here
API_BASE_URL=https://router.huggingface.co/v1
MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
LOCAL_IMAGE_NAME=smart-contract-auditor
# Optional
# GRADIO_SERVER_PORT=7860

Docker and Validation

bash
openenv validate
docker build -t smart-contract-auditor .
docker run -d --name smart-contract-auditor-test -p 7860:7860 smart-contract-auditor
curl http://127.0.0.1:7860/health

Key Project Files

text
.
├── environment.py
├── models.py
├── contracts.py
├── inference.py
├── inference_rl.py
├── dashboard.py
├── server/
│   └── app.py
├── openenv.yaml
└── README.md

Troubleshooting

IssueCauseFix
Errno 10048 on startupPort 7860 already usedKill process on 7860, restart app
Browser shows 0.0.0.0 errorWrong URL in browserUse http://127.0.0.1:7860
LLM auth failsMissing/invalid tokenSet correct HF_TOKEN
LLM request mismatchWrong endpoint/modelCheck API_BASE_URL and MODEL_NAME

License

MIT