Text Classification
Transformers
Safetensors
English
roberta
code
solidity
smart-contracts
vulnerability-detection
graphcodebert
Eval Results (legacy)
Instructions to use tanaymitra01/graphcodebert-vulnerability-detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tanaymitra01/graphcodebert-vulnerability-detector with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="tanaymitra01/graphcodebert-vulnerability-detector")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("tanaymitra01/graphcodebert-vulnerability-detector") model = AutoModelForSequenceClassification.from_pretrained("tanaymitra01/graphcodebert-vulnerability-detector", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Graph CodeBERT โ Solidity Vulnerability Detector
Fine-tuned microsoft/graphcodebert-base for Solidity smart-contract vulnerability type classification.
Part of SolidityGuard โ used as a first-pass detector alongside Slither and an LLM auditor.
How it fits in SolidityGuard
- Input: Solidity source
- Detectors: Slither / patterns + this Graph CodeBERT model
- LLM agents: Scanner โ Analyzer โ Exploit Gen / Fix Suggester
- Output: Audit findings with severity and confidence
Model
- Tokenizer โ
max_length=512 - Graph CodeBERT encoder (~125M params)
- Linear classification head โ 12-class softmax โ label + confidence
Training
- SmartBugs-Wild contracts (capped at 5,000)
- Labels from SmartBugs-Results tool consensus (โฅ2 tools agree on a category; else
safe) - Split 70 / 15 / 15 (train / val / test) with light augmentation
- Fine-tune
microsoft/graphcodebert-basewith early stopping on validation macro-F1 - Best checkpoint published here
Intended use
- Input: Solidity source code (string)
- Output: one of 12 labels + confidence
- Best as a screening signal, not a sole security audit
Labels
| ID | Label | Typical severity hint |
|---|---|---|
| 0 | safe |
โ |
| 1 | reentrancy |
Critical |
| 2 | access_control |
Critical |
| 3 | tx_origin_auth |
Critical |
| 4 | integer_overflow |
Critical |
| 5 | unsafe_delegatecall |
Critical |
| 6 | weak_randomness |
Medium |
| 7 | unbounded_loop |
Medium |
| 8 | redundant_storage |
Low |
| 9 | gas_optimization |
Low |
| 10 | best_practice |
Low |
| 11 | other |
Medium |
Held-out test metrics
| Metric | Value |
|---|---|
| Accuracy | 0.562 |
| Macro F1 | 0.466 |
F1 safe |
0.694 |
F1 integer_overflow |
0.634 |
F1 reentrancy |
0.461 |
F1 other |
0.340 |
F1 access_control |
0.200 |
Labels are noisy (static-analysis consensus), so scores are moderate by design.
Quick start
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
repo = "tanaymitra01/graphcodebert-vulnerability-detector"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo)
model.eval()
code = """
pragma solidity ^0.8.0;
contract Vault {
mapping(address => uint) public bal;
function withdraw() public {
uint amount = bal[msg.sender];
(bool ok,) = msg.sender.call{value: amount}("");
require(ok);
bal[msg.sender] = 0;
}
}
"""
inputs = tok(code, return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
probs = torch.softmax(model(**inputs).logits, dim=-1)[0]
pred = int(probs.argmax())
print(model.config.id2label[pred], float(probs[pred]))
With SolidityGuard
export GRAPHCODEBERT_PATH=tanaymitra01/graphcodebert-vulnerability-detector
Where to get the weights
| Location | Path |
|---|---|
| Hugging Face (recommended) | tanaymitra01/graphcodebert-vulnerability-detector |
| GitHub LFS | training/checkpoints/best/ in the SolidityGuard repo |
Files
model.safetensorsโ weightsconfig.jsonโ RobertaForSequenceClassification config + label mapslabel_map.jsonโ label list / id maps used in trainingREADME.mdโ this model card
Limitations
- Tool-derived labels โ audited ground truth
- Truncation at 512 tokens; large contracts lose context
- Rare classes (e.g. access control) have low F1
- Not a replacement for professional security review
Citation
@misc{solidityguard-graphcodebert,
title = {Graph CodeBERT Vulnerability Detector for Solidity},
author = {Tanay Mitra},
year = {2026},
url = {https://huggingface.co/tanaymitra01/graphcodebert-vulnerability-detector}
}
- Downloads last month
- 36
Model tree for tanaymitra01/graphcodebert-vulnerability-detector
Base model
microsoft/graphcodebert-baseEvaluation results
- Test accuracy on SmartBugs-Wild (subset, tool-consensus labels)self-reported0.562
- Macro F1 on SmartBugs-Wild (subset, tool-consensus labels)self-reported0.466