agentleFS
OpenZeppelinOpenZeppelin/openzeppelin-contracts-upgradeable/.claude/skills/library-api-design/SKILL.md

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

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 2 mentionsApr 2026: 2 mentionsMay 2026: 0 mentionsJun 2026: 3 mentionsJul 2026: 1 mentionAug 2026: 0 mentionsSep 2026: 2 mentionsOct 2026: 4 mentionsNov 2026: 6 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the OpenZeppelin/openzeppelin-contracts-upgradeable repository that our weekly crawl found. There is no adoption data for this file yet.

Most recently taken up by

Who's talking about OpenZeppelin/openzeppelin-contracts-upgradeable

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

45 more on GitHub
  • Other versions1 project uses a version of this.

    Word for word · 1

    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.

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
  1. Very specific:

    Use memory for string, bytes, arrays, and structs — including in public functions.

    line 44
  2. Very specific:

    Default to public. Use external only when:

    line 52
  3. Distinctive:

    If an operation can do nothing without creating a security concern, it should do nothing.

    line 86
  4. Very specific:

    Use _msgSender() in application logic.

    line 114
  5. Very specific:

    When overriding from multiple bases, list all of them: override(A, B).

    line 126

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. The return value is a slice of msg.data (e.g. _msgData() in Context.sol).
  2. 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) in AccountERC7579.sol).
  3. An explicit Calldata-suffixed parallel variant in a utility library, where the base version still uses memory (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

KeywordWhenNaming
constantCompile-time known (type hashes, role ids, slot addresses)ALL_CAPS_WITH_UNDERSCORES
immutableConstructor-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 immutable in 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.