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.
max_length=512 safe) microsoft/graphcodebert-base with early stopping on validation macro-F1 | 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 |
| 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.
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]))
export GRAPHCODEBERT_PATH=tanaymitra01/graphcodebert-vulnerability-detector
| Location | Path |
|---|---|
| Hugging Face (recommended) | tanaymitra01/graphcodebert-vulnerability-detector |
| GitHub LFS | training/checkpoints/best/ in the SolidityGuard repo |
model.safetensors — weights config.json — RobertaForSequenceClassification config + label maps label_map.json — label list / id maps used in training README.md — this model card@misc{solidityguard-graphcodebert,
title = {Graph CodeBERT Vulnerability Detector for Solidity},
author = {Tanay Mitra},
year = {2026},
url = {https://huggingface.co/tanaymitra01/graphcodebert-vulnerability-detector}
}
microsoft/graphcodebert-base