linea-monorepo / contracts
AGENTS.md126 starsChanged 3 months agoApache-2.0View on GitHub
Inherits all rules from root AGENTS.md. Only overrides and additions below. Solidity smart contracts for the Lineth protocol: L1 rollup (LinethRollup), messaging services (L1/L2MessageService), token bridge (TokenBridge), and supporting libraries. Built with Hardhat and Foundry. Every public/external function, event, and error MUST have NatSpec: - @notice on every public/external function - @param for every parameter (in signature order) - @return for every return value (named) - @author Consensys Software Inc. and @custom:security-contact security-report@linea.build on every contract/interface - @dev for non-obvious…
- Installs packages
We split this AGENTS.md into the rules it gives an agent
7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 61
Every public/external function, event, and error MUST have NatSpec:
- Distinctive: line 114
No magic numbers — use named constants
- Very specific: line 115
Never deploy without VERIFY_CONTRACT=true for block explorer verification
- Distinctive: line 127
Always read the existing interface before modifying a contract
- Distinctive: line 128
Check storage layout compatibility before changing state variables in upgradeable contracts
- Very specific: line 129
Run pnpm -F contracts run lint:fix before committing any Solidity changes
- Very specific: line 151
Run pnpm hardhat compile in /contracts (requires pnpm i first).
≈ “Common” is an estimate: at least 1 in 5 of the 36,368 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — Contracts Agent Guidelines
Inherits all rules from root AGENTS.md. Only overrides and additions below.
Package Overview
Solidity smart contracts for the Lineth protocol: L1 rollup (LinethRollup), messaging services (L1/L2MessageService), token bridge (TokenBridge), and supporting libraries. Built with Hardhat and Foundry.
How to Run
# Install dependencies
pnpm install
# Build (compile contracts)
pnpm -F contracts run build
# Run tests
pnpm -F contracts run test
# Run tests with gas reporting
pnpm -F contracts run test:reportgas
# Coverage
pnpm -F contracts run coverage
# Lint Solidity
pnpm -F contracts run lint:sol
pnpm -F contracts run lint:sol:fix
# Lint TypeScript (test/deploy scripts)
pnpm -F contracts run lint:ts
pnpm -F contracts run lint:ts:fix
# Format Solidity
pnpm -F contracts run prettier:sol
pnpm -F contracts run prettier:sol:fix
# Full lint + format
pnpm -F contracts run lint:fix
# Generate Solidity docs (requires Foundry)
pnpm -F contracts run solidity:docgenSolidity-Specific Conventions
Compiler and EVM
- Solidity version:
0.8.33(exact for contracts, caret^0.8.33for interfaces/abstract/libraries) - EVM version: osaka (Hardhat), cancun (Foundry)
- OpenZeppelin contracts: 4.9.6
Licenses
- Interfaces:
// SPDX-License-Identifier: Apache-2.0 - Contracts:
// SPDX-License-Identifier: AGPL-3.0
NatSpec Documentation
Every public/external function, event, and error MUST have NatSpec:
@noticeon every public/external function@paramfor every parameter (in signature order)@returnfor every return value (named)@author Consensys Software Inc.and@custom:security-contact security-report@linea.buildon every contract/interface@devfor non-obvious implementation detailsDEPRECATEDin NatSpec for deprecated items
Naming
| Item | Convention | Example |
| Public state | camelCase | uint256 messageCount |
| Private/internal state | _camelCase | uint256 _internalCounter |
| Constants | UPPER_SNAKE_CASE | bytes32 DEFAULT_ADMIN_ROLE |
| Function params | _camelCase | function send(address _to) |
| Return variables | camelCase (named) | returns (bytes32 messageHash) |
| Mappings | descriptive keys | mapping(uint256 id => bytes32 hash) |
| Init functions | __Contract_init | __PauseManager_init() |
File Layout
Interface: Structs -> Enums -> Events -> Errors -> External Functions
Contract: Using statements -> Constants -> State variables -> Structs -> Enums -> Events -> Errors -> Modifiers -> Functions
Imports
Named imports only. Explicit inheritance of key ancestors. Blank line after import block.
Gas Optimization
external+calldatafor functions accepting arrays/structs- Cache storage values read multiple times
- Custom errors over revert strings
uncheckedonly with proven safe arithmetic (with comment)- Short-circuit: cheap checks before expensive ones
- Explicit batch limits for loops
Visibility
- Constants:
internalunless explicitly needed public - Overridable functions:
public virtual(notexternal virtual) - Minimize public surface area
- Explicit visibility on all state variables
Solidity-Specific Safety Rules
- Upgradeable contracts use ERC-7201 namespaced storage (not storage gaps)
- Both
initializeandreinitializeVNusereinitializer(N)(neverinitializer) - Zero-value checks via
ErrorUtils.revertIfZeroAddress()/ErrorUtils.revertIfZeroHash() - Assembly: hex for memory offsets (
mstore(add(mPtr, 0x20), _var)) - Repeated checks extracted into modifiers
- No magic numbers — use named constants
- Never deploy without
VERIFY_CONTRACT=truefor block explorer verification - Contract modifications from audited code require independent audit
Testing
- Hardhat tests:
test/hardhat/— TypeScript test files - Foundry tests:
test/foundry/— Solidity test files - Coverage:
SOLIDITY_COVERAGE=trueflag with.solcover.jsconfig - CI runs coverage and uploads to Codecov with
hardhatflag
Agent Rules (Overrides)
- Always read the existing interface before modifying a contract
- Check storage layout compatibility before changing state variables in upgradeable contracts
- Run
pnpm -F contracts run lint:fixbefore committing any Solidity changes - For detailed rules, see
.agents/skills/developing-smart-contracts/and.cursor/rules/smart-contract-guidelines/
Hardhat scripts and optional browser signer UI (HARDHAT_SIGNER_UI)
- Default: deployments use
DEPLOYER_PRIVATE_KEY(andnamedAccounts) like any standard Hardhat project. - Opt-in UI: set
HARDHAT_SIGNER_UI=trueto sign in a browser via the local Next.js app undercontracts/signer-ui/, driven bycontracts/scripts/hardhat/signer-ui-bridge.ts. Deploy scripts usewithSignerUiSession,getUiSigner, and helpers inscripts/hardhat/utils.tsthat callsetUiTransactionContextfor richer UI labels. Selected operational tasks userunWithSignerUiSession+getUiSigner.HARDHAT_SIGNER_UI=trueandDEPLOYER_PRIVATE_KEYare mutually exclusive; Hardhat errors if both are set. After a fullhardhat deploy, the bridge reports a terminal outcome and stops Next.js by default (seeHARDHAT_SIGNER_UI_LEAVE_NEXT_DEV_AFTER_DEPLOY/HARDHAT_SIGNER_UI_SHUTDOWN_NEXT_DEVin deployment docs). - Docs: contracts/docs/deployment/README.md (overview), contracts/signer-ui/README.md (operator walkthrough), contracts/docs/deployment/signer-ui-removal.md (how to delete the feature).
- Lint:
contracts/eslint.config.mjsignoressigner-ui/**so Next’s.nextoutput is not parsed by the contracts ESLint project.
local-deployments-artifacts/
Hardhat compilation artifacts consumed by the E2E test pipeline (e2e/scripts/generateAbi.ts).
| Subdirectory | Contents |
deployed-artifacts/ | Artifacts for production on-chain deployments |
static-artifacts/ | Artifacts for non-upgradeable contracts used in E2E tests |
dynamic-artifacts/ | Artifacts for upgradeable contracts |
Producing an artifact
- Run
pnpm hardhat compilein/contracts(requirespnpm ifirst). - Find the JSON build artifact in
contracts/build/src/. - Copy it to the appropriate subdirectory above.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 28,693 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- coordinator/AGENTS.mdAGENTS.md
- e2e/AGENTS.mdAGENTS.md
- maru/AGENTS.mdAGENTS.md
- postman/AGENTS.mdAGENTS.md
- prover/AGENTS.mdAGENTS.md
- prover-ray/AGENTS.mdAGENTS.md
- tracer/AGENTS.mdAGENTS.md
- transaction-exclusion-api/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/documentation.mdcCursor rule
- .cursor/rules/security-logging-guidelines/EXAMPLES.mdCursor rule
- .cursor/rules/security-logging-guidelines/RULES.mdCursor rule
- .cursor/rules/smart-contract-guidelines/RULE.mdCursor rule
- .cursor/rules/versioning-guidelines/EXAMPLES.mdCursor rule
- .cursor/rules/versioning-guidelines/RULES.mdCursor rule
- developing-smart-contractsSkill
- linea-dependency-maintenanceSkill
- squash-bugbotSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

