EIP-1470 · Stagnant · Informational · 2018-09-18
EIP-1470: Smart Contract Weakness Classification (SWC)
Proposed the Smart Contract Weakness Classification (SWC), a CWE-style catalogue of numbered smart-contract bug types such as SWC-101 for integer overflow.
What problem does it solve?
Audit reports, security tools and academic papers each used their own names for the same smart-contract bugs. Comparing findings, triaging tool output or training analysers was slow, even for experts, because there was no shared vocabulary.
Mainstream software security solved this with the Common Weakness Enumeration (CWE), a numbered list of weakness types. CWE has nothing specific to smart contracts, so EIP-1470 proposes a smart-contract-specific layer on top of it: the SWC (Smart Contract Weakness Classification).
How it works
Key terms in the spec:
- Weakness: an error that, under the right conditions, can lead to a vulnerability.
- Variant: a specific, smart-contract-level weakness. Each gets an SWC ID, e.g.
SWC-101for Integer Overflow and Underflow. - Relationship: each SWC links to its closest parent in CWE. SWC-101, for example, links to CWE-682 Incorrect Calculation.
- Test case: a small or real-world contract showing the weakness.
Each SWC entry is a Markdown document with a title naming the root cause, its CWE relationship, a description of impact, remediation advice and references.
Each test case has three parts: the source (Solidity, Vyper…), the compiled artefact in a machine-readable format, and a YAML/JSON configuration stating which SWC IDs appear and how many times. Tool authors can run their analyser over the test cases and compare against the expected results.
Sample code
A test-case configuration following the schema in the spec (illustrative values):
description: Token contract with an unchecked addition in transfer()
issues:
- id: "SWC-101"
count: 1
locations:
- bytecode_offsets:
"0x6060...": [412]
line_numbers:
token.sol: [27]
The kind of contract such a case would describe (pre-0.8 Solidity, where arithmetic did not revert on overflow):
pragma solidity ^0.4.24;
contract Token {
mapping(address => uint256) public balanceOf;
function transfer(address to, uint256 value) public {
require(balanceOf[msg.sender] - value >= 0); // always true for uint
balanceOf[msg.sender] -= value; // can underflow (SWC-101)
balanceOf[to] += value;
}
}
Things to know
- Status: Stagnant. It is an Informational EIP; the classification itself was maintained outside the EIP process, in a public SWC registry repository referenced by the spec.
- The registry is a vocabulary, not a checklist of everything that can go wrong. Many later bug classes (oracle manipulation, economic attacks, cross-chain issues) are not well covered by it.
- SWC IDs are still seen in audit reports and tool output, so it helps to recognise them; check whether the registry you are reading is still maintained before relying on it.
- Some entries describe issues that newer compilers mitigate, such as SWC-101 after Solidity 0.8 made checked arithmetic the default.