library-api-design
Skill1.2k starsChanged 24 days agoMITView on GitHub
API design rules for openzeppelin-contracts. Use when adding, modifying, or reviewing any contract under contracts/. Covers virtual, memory vs calldata, public vs external, overloads, no-op vs revert, _update single-override pattern, internal/external split, _msgSender, and override points.
1 other project uses a version of this.
Trending
More talk lately.about the whole repository
Most recently taken up by
- OpenZeppelin/openzeppelin-contractsword for word, first seen Oct 8, 2026
Who's talking about OpenZeppelin/openzeppelin-contracts-upgradeable
- smartcontractkit/chainlink“[FEAT] Chainlink upgradeable smart contracts”GitHub · Sep 7, 2021 · 40 reactions
- foundry-rs/foundry“Support EIP-7201 in `forge inspect storage`”GitHub · Apr 14, 2024 · 4 reactions
- OpenZeppelin/openzeppelin-contracts“Use diamond storage instead of gaps in upgradeable contracts”GitHub · Nov 12, 2021 · 3 reactions
- code-423n4/2022-06-nibbl-findings“[PNM-001] Function `permit` directly uses `_approve`, suffering from the well-known double attacks”GitHub · Jun 24, 2022 · 2 reactions
- OpenZeppelin/openzeppelin-contracts“Release 4.7”GitHub · May 4, 2022 · 2 reactions
The biggest 5 of 51 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 51
Talked about on GitHub and Stack Overflow (51 times).
On GitHub · 50
- Sep 7, 2021[FEAT] Chainlink upgradeable smart contracts — smartcontractkit/chainlink40 reactions · 15 comments
- Apr 14, 2024Support EIP-7201 in `forge inspect storage` — foundry-rs/foundry4 reactions · 9 comments
- Nov 12, 2021Use diamond storage instead of gaps in upgradeable contracts — OpenZeppelin/openzeppelin-contracts3 reactions · 37 comments
- Jun 24, 2022[PNM-001] Function `permit` directly uses `_approve`, suffering from the well-known double attacks — code-423n4/2022-06-nibbl-findings2 reactions · 3 comments
- May 4, 2022Release 4.7 — OpenZeppelin/openzeppelin-contracts2 reactions · 4 comments
45 more on GitHub
- Jun 2, 2026chore(deps-dev): bump the openzeppelin group across 1 directory with 3 updates — XFuel-Lab/chit4021 reaction · 5 comments
- Apr 8, 2026foundry-rs#13763 (#398) — Dargon789/foundry1 reaction · 12 comments
- Mar 9, 2026`forge install` submodule cleanup discrepancy when using `--no-git` — foundry-rs/foundry1 reaction
- Dec 17, 2023cergyk - FootiumClub::ERC721Upgradeable/Pausable Cannot pause transfers on FootiumClub NFT — sherlock-audit/2023-12-footium-judging1 reaction · 15 comments
- Oct 27, 2023__Ownable_init() function isn't called properly in the initializer — hats-finance/Smooth-0x64bc275b37e62eec81a00ecaecd2b9567058f9901 reaction · 1 comment
- Oct 17, 2023Ownable2StepUpgradeable requires initializing OwnableUpgradeable — OpenZeppelin/openzeppelin-contracts1 reaction · 12 comments
- Nov 14, 2022removes base contract dependency on hardhat / fixes initializer modifiers — Network-Goods/hypercerts-protocol1 reaction · 3 comments
- Oct 20, 2022[R&D review] Unify ERC20 interfaces — morpho-org/morpho-optimizers-vaults1 reaction · 12 comments
- Oct 18, 2022Contracts without GAP can lead a upgrade disaster — code-423n4/2022-10-traderjoe-findings1 reaction · 2 comments
- Aug 6, 2022 Use of not recommended ERC721 _mint function — code-423n4/2022-08-rigor-findings1 reaction · 1 comment
- Jun 25, 2022QA Report — code-423n4/2022-06-yieldy-findings1 reaction
- Jan 10, 2022New keyword `pin` for fixed sparse storage layouts — argotorg/solidity1 reaction · 10 comments
- Nov 4, 2026chore(deps): bump lib/openzeppelin-contracts-upgradeable from `7bd46d8` to `7839763` — YieldShield/smart-contracts0 reactions · 1 comment
- Nov 4, 2026Bump contracts/lib/openzeppelin-contracts-upgradeable from `7bf4727` to `7839763` — Rong0715/assert-dao0 reactions
- Nov 3, 2026chore(deps): bump lib/openzeppelin-contracts-upgradeable from `ed0d253` to `7839763` — the3rdweblabs/payment-kit.evm0 reactions · 2 comments
- Nov 3, 2026Bump lib/openzeppelin-contracts-upgradeable from `3d5fa5c` to `7839763` — lukema95/flip-core0 reactions
- Nov 2, 2026chore(deps): bump lib/openzeppelin-contracts-upgradeable from `fc6d2f3` to `58c8c82` — owieth/foundry-setup0 reactions
- Nov 2, 2026build(deps): bump contracts/lib/openzeppelin-contracts-upgradeable from `1717bdd` to `ce38bf1` — YieldShield/yieldshield-bnb-open-source0 reactions
- Oct 28, 2026chore(deps): bump lib/openzeppelin-contracts-upgradeable from `7bd46d8` to `fc6d2f3` — YieldShield/smart-contracts0 reactions · 2 comments
- Oct 21, 2026chore(deps): bump @openzeppelin/contracts-upgradeable from 5.3.0 to 5.4.0 — Datura-ai/celium-collateral-contracts0 reactions
- Oct 15, 2026chore(deps): bump @openzeppelin/contracts-upgradeable from 5.4.0 to 5.7.0 in /solidity in the openzeppelin-contracts group across 1 directory — oasisprotocol/privana0 reactions · 1 comment
- Oct 1, 2026chore(deps): Bump contracts/lib/openzeppelin-contracts-upgradeable from `527c1bd` to `66f1abd` — ismellike/nft-gacha0 reactions
- Sep 18, 2026Bump @openzeppelin/contracts-upgradeable from 5.0.0 to 5.0.2 in the npm_and_yarn group across 1 directory — Ronnie-Ahmed/Foundry_Tutorial0 reactions
- Sep 1, 2026chore(deps): bump contracts/lib/openzeppelin-contracts-upgradeable from `c1b1bed` to `f8fc282` — NeoWeb3Nova/NeoDeFi0 reactions · 1 comment
- Jul 27, 2026Bump lib/openzeppelin-contracts-upgradeable from `723f8ca` to `7a37a98` — dust/zen-staking-layer0 reactions
- Jun 20, 2026chore(deps): bump contracts/lib/openzeppelin-contracts-upgradeable from `7bf4727` to `c1b1bed` — tresr-community/tresr-game0 reactions
- Jun 4, 2026deps: bump the openzeppelin group across 1 directory with 3 updates — eq-lab/pipeline-contracts0 reactions
- Apr 20, 2026Track upstream OZ PR to expose ERC-7201 root slot as internal — S01-Issuer/st0x.deploy0 reactions · 3 comments
- Mar 9, 2026chore(deps): bump lib/openzeppelin-contracts-upgradeable from `60b305a` to `524c8c9` — k0yote/newlo-point0 reactions
- Nov 25, 2025Bump @openzeppelin/contracts-upgradeable from 5.0.1 to 5.0.2 — vechain/vevote0 reactions · 2 comments
- Feb 19, 2025Bald Crimson Alligator - Launch contract does not use upgradable versions of parent initializer functions — sherlock-audit/2025-02-rova-judging0 reactions
- Feb 5, 2025Bump @openzeppelin/contracts-upgradeable from 4.9.3 to 4.9.6 — lidofinance/linea-contracts0 reactions
- Dec 5, 2024Energetic Honeysuckle Leopard - corrupt upgdreability pattarn — sherlock-audit/2024-11-ethos-network-ii-judging0 reactions
- Dec 2, 2024Bump contracts/lib/openzeppelin-contracts-upgradeable from `723f8ca` to `5fcea08` — ava-labs/avalanche-interchain-token-transfer0 reactions
- Nov 5, 2024USDE : renounceRole is not fully sealed — hats-finance/Euro-Dollar-0xa4ccd3b6daa763f729ad59eae75f9cbff7baf2cd0 reactions · 1 comment
- Aug 6, 2024chore(deps): update dependency @openzeppelin/contracts to v4.9.6 [security] — ashutoshvarma/sway0 reactions · 1 comment
- Jul 8, 2024Bump @openzeppelin/contracts-upgradeable from 5.0.0 to 5.0.2 — Ultra-Tech-code/Dynamic_NFT0 reactions
- Jun 8, 2024Uninitialized Implementation Contracts are not Completely Protected — code-423n4/2024-05-predy-validation0 reactions
- May 1, 2024CvxRewardDistributor misses `_Ownable2Step_init()` in the `initialize()` function — hats-finance/Convergence---Convex-integration-0xb3df23e155b74ad2b93777f58980d6727e8b40bb0 reactions · 13 comments
- Apr 29, 2024chore(deps): bump lib/openzeppelin-contracts-upgradeable from `762e9bc` to `82e861e` — Akagi201/foundry-template0 reactions
- Apr 24, 2024build(deps-dev): bump @openzeppelin/contracts-upgradeable from 4.9.3 to 4.9.6 — henkaku-center/mono-auction-contract0 reactions
- Apr 16, 2024chore(deps-dev): bump @openzeppelin/contracts-upgradeable from 4.9.3 to 4.9.6 — spherity/ethr-revocation-registry0 reactions
- Feb 29, 2024Bump @openzeppelin/contracts-upgradeable from 4.9.3 to 4.9.6 — Fathom-Fi/fathom-solidity-sdk0 reactions
- Feb 29, 2024Bump @openzeppelin/contracts-upgradeable from 4.9.3 to 4.9.6 in /contracts — 1337CyberSecurity/chainlink0 reactions
- Feb 29, 2024Bump @openzeppelin/contracts-upgradeable from 4.9.3 to 4.9.6 — eniblock/website-demo0 reactions
On Stack Overflow · 1
Other versions1 project uses a version of this.
Word for word · 1
- OpenZeppelin/openzeppelin-contracts★ 27k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- add-changesetSkill
- solidity-styleSkill
- testingSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 44
Use memory for string, bytes, arrays, and structs — including in public functions.
- Very specific: line 52
Default to public. Use external only when:
- Distinctive: line 86
If an operation can do nothing without creating a security concern, it should do nothing.
- Very specific: line 114
Use _msgSender() in application logic.
- Very specific: line 126
When overriding from multiple bases, list all of them: override(A, B).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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
Library API design
This repo is a base library: every contract is inherited downstream. The rules below preserve that inheritability. Most of them are not lint-enforced — they require judgment when adding new contracts.
virtual on overridable functions
Mark every public and internal function virtual — with two specific exceptions:
Alias functions (one function that just forwards to another with no added logic) are NOT virtual. The canonical form is the virtual one. Add a NatSpec NOTE: pointing to it:
/**
* @dev See {IERC20-transfer}.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
// ...
_update(from, to, value);
}Convenience overloads that only fill in a default argument are NOT virtual; the full-argument canonical form is:
// not virtual (only sets emitEvent = true):
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
// virtual (real override point):
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual { ... }Solhint's no-external-virtual rule catches external virtual (fallback excepted) — the right fix is public virtual, not silencing the rule. The reason external can't be the override point: an override of an external function cannot call super, so a function designed to be overridden must be public.
memory for reference-type arguments
Use memory for string, bytes, arrays, and structs — including in public functions. calldata forces every inheritor to match, so it is only valid in three narrow cases:
- The return value is a slice of
msg.data(e.g._msgData()inContext.sol). - An internal calldata-decoding helper that is genuinely scoped to one function (e.g.
_extractSignatureValidator(bytes calldata signature) internal pure returns (address module, bytes calldata innerSignature)inAccountERC7579.sol). - An explicit
Calldata-suffixed parallel variant in a utility library, where the base version still usesmemory(e.g.MerkleProof.verifyCalldata).
public vs external
Default to public. Use external only when:
- The ERC spec itself defines the function as
external(e.g.ERC20Permit.DOMAIN_SEPARATOR,UUPSUpgradeable.proxiableUUID). - The contract design explicitly prevents internal calls and the function must only be reachable from outside (e.g.
ERC7786Recipient.receiveMessage, where only an authorized gateway should call it and meta-transactions don't apply).
external for the second reason needs a NatSpec NOTE: explaining why.
The internal/external split
public functions exist only to (1) capture _msgSender() and (2) delegate to an internal function that takes the actor as an explicit argument. All logic lives in the internal variant:
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}This keeps internal functions composable, testable through hardhat-exposed, and independently overridable.
_update single override point
For state machines with several entry points (mint, burn, transfer), make _mint/_burn/_transfer non-virtual aliases that delegate to a single virtual _update(...). Extensions override _update only, never the individual operations, and always call super._update(...) before adding side effects:
function _update(address from, address to, uint256 value) internal virtual override {
super._update(from, to, value); // base logic first
_transferVotingUnits(from, to, value); // side effects after
}Prefer no-ops over reverts
If an operation can do nothing without creating a security concern, it should do nothing. This shows up at three levels:
Vacuous inputs: skip silently rather than reverting. batchSize == 0 skips the whole mint loop; ERC721Utils.checkOnERC721Received skips the callback for EOAs because there is nothing to check. Document the no-op condition with a short inline comment.
Idempotent state transitions: return a bool from operations that may already be at the target state, instead of reverting. The caller can add a revert; the base never takes that choice away:
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
}
return false; // already revoked — no-op, not revert
}Empty virtual hooks: internal virtual {} is a valid extension point when no default behavior exists. Always _camelCase, always internal virtual, always documented with @dev:
/// @dev Hook called every time the tally for a proposal is updated.
function _tallyUpdated(uint256 proposalId) internal virtual {}Rule of thumb: overrides can always add requirements on top of a no-op base. They cannot remove a requirement the base already enforces.
_msgSender() vs msg.sender
Use _msgSender() in application logic. msg.sender appears only inside Context.sol / ERC2771Context.sol, or in deliberate protocol-level exceptions (e.g. ERC7786Recipient.receiveMessage, where wrapping the sender would break the protocol). Every exception outside the Context layer needs a NOTE: explaining why.
super and extension contracts
super must be called in _update overrides, in supportsInterface overrides, and whenever an extension builds on base behavior. Skipping super is only acceptable for genuinely new functions that have no base implementation.
supportsInterface always follows the pattern:
interfaceId == type(X).interfaceId || super.supportsInterface(interfaceId)When overriding from multiple bases, list all of them: override(A, B).
Constructors, immutables, and the transpiler
| Keyword | When | Naming |
constant | Compile-time known (type hashes, role ids, slot addresses) | ALL_CAPS_WITH_UNDERSCORES |
immutable | Constructor-set, deploy-time computed | _camelCase (same as private state) |
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable is not a "this value is too dangerous to change" tag — every immutable can still be changed by upgrading to a new implementation. The tag controls per-implementation vs per-proxy:
- Tag present: the value stays
immutablein the upgradeable variant. It is set in the upgradeable contract's constructor and shared by every proxy that points at that implementation. Changing it requires a new implementation. - Tag absent: the transpiler converts the field to a regular storage slot and moves initialization into the initializer. Each proxy gets its own value while sharing one implementation.
Pick the tag when the value is logically a property of the implementation (e.g. ERC2771Context._trustedForwarder — the trust relationship belongs to the deployed code, not each proxy). Omit it when each deployment should configure its own value (e.g. GovernorVotes._token).
ERC-7201 namespaced storage
ERC-7201 is opt-in, not the default. Upgradeable variants of OZ contracts are auto-generated by the OpenZeppelin Transpiler — don't preemptively add ERC-7201 storage layouts to new contracts.
Reach for it only when namespacing is genuinely necessary, such as Initializable.sol (sequential slot 0 would be risky for proxy implementations). New uses must justify themselves in NatSpec. When it is the right tool:
/// @custom:storage-location erc7201:openzeppelin.storage.MyContract
struct MyContractStorage {
uint256 _value;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.MyContract")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant MY_CONTRACT_STORAGE = 0x...;
// solhint-disable-next-line var-name-mixedcase
function _getMyContractStorage() private pure returns (MyContractStorage storage $) {
assembly {
$.slot := MY_CONTRACT_STORAGE
}
}Rules: struct annotated with @custom:storage-location; inline formula comment above the constant; pointer variable always named $; solhint-disable-next-line var-name-mixedcase immediately before any function that uses $; constant in ALL_CAPS. Always verify the slot value with SlotDerivation.erc7201Slot() — never compute by hand.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

