Solidity smart contract development guidelines for Linea blockchain. Use when writing, reviewing, or refactoring Solidity contracts, or when the user asks about Solidity best practices, contract structure, or NatSpec docstrings. Covers NatSpec documentation, naming conventions, file layout, and code style.
95
—
Does it follow best practices?
Impact
91%
1.37xAverage score across 3 eval scenarios
Passed
No known issues
Best practices for developing Solidity smart contracts on Linea blockchain. Contains rules covering documentation, naming, structure, and code style.
Reference: Linea Contract Style Guide
Reference these guidelines when:
// SPDX-License-Identifier: Apache-2.0 OR MIT
0.8.33 (exact)^0.8.33 (caret)| Priority | Category | Impact | Rule File |
|---|---|---|---|
| 1 | Gas optimization | CRITICAL | rules/gas-optimization.md |
| 2 | NatSpec Docstrings | HIGH | rules/natspec.md |
| 3 | File Layout | HIGH | rules/file-layout.md |
| 4 | Naming | HIGH | rules/naming-conventions.md |
| 5 | Imports | MEDIUM | rules/imports.md |
| 6 | Visibility | MEDIUM | rules/visibility.md |
| 7 | General Rules | MEDIUM | rules/general-rules.md |
Read individual rule files for detailed explanations and code examples (correct and incorrect).
Gas efficiency is critical for Linea contracts. Apply these rules unless there is a documented safety, audit, or readability reason to deviate.
// Correct: external + calldata, cache storage reads
function submit(bytes32[] calldata _proofs) external {
uint256 current = fee;
require(current != 0, FeeNotSet());
_verify(_proofs, current);
}
// Incorrect: public + memory, repeated storage reads
function submit(bytes32[] memory _proofs) public {
require(fee != 0, FeeNotSet());
_verify(_proofs, fee);
}See rules/gas-optimization.md for details.
ALWAYS use NatSpec docstrings for all public/external items.
// Correct: complete NatSpec with @notice, @param (in signature order), @return
/**
* @notice Sends a message to L2.
* @param _to The recipient address on L2.
* @param _fee The fee amount in wei.
* @return messageHash The hash of the sent message.
*/
function sendMessage(address _to, uint256 _fee) external payable returns (bytes32 messageHash);Every contract/interface NatSpec block must include @author Consensys Software Inc. and @custom:security-contact security-report@linea.build.
Consult rules/natspec.md for NatSpec docstring rules and examples
Interface structure:
Contract structure:
See rules/file-layout.md for templates.
See rules/naming-conventions.md for symbol naming conventions.
Always use named imports. Always insert a blank line after imports.
// Correct: named imports with blank line before NatSpec/contract declaration
import { IMessageService } from "../interfaces/IMessageService.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title Brief description.
* @author Consensys Software Inc.
* @custom:security-contact security-report@linea.build
*/
contract MessageService is IMessageService, Ownable {See rules/imports.md for details.
See rules/visibility.md for rules on applying visibility modifiers (internal, external, public, etc).
See rules/general-rules.md for inheritance and general style rules
Follow this sequence when writing or modifying Solidity contracts:
pnpm -F contracts run buildpnpm -F contracts run lint:fixpnpm -F contracts run test@notice, @param (in signature order), and @return.memory copies, repeated storage reads, and missing batch limits.Before making a commit, please verify:
@notice, @param, @return)rules/*.md have been appliedpnpm -F contracts run lint:fix)For commands for testing and linting, refer to rules/commands.md
9c684a0
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.