task_categories:text-classification task_categories:text-generation size_categories:n<1K language:en license:cc solidity vulnerability smart contract defi hacks hacks doi:10.57967/hf/0807 region:us
---
dataset_info:
  features:
  - name: attack_title
    dtype: string
  - name: github_path
    dtype: string
  - name: testcase
    dtype: string
  - name: is_real
    dtype: bool
  - name: interfaces
    list:
    - name: content
      dtype: string
    - name: imported
      dtype: bool
    - name: name
      dtype: string
    - name: token_count
      dtype: int64
  - name: date
    dtype: string
  - name: title
    dtype: string
  - name: id
    dtype: string
  - name: contract_path
    dtype: string
  - name: lost_value
    dtype: 'null'
  - name: attack_explain
    dtype: string
  - name: token_count
    dtype: int64
  splits:
  - name: train
    num_bytes: 6232550
    num_examples: 270
  download_size: 592765
  dataset_size: 6232550
license: cc
task_categories:
- text-classification
- text-generation
language:
- en
tags:
- solidity
- vulnerability
- smart contract
- defi hacks
- hacks
pretty_name: Solidity Defi Vulnerabilities
size_categories:
- n<1K
---
# Solidity DeFi Vulnerabilities

## Dataset Description
This dataset is collected from the following sources:
- [DeFiHackLabs](https://github.com/SunWeb3Sec/DeFiHackLabs) (Head Commit: `d951fa08a52c5651f9b3d9d7d919c996aebc0fa3`)
- [DeFiVulnLabs](https://github.com/SunWeb3Sec/DeFiVulnLabs) (Head Commit: `37d095da5780f6ba49caad49f256d8bf654aca89`)

It contains data related to various decentralized finance (DeFi) attack scenarios and vulnerabilities, including information about attack explanations, test cases, dates, token counts, interfaces, lost values, attack titles, and contract paths.

## Dataset Summary
The dataset consists of [270 examples](#data-splits) in total. Each example includes the following features:

- `id` (string): Identifier of the example.
- `title` (string): Title of the example or the Token name targeted by the attack.
- `attack_title` (string): Title of the attack or the name of the vulnerability.
- `github_path` (string): Path to the example's corresponding GitHub repository.
- `attack_explain` (string): Explanation of the attack scenario generated by `gpt-3.5-turbo`.
- `testcase` (string): Test case content in Solidity programming language.
- `date` (string): Date of the attack if exists otherwise it is the date when the dataset is created i.e 20230623.
- `token_count` (integer): Number of tokens in the example.
- `interfaces` (list): List of interfaces with the following sub-features:
  - `content` (string): Interface content.
  - `imported` (boolean): Indicates if the interface is imported.
  - `name` (string): Name of the interface.
  - `token_count` (integer): Number of tokens in the interface.
- `lost_value` (null): Value lost in the attack scenario (null if not applicable).
- `contract_path` (string): Relative path to the contract related to the attack.
- `is_real` (bool): Indicidates whether it is a real attack from DeFiHackLabs or just an example from DeFiVulnLabs.

## Supported Tasks and Leaderboards

The DeFiHackLabs dataset can be used for tasks related to analyzing DeFi attack scenarios, developing defense mechanisms, and improving security in decentralized finance.
As of now, there are no specific leaderboards associated with this dataset.

## Languages

The dataset is in the English language (en), and Solidity programming language.

## Data Splits

The dataset is split into a single split:

- `train`: 270 examples (100% of the dataset)

## Dataset Creation

The `token_count` field is calculated via the following snippet:
```python
import tiktoken

encoding = tiktoken.encoding_for_model('gpt-3.5-turbo')

def num_tokens_from_string(string: str) -> int:
    """Returns the number of tokens in a text string."""
    num_tokens = len(encoding.encode(string))
    return num_tokens
```

The `attack_explain` field is generated via OpenAI's `gpt-3.5-turbo` API with the followin prompt. Note that, for DeFiHackLabs, 'attack' is used instead of vulnerability. 
```
The following is a Solidity test case written in Foundry that exposes a vulnerability (OR an attack) titled "{attack_title}".
In one paragraph explain how it exposes this specific vulnerability?
{testcase}
```

## License

This dataset is released under the [Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license](https://creativecommons.org/licenses/by-nc/4.0/).

## Citation

Please use the following citations when referencing the this dataset:

1. Dataset's huggingface page:
```
@misc {seyyed_ali_ayati_2023,
	author       = { {Seyyed Ali Ayati} },
	title        = { solidity-defi-vulnerabilities (Revision 2e229c9) },
	year         = 2023,
	url          = { https://huggingface.co/datasets/seyyedaliayati/solidity-defi-vulnerabilities },
	doi          = { 10.57967/hf/0807 },
	publisher    = { Hugging Face }
}
```
2. DeFiHackLabs GitHub Repository:
```
@misc{sunweb3sec/2023,
  title = {{DeFiHackLabs}},
  author = {{SunWeb3Sec}},
  year = {2023},
  url = {https://github.com/SunWeb3Sec/DeFiHackLabs}
}
```
3. DeFiVulnLabs GitHub Repository:
```
@misc{sunweb3sec/2023,
  title = {{DeFiVulnLabs}},
  author = {{SunWeb3Sec}},
  year = {2023},
  url = {https://github.com/SunWeb3Sec/DeFiVulnLabs}
}
```