@@ -3,13 +3,17 @@ description:
33globs: *.sol
44alwaysApply: false
55---
6+
67# Optimism Solidity Style Guide
78
89Applies to Solidity files.
910
1011## Comments
11- - Use triple-slash solidity natspec comment style
12- - Always use `@notice` instead of `@dev`
12+
13+ - NatSpec documentation comments must use the triple-slash `///` style
14+ - Use `//` for regular inline comments that are not NatSpec
15+ - Use `@notice` for documenting what a function/contract does (external-facing documentation)
16+ - Use `@dev` for internal developer notes, reminders, or invariants (e.g., "when updating this, also update X")
1317- Use a line-length of 100 characters
1418- Custom tags:
1519 - `@custom:proxied`: Add to a contract whenever it's meant to live behind a proxy
@@ -19,10 +23,12 @@ Applies to Solidity files.
1923 - `@custom:network-specific`: Add to state variables which vary between OP Chains
2024
2125## Errors
26+
2227- When adding new errors, always use custom Solidity errors
2328- Custom errors should take the format `ContractName_ErrorDescription`
2429
2530## Naming Conventions
31+
2632- Function parameters should be prefixed with an underscore
2733- Function return arguments should be suffixed with an underscore
2834- Event parameters should NOT be prefixed with an underscore
@@ -33,6 +39,7 @@ Applies to Solidity files.
3339- Spacers must be named `spacer_<slot>_<offset>_<length>` and be `private`
3440
3541## Upgradeability
42+
3643- Contracts should be built assuming upgradeability by default
3744- Extend OpenZeppelin's `Initializable` or base contract
3845- Use the `ReinitializableBase` contract
@@ -43,6 +50,7 @@ Applies to Solidity files.
4350 - Set any immutables (though generally avoid immutables)
4451
4552## Versioning
53+
4654- All non-library/non-abstract contracts must inherit `ISemver` and expose `version()`
4755- Production-ready contracts must have version `1.0.0` or greater
4856- Version increments:
@@ -53,12 +61,15 @@ Applies to Solidity files.
5361AI code review tools should NOT comment on the choice of version increment.
5462
5563## Dependencies
64+
5665- Prefer OpenZeppelin's Upgradeable contracts for basic functionality
5766
5867## State Changes
68+
5969- All state changing functions should emit a corresponding event
6070
6171## Testing
72+
6273- Tests should be written using Foundry
6374- For testing reverts with low-level calls, use the `revertsAsExpected` pattern
6475- Test function naming: `[method]_[functionName]_[reason]_[status]`
0 commit comments