File size: 1,614 Bytes
521eef6
 
 
 
 
 
 
 
 
 
 
 
 
e25c676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
license: mit
language:
- en
tags:
- smart-contracts
- vulnerability-detection
- solidity
- security
base_model: microsoft/codebert-base
pipeline_tag: text-classification
---

# CodeBERT for Solidity Vulnerability Detection

Fine-tuned version of microsoft/codebert-base for binary classification of Solidity smart contracts as vulnerable (1) or safe (0).

## Model Details
- Base model: microsoft/codebert-base
- Task: Binary classification (vulnerable=1, safe=0)
- Dataset: 367 Solidity smart contracts generated by 5 LLMs
- Training: 5 epochs, batch size 8, AdamW optimizer
- Platform: Google Colaboratory (T4 GPU)

## Results
- Accuracy: 95.9%
- Precision (vulnerable): 100%
- Recall (vulnerable): 93.3%
- F1-score (vulnerable): 0.97
- False positives: 0

## How to Use

Install: pip install transformers torch

    from transformers import AutoTokenizer, AutoModelForSequenceClassification
    import torch

    tokenizer = AutoTokenizer.from_pretrained("Sabreen2026/codebert-solidity-vulnerability")
    model = AutoModelForSequenceClassification.from_pretrained("Sabreen2026/codebert-solidity-vulnerability")
    model.eval()

    contract_code = "pragma solidity ^0.8.0; contract Test { }"

    inputs = tokenizer(contract_code, truncation=True, padding=True, max_length=512, return_tensors='pt')
    with torch.no_grad():
        outputs = model(**inputs)
        prediction = torch.argmax(outputs.logits, dim=1).item()

    print('VULNERABLE' if prediction == 1 else 'SAFE')

## Citation
Ahmadjee, S. (2026). Vulnerability Detection in LLM-Generated Solidity Smart Contracts Using Fine-Tuned CodeBERT.