[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-openzeppelin-upgrade-solidity-contracts":3,"mdc--82ju64-key":36,"related-repo-openzeppelin-upgrade-solidity-contracts":2063,"related-org-openzeppelin-upgrade-solidity-contracts":2155},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":11,"stars":25,"repoUrl":26,"updatedAt":27,"license":28,"forks":29,"topics":30,"repo":31,"sourceUrl":34,"mdContent":35},"upgrade-solidity-contracts","upgrade Solidity smart contracts with proxies","Upgrade Solidity smart contracts using OpenZeppelin proxy patterns. Use when users need to: (1) make contracts upgradeable with UUPS, Transparent, or Beacon proxies, (2) write initializers instead of constructors, (3) use the Hardhat or Foundry upgrades plugins, (4) understand storage layout rules and ERC-7201 namespaced storage, (5) validate upgrade safety, (6) manage proxy deployments and upgrades, or (7) understand upgrade restrictions between OpenZeppelin Contracts major versions.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},"openzeppelin","OpenZeppelin","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Fopenzeppelin.png",[12,16,19,22],{"name":13,"slug":14,"type":15},"Security","security","tag",{"name":17,"slug":18,"type":15},"Migration","migration",{"name":20,"slug":21,"type":15},"Smart Contracts","smart-contracts",{"name":23,"slug":24,"type":15},"Solidity","solidity",193,"https:\u002F\u002Fgithub.com\u002FOpenZeppelin\u002Fopenzeppelin-skills","2026-07-13T06:04:20.958319","AGPL-3.0-only",25,[],{"repoUrl":26,"stars":25,"forks":29,"topics":32,"description":33},[],"Agent skills for secure smart contract development with OpenZeppelin Contracts libraries","https:\u002F\u002Fgithub.com\u002FOpenZeppelin\u002Fopenzeppelin-skills\u002Ftree\u002FHEAD\u002Fskills\u002Fupgrade-solidity-contracts","---\nname: upgrade-solidity-contracts\ndescription: \"Upgrade Solidity smart contracts using OpenZeppelin proxy patterns. Use when users need to: (1) make contracts upgradeable with UUPS, Transparent, or Beacon proxies, (2) write initializers instead of constructors, (3) use the Hardhat or Foundry upgrades plugins, (4) understand storage layout rules and ERC-7201 namespaced storage, (5) validate upgrade safety, (6) manage proxy deployments and upgrades, or (7) understand upgrade restrictions between OpenZeppelin Contracts major versions.\"\nlicense: AGPL-3.0-only\nmetadata:\n  author: OpenZeppelin\n---\n\n# Solidity Upgrades\n\n## Contents\n\n- [Proxy Patterns Overview](#proxy-patterns-overview)\n- [Upgrade Restrictions Between Major Versions (v4 → v5)](#upgrade-restrictions-between-major-versions-v4--v5)\n- [Writing Upgradeable Contracts](#writing-upgradeable-contracts)\n- [Hardhat Upgrades Workflow](#hardhat-upgrades-workflow)\n- [Foundry Upgrades Workflow](#foundry-upgrades-workflow)\n- [Handling Upgrade Validation Issues](#handling-upgrade-validation-issues)\n- [Upgrade Safety Checklist](#upgrade-safety-checklist)\n\n## Proxy Patterns Overview\n\n| Pattern | Upgrade logic lives in | Best for |\n|---------|----------------------|----------|\n| **UUPS** (`UUPSUpgradeable`) | Implementation contract (override `_authorizeUpgrade`) | Most projects — lighter proxy, lower deploy gas |\n| **Transparent** | Separate `ProxyAdmin` contract | When admin\u002Fuser call separation is critical — admin cannot accidentally call implementation functions |\n| **Beacon** | Shared beacon contract | Multiple proxies sharing one implementation — upgrading the beacon atomically upgrades all proxies |\n\nAll three use EIP-1967 storage slots for the implementation address, admin, and beacon.\n\n> **Transparent proxy — v5 constructor change:** In v5, `TransparentUpgradeableProxy` automatically deploys its own `ProxyAdmin` contract and stores the admin address in an immutable variable (set at construction time, never changeable). The second constructor parameter is the **owner address** for that auto-deployed `ProxyAdmin` — do **not** pass an existing `ProxyAdmin` contract address here. Transfer of upgrade capability is handled exclusively through `ProxyAdmin` ownership. This differs from v4, where `ProxyAdmin` was deployed separately and its address was passed to the proxy constructor.\n\n## Upgrade Restrictions Between Major Versions (v4 → v5)\n\n**Upgrading a proxy's implementation from one using OpenZeppelin Contracts v4 to one using v5 is not supported.**\n\nv4 uses sequential storage (slots in declaration order); v5 uses namespaced storage (ERC-7201, structs at deterministic slots). A v5 implementation cannot safely read state written by a v4 implementation. Manual data migration is theoretically possible but often infeasible — `mapping` entries cannot be enumerated, so values written under arbitrary keys cannot be relocated.\n\n**Recommended approach:** Deploy new proxies with v5 implementations and migrate users to the new address — do not upgrade proxies that currently point to v4 implementations.\n\n**Updating your codebase to v5 is encouraged.** The restriction above applies only to already-deployed proxies. New deployments built on v5, and upgrades within the same major version, are fully supported.\n\n## Writing Upgradeable Contracts\n\n### Use initializers instead of constructors\n\nProxy contracts delegatecall into the implementation. Constructors run only when the implementation itself is deployed, not when a proxy is created. Replace constructors with initializer functions:\n\n```solidity\nimport {Initializable} from \"@openzeppelin\u002Fcontracts\u002Fproxy\u002Futils\u002FInitializable.sol\";\n\ncontract MyToken is Initializable, ERC20Upgradeable, OwnableUpgradeable {\n    \u002F\u002F\u002F @custom:oz-upgrades-unsafe-allow constructor\n    constructor() {\n        _disableInitializers(); \u002F\u002F lock the implementation\n    }\n\n    function initialize(address initialOwner) public initializer {\n        __ERC20_init(\"MyToken\", \"MTK\");\n        __Ownable_init(initialOwner);\n    }\n}\n```\n\nKey rules:\n- Top-level `initialize` uses the `initializer` modifier\n- Parent init functions (`__X_init`) use `onlyInitializing` internally — call them explicitly, the compiler does not auto-linearize initializers like constructors\n- Always call `_disableInitializers()` in a constructor to prevent attackers from initializing the implementation directly\n- Do not set initial values in field declarations (e.g., `uint256 x = 42`) — these compile into the constructor and won't execute for the proxy. `constant` is safe (inlined at compile time). `immutable` values are stored in bytecode and shared across all proxies — the plugins flag them as unsafe by default; use `\u002F\u002F\u002F @custom:oz-upgrades-unsafe-allow state-variable-immutable` to opt in when a shared value is intended\n\n### Use the upgradeable package\n\nImport from `@openzeppelin\u002Fcontracts-upgradeable` for base contracts (e.g., `ERC20Upgradeable`, `OwnableUpgradeable`). Import interfaces and libraries from `@openzeppelin\u002Fcontracts`. In v5.5+, `Initializable` and `UUPSUpgradeable` should also be imported directly from `@openzeppelin\u002Fcontracts` — aliases in the upgradeable package will be removed in the next major release.\n\n### Storage layout rules\n\nWhen upgrading, the new implementation must be storage-compatible with the old one:\n\n- **Never** reorder, remove, or change the type of existing state variables\n- **Never** insert new variables before existing ones\n- **Only** append new variables at the end\n- **Never** change the inheritance order of base contracts\n\n### Namespaced storage (ERC-7201)\n\nThe modern approach — all `@openzeppelin\u002Fcontracts-upgradeable` contracts (v5+) use this. State variables are grouped into a struct at a deterministic storage slot, isolating each contract's storage and eliminating the need for storage gaps. Recommended for all contracts that may be imported as base contracts.\n\n```solidity\n\u002F\u002F\u002F @custom:storage-location erc7201:example.main\nstruct MainStorage {\n    uint256 value;\n    mapping(address => uint256) balances;\n}\n\n\u002F\u002F keccak256(abi.encode(uint256(keccak256(\"example.main\")) - 1)) & ~bytes32(uint256(0xff))\nbytes32 private constant MAIN_STORAGE_LOCATION = 0x...;\n\nfunction _getMainStorage() private pure returns (MainStorage storage $) {\n    assembly { $.slot := MAIN_STORAGE_LOCATION }\n}\n```\n\nUsing a variable from namespaced storage:\n```solidity\nfunction _getBalance(address account) internal view returns (uint256) {\n    MainStorage storage $ = _getMainStorage();\n    return $.balances[account];\n}\n```\n\nBenefits over legacy storage gaps: safe to add variables to base contracts, inheritance order changes don't break layout, each contract's storage is fully isolated.\n\nWhen upgrading, never remove a namespace by dropping it from the inheritance chain. The plugin flags deleted namespaces as an error — the state stored in that namespace becomes orphaned: the data remains on-chain but the new implementation has no way to read or write it. If a namespace is no longer actively used, keep the old contract in the inheritance chain. An unused namespace adds no runtime cost and causes no storage conflict. There is no targeted flag to suppress this error; the only bypass is `unsafeSkipStorageCheck`, which disables all storage layout compatibility checks and is a dangerous last resort.\n\n#### Computing ERC-7201 storage locations\n\nWhen generating namespaced storage code, always compute the actual `STORAGE_LOCATION` constant. **Use the Bash tool to run the command below** with the actual namespace id and embed the computed value directly in the generated code. Never leave placeholder values like `0x...`.\n\nThe formula is: `keccak256(abi.encode(uint256(keccak256(id)) - 1)) & ~bytes32(uint256(0xff))` where `id` is the namespace string (e.g., `\"example.main\"`).\n\n**Node.js with ethers**:\n\n```bash\nnode -e \"const{keccak256,toUtf8Bytes,zeroPadValue,toBeHex}=require('ethers');const id=process.argv[1];const h=BigInt(keccak256(toUtf8Bytes(id)))-1n;console.log(toBeHex(BigInt(keccak256(zeroPadValue(toBeHex(h),32)))&~0xffn,32))\" \"example.main\"\n```\n\nReplace `\"example.main\"` with the actual namespace id, run the command, and use the output as the constant value.\n\n### Unsafe operations\n\n- **No `selfdestruct`** — on pre-Dencun chains, destroys the implementation and bricks all proxies. Post-Dencun (EIP-6780), `selfdestruct` only destroys code if called in the same transaction as creation, but the plugins still flag it as unsafe\n- **No `delegatecall`** to untrusted contracts — a malicious target could `selfdestruct` or corrupt storage\n\nAdditionally, avoid using `new` to create contracts inside an upgradeable contract — the created contract won't be upgradeable. Inject pre-deployed addresses instead.\n\n## Hardhat Upgrades Workflow\n\nInstall the plugin:\n\n```bash\nnpm install --save-dev @openzeppelin\u002Fhardhat-upgrades\nnpm install --save-dev @nomicfoundation\u002Fhardhat-ethers ethers  # peer dependencies\n```\n\nRegister in `hardhat.config`:\n\n```javascript\nrequire('@openzeppelin\u002Fhardhat-upgrades'); \u002F\u002F JS\nimport '@openzeppelin\u002Fhardhat-upgrades';   \u002F\u002F TS\n```\n\nWorkflow concept — the plugin provides functions on the `upgrades` object (`deployProxy`, `upgradeProxy`, `deployBeacon`, `upgradeBeacon`, `deployBeaconProxy`). Each function:\n1. Validates the implementation for upgrade safety (storage layout, initializer patterns, unsafe opcodes)\n2. Deploys the implementation (reuses if already deployed)\n3. Deploys or updates the proxy\u002Fbeacon\n4. Calls the initializer (on deploy)\n\nThe plugin tracks deployed implementations in `.openzeppelin\u002F` per-network files. Commit non-development network files to version control.\n\nUse `prepareUpgrade` to validate and deploy a new implementation without executing the upgrade — useful when a multisig or governance contract holds upgrade rights.\n\n> Read the installed plugin's README or source for exact API signatures and options, as these evolve across versions.\n\n## Foundry Upgrades Workflow\n\nInstall dependencies:\n\n```bash\nforge install foundry-rs\u002Fforge-std\nforge install OpenZeppelin\u002Fopenzeppelin-foundry-upgrades\nforge install OpenZeppelin\u002Fopenzeppelin-contracts-upgradeable\n```\n\nConfigure `foundry.toml`:\n\n```toml\n[profile.default]\nffi = true\nast = true\nbuild_info = true\nextra_output = [\"storageLayout\"]\n```\n\n> Node.js is required — the library shells out to the OpenZeppelin Upgrades CLI for validation.\n\nImport and use in scripts\u002Ftests:\n\n```solidity\nimport {Upgrades} from \"openzeppelin-foundry-upgrades\u002FUpgrades.sol\";\n\n\u002F\u002F Deploy\naddress proxy = Upgrades.deployUUPSProxy(\n    \"MyContract.sol\",\n    abi.encodeCall(MyContract.initialize, (args))\n);\n\n\u002F\u002F IMPORTANT: Before upgrading, annotate MyContractV2 with: \u002F\u002F\u002F @custom:oz-upgrades-from MyContract\n\n\u002F\u002F Upgrade and call a function\nUpgrades.upgradeProxy(proxy, \"MyContractV2.sol\", abi.encodeCall(MyContractV2.foo, (\"arguments for foo\")));\n\n\u002F\u002F Upgrade without calling a function\nUpgrades.upgradeProxy(proxy, \"MyContractV2.sol\", \"\");\n```\n\nKey differences from Hardhat:\n- Contracts are referenced by name string, not factory object\n- No automatic implementation tracking — annotate new versions with `@custom:oz-upgrades-from` or pass `referenceContract` in the `Options` struct\n- `UnsafeUpgrades` variant skips all validation (takes addresses instead of names) — never use in production scripts\n- Run `forge clean` or use `--force` before running scripts\n\n> Read the installed library's `Upgrades.sol` for the full API and `Options` struct.\n\n## Handling Upgrade Validation Issues\n\nWhen the plugins flag a warning or error, work through this hierarchy:\n\n1. **Fix the root cause.** Determine whether the code can be restructured to eliminate the concern entirely — remove the problematic pattern or refactor storage. This is always the right first step.\n2. **Use in-code annotations if the situation is genuinely safe.** If restructuring isn't appropriate and you've determined the flagged pattern is actually safe, the plugins support annotations that let you document that judgment directly at the source. Check the installed plugin's docs for what's available. These annotations create a clear audit trail of intentional exceptions — use them only after evaluating the safety, not as a shortcut.\n3. **Use a narrow flag if an annotation won't work.** Some cases (e.g., a third-party base contract you can't modify) can't be addressed in source. Use the most targeted flag available, scoped to the specific construct.\n4. **Broad bypass as a last resort, with full awareness of the risk.** Options like `UnsafeUpgrades` (Foundry) or blanket `unsafeAllow` entries skip all validation for the affected scope. If you use them, comment why, and verify manually — the plugin is no longer protecting you.\n\n## Upgrade Safety Checklist\n\n- [ ] **Storage compatibility**: No reordering, removal, or type changes of existing variables. Only append new variables (or add fields to namespaced structs).\n- [ ] **Initializer protection**: Top-level `initialize` uses `initializer` modifier. Implementation constructor calls `_disableInitializers()`.\n- [ ] **Parent initializers called**: Every inherited upgradeable contract's `__X_init` is called exactly once in `initialize`.\n- [ ] **No unsafe opcodes**: No `selfdestruct` or `delegatecall` to untrusted targets.\n- [ ] **Function selector clashes**: Proxy admin functions and implementation functions must not share selectors. UUPS and Transparent patterns handle this by design; custom proxies need manual review.\n- [ ] **UUPS `_authorizeUpgrade`**: Overridden with proper access control (e.g., `onlyOwner`). Forgetting this makes the proxy non-upgradeable or upgradeable by anyone.\n- [ ] **Test the upgrade path**: Deploy V1, upgrade to V2, verify state is preserved and new logic works. Both Hardhat and Foundry plugins can validate upgrades in test suites.\n- [ ] **Reinitializer for V2+**: If V2 needs new initialization logic, use `reinitializer(2)` modifier (not `initializer`, which can only run once).\n- [ ] **Unique ERC-7201 namespace ids**: No two contracts in the inheritance chain share the same namespace id. Colliding ids map to the same storage slot, causing silent storage corruption.\n",{"data":37,"body":39},{"name":4,"description":6,"license":28,"metadata":38},{"author":9},{"type":40,"children":41},"root",[42,51,58,127,132,255,261,332,337,345,358,368,378,383,390,395,523,528,623,629,688,694,699,740,746,758,857,862,900,905,918,925,953,982,992,1046,1058,1064,1112,1125,1130,1135,1196,1208,1291,1340,1364,1377,1390,1398,1403,1408,1464,1476,1525,1533,1538,1668,1673,1742,1765,1770,1775,1833,1838,2057],{"type":43,"tag":44,"props":45,"children":47},"element","h1",{"id":46},"solidity-upgrades",[48],{"type":49,"value":50},"text","Solidity Upgrades",{"type":43,"tag":52,"props":53,"children":55},"h2",{"id":54},"contents",[56],{"type":49,"value":57},"Contents",{"type":43,"tag":59,"props":60,"children":61},"ul",{},[62,73,82,91,100,109,118],{"type":43,"tag":63,"props":64,"children":65},"li",{},[66],{"type":43,"tag":67,"props":68,"children":70},"a",{"href":69},"#proxy-patterns-overview",[71],{"type":49,"value":72},"Proxy Patterns Overview",{"type":43,"tag":63,"props":74,"children":75},{},[76],{"type":43,"tag":67,"props":77,"children":79},{"href":78},"#upgrade-restrictions-between-major-versions-v4--v5",[80],{"type":49,"value":81},"Upgrade Restrictions Between Major Versions (v4 → v5)",{"type":43,"tag":63,"props":83,"children":84},{},[85],{"type":43,"tag":67,"props":86,"children":88},{"href":87},"#writing-upgradeable-contracts",[89],{"type":49,"value":90},"Writing Upgradeable Contracts",{"type":43,"tag":63,"props":92,"children":93},{},[94],{"type":43,"tag":67,"props":95,"children":97},{"href":96},"#hardhat-upgrades-workflow",[98],{"type":49,"value":99},"Hardhat Upgrades Workflow",{"type":43,"tag":63,"props":101,"children":102},{},[103],{"type":43,"tag":67,"props":104,"children":106},{"href":105},"#foundry-upgrades-workflow",[107],{"type":49,"value":108},"Foundry Upgrades Workflow",{"type":43,"tag":63,"props":110,"children":111},{},[112],{"type":43,"tag":67,"props":113,"children":115},{"href":114},"#handling-upgrade-validation-issues",[116],{"type":49,"value":117},"Handling Upgrade Validation Issues",{"type":43,"tag":63,"props":119,"children":120},{},[121],{"type":43,"tag":67,"props":122,"children":124},{"href":123},"#upgrade-safety-checklist",[125],{"type":49,"value":126},"Upgrade Safety Checklist",{"type":43,"tag":52,"props":128,"children":130},{"id":129},"proxy-patterns-overview",[131],{"type":49,"value":72},{"type":43,"tag":133,"props":134,"children":135},"table",{},[136,160],{"type":43,"tag":137,"props":138,"children":139},"thead",{},[140],{"type":43,"tag":141,"props":142,"children":143},"tr",{},[144,150,155],{"type":43,"tag":145,"props":146,"children":147},"th",{},[148],{"type":49,"value":149},"Pattern",{"type":43,"tag":145,"props":151,"children":152},{},[153],{"type":49,"value":154},"Upgrade logic lives in",{"type":43,"tag":145,"props":156,"children":157},{},[158],{"type":49,"value":159},"Best for",{"type":43,"tag":161,"props":162,"children":163},"tbody",{},[164,205,234],{"type":43,"tag":141,"props":165,"children":166},{},[167,188,200],{"type":43,"tag":168,"props":169,"children":170},"td",{},[171,177,179,186],{"type":43,"tag":172,"props":173,"children":174},"strong",{},[175],{"type":49,"value":176},"UUPS",{"type":49,"value":178}," (",{"type":43,"tag":180,"props":181,"children":183},"code",{"className":182},[],[184],{"type":49,"value":185},"UUPSUpgradeable",{"type":49,"value":187},")",{"type":43,"tag":168,"props":189,"children":190},{},[191,193,199],{"type":49,"value":192},"Implementation contract (override ",{"type":43,"tag":180,"props":194,"children":196},{"className":195},[],[197],{"type":49,"value":198},"_authorizeUpgrade",{"type":49,"value":187},{"type":43,"tag":168,"props":201,"children":202},{},[203],{"type":49,"value":204},"Most projects — lighter proxy, lower deploy gas",{"type":43,"tag":141,"props":206,"children":207},{},[208,216,229],{"type":43,"tag":168,"props":209,"children":210},{},[211],{"type":43,"tag":172,"props":212,"children":213},{},[214],{"type":49,"value":215},"Transparent",{"type":43,"tag":168,"props":217,"children":218},{},[219,221,227],{"type":49,"value":220},"Separate ",{"type":43,"tag":180,"props":222,"children":224},{"className":223},[],[225],{"type":49,"value":226},"ProxyAdmin",{"type":49,"value":228}," contract",{"type":43,"tag":168,"props":230,"children":231},{},[232],{"type":49,"value":233},"When admin\u002Fuser call separation is critical — admin cannot accidentally call implementation functions",{"type":43,"tag":141,"props":235,"children":236},{},[237,245,250],{"type":43,"tag":168,"props":238,"children":239},{},[240],{"type":43,"tag":172,"props":241,"children":242},{},[243],{"type":49,"value":244},"Beacon",{"type":43,"tag":168,"props":246,"children":247},{},[248],{"type":49,"value":249},"Shared beacon contract",{"type":43,"tag":168,"props":251,"children":252},{},[253],{"type":49,"value":254},"Multiple proxies sharing one implementation — upgrading the beacon atomically upgrades all proxies",{"type":43,"tag":256,"props":257,"children":258},"p",{},[259],{"type":49,"value":260},"All three use EIP-1967 storage slots for the implementation address, admin, and beacon.",{"type":43,"tag":262,"props":263,"children":264},"blockquote",{},[265],{"type":43,"tag":256,"props":266,"children":267},{},[268,273,275,281,283,288,290,295,297,302,304,309,311,316,318,323,325,330],{"type":43,"tag":172,"props":269,"children":270},{},[271],{"type":49,"value":272},"Transparent proxy — v5 constructor change:",{"type":49,"value":274}," In v5, ",{"type":43,"tag":180,"props":276,"children":278},{"className":277},[],[279],{"type":49,"value":280},"TransparentUpgradeableProxy",{"type":49,"value":282}," automatically deploys its own ",{"type":43,"tag":180,"props":284,"children":286},{"className":285},[],[287],{"type":49,"value":226},{"type":49,"value":289}," contract and stores the admin address in an immutable variable (set at construction time, never changeable). The second constructor parameter is the ",{"type":43,"tag":172,"props":291,"children":292},{},[293],{"type":49,"value":294},"owner address",{"type":49,"value":296}," for that auto-deployed ",{"type":43,"tag":180,"props":298,"children":300},{"className":299},[],[301],{"type":49,"value":226},{"type":49,"value":303}," — do ",{"type":43,"tag":172,"props":305,"children":306},{},[307],{"type":49,"value":308},"not",{"type":49,"value":310}," pass an existing ",{"type":43,"tag":180,"props":312,"children":314},{"className":313},[],[315],{"type":49,"value":226},{"type":49,"value":317}," contract address here. Transfer of upgrade capability is handled exclusively through ",{"type":43,"tag":180,"props":319,"children":321},{"className":320},[],[322],{"type":49,"value":226},{"type":49,"value":324}," ownership. This differs from v4, where ",{"type":43,"tag":180,"props":326,"children":328},{"className":327},[],[329],{"type":49,"value":226},{"type":49,"value":331}," was deployed separately and its address was passed to the proxy constructor.",{"type":43,"tag":52,"props":333,"children":335},{"id":334},"upgrade-restrictions-between-major-versions-v4-v5",[336],{"type":49,"value":81},{"type":43,"tag":256,"props":338,"children":339},{},[340],{"type":43,"tag":172,"props":341,"children":342},{},[343],{"type":49,"value":344},"Upgrading a proxy's implementation from one using OpenZeppelin Contracts v4 to one using v5 is not supported.",{"type":43,"tag":256,"props":346,"children":347},{},[348,350,356],{"type":49,"value":349},"v4 uses sequential storage (slots in declaration order); v5 uses namespaced storage (ERC-7201, structs at deterministic slots). A v5 implementation cannot safely read state written by a v4 implementation. Manual data migration is theoretically possible but often infeasible — ",{"type":43,"tag":180,"props":351,"children":353},{"className":352},[],[354],{"type":49,"value":355},"mapping",{"type":49,"value":357}," entries cannot be enumerated, so values written under arbitrary keys cannot be relocated.",{"type":43,"tag":256,"props":359,"children":360},{},[361,366],{"type":43,"tag":172,"props":362,"children":363},{},[364],{"type":49,"value":365},"Recommended approach:",{"type":49,"value":367}," Deploy new proxies with v5 implementations and migrate users to the new address — do not upgrade proxies that currently point to v4 implementations.",{"type":43,"tag":256,"props":369,"children":370},{},[371,376],{"type":43,"tag":172,"props":372,"children":373},{},[374],{"type":49,"value":375},"Updating your codebase to v5 is encouraged.",{"type":49,"value":377}," The restriction above applies only to already-deployed proxies. New deployments built on v5, and upgrades within the same major version, are fully supported.",{"type":43,"tag":52,"props":379,"children":381},{"id":380},"writing-upgradeable-contracts",[382],{"type":49,"value":90},{"type":43,"tag":384,"props":385,"children":387},"h3",{"id":386},"use-initializers-instead-of-constructors",[388],{"type":49,"value":389},"Use initializers instead of constructors",{"type":43,"tag":256,"props":391,"children":392},{},[393],{"type":49,"value":394},"Proxy contracts delegatecall into the implementation. Constructors run only when the implementation itself is deployed, not when a proxy is created. Replace constructors with initializer functions:",{"type":43,"tag":396,"props":397,"children":401},"pre",{"className":398,"code":399,"language":24,"meta":400,"style":400},"language-solidity shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import {Initializable} from \"@openzeppelin\u002Fcontracts\u002Fproxy\u002Futils\u002FInitializable.sol\";\n\ncontract MyToken is Initializable, ERC20Upgradeable, OwnableUpgradeable {\n    \u002F\u002F\u002F @custom:oz-upgrades-unsafe-allow constructor\n    constructor() {\n        _disableInitializers(); \u002F\u002F lock the implementation\n    }\n\n    function initialize(address initialOwner) public initializer {\n        __ERC20_init(\"MyToken\", \"MTK\");\n        __Ownable_init(initialOwner);\n    }\n}\n","",[402],{"type":43,"tag":180,"props":403,"children":404},{"__ignoreMap":400},[405,416,426,435,444,453,462,471,479,488,497,506,514],{"type":43,"tag":406,"props":407,"children":410},"span",{"class":408,"line":409},"line",1,[411],{"type":43,"tag":406,"props":412,"children":413},{},[414],{"type":49,"value":415},"import {Initializable} from \"@openzeppelin\u002Fcontracts\u002Fproxy\u002Futils\u002FInitializable.sol\";\n",{"type":43,"tag":406,"props":417,"children":419},{"class":408,"line":418},2,[420],{"type":43,"tag":406,"props":421,"children":423},{"emptyLinePlaceholder":422},true,[424],{"type":49,"value":425},"\n",{"type":43,"tag":406,"props":427,"children":429},{"class":408,"line":428},3,[430],{"type":43,"tag":406,"props":431,"children":432},{},[433],{"type":49,"value":434},"contract MyToken is Initializable, ERC20Upgradeable, OwnableUpgradeable {\n",{"type":43,"tag":406,"props":436,"children":438},{"class":408,"line":437},4,[439],{"type":43,"tag":406,"props":440,"children":441},{},[442],{"type":49,"value":443},"    \u002F\u002F\u002F @custom:oz-upgrades-unsafe-allow constructor\n",{"type":43,"tag":406,"props":445,"children":447},{"class":408,"line":446},5,[448],{"type":43,"tag":406,"props":449,"children":450},{},[451],{"type":49,"value":452},"    constructor() {\n",{"type":43,"tag":406,"props":454,"children":456},{"class":408,"line":455},6,[457],{"type":43,"tag":406,"props":458,"children":459},{},[460],{"type":49,"value":461},"        _disableInitializers(); \u002F\u002F lock the implementation\n",{"type":43,"tag":406,"props":463,"children":465},{"class":408,"line":464},7,[466],{"type":43,"tag":406,"props":467,"children":468},{},[469],{"type":49,"value":470},"    }\n",{"type":43,"tag":406,"props":472,"children":474},{"class":408,"line":473},8,[475],{"type":43,"tag":406,"props":476,"children":477},{"emptyLinePlaceholder":422},[478],{"type":49,"value":425},{"type":43,"tag":406,"props":480,"children":482},{"class":408,"line":481},9,[483],{"type":43,"tag":406,"props":484,"children":485},{},[486],{"type":49,"value":487},"    function initialize(address initialOwner) public initializer {\n",{"type":43,"tag":406,"props":489,"children":491},{"class":408,"line":490},10,[492],{"type":43,"tag":406,"props":493,"children":494},{},[495],{"type":49,"value":496},"        __ERC20_init(\"MyToken\", \"MTK\");\n",{"type":43,"tag":406,"props":498,"children":500},{"class":408,"line":499},11,[501],{"type":43,"tag":406,"props":502,"children":503},{},[504],{"type":49,"value":505},"        __Ownable_init(initialOwner);\n",{"type":43,"tag":406,"props":507,"children":509},{"class":408,"line":508},12,[510],{"type":43,"tag":406,"props":511,"children":512},{},[513],{"type":49,"value":470},{"type":43,"tag":406,"props":515,"children":517},{"class":408,"line":516},13,[518],{"type":43,"tag":406,"props":519,"children":520},{},[521],{"type":49,"value":522},"}\n",{"type":43,"tag":256,"props":524,"children":525},{},[526],{"type":49,"value":527},"Key rules:",{"type":43,"tag":59,"props":529,"children":530},{},[531,552,573,586],{"type":43,"tag":63,"props":532,"children":533},{},[534,536,542,544,550],{"type":49,"value":535},"Top-level ",{"type":43,"tag":180,"props":537,"children":539},{"className":538},[],[540],{"type":49,"value":541},"initialize",{"type":49,"value":543}," uses the ",{"type":43,"tag":180,"props":545,"children":547},{"className":546},[],[548],{"type":49,"value":549},"initializer",{"type":49,"value":551}," modifier",{"type":43,"tag":63,"props":553,"children":554},{},[555,557,563,565,571],{"type":49,"value":556},"Parent init functions (",{"type":43,"tag":180,"props":558,"children":560},{"className":559},[],[561],{"type":49,"value":562},"__X_init",{"type":49,"value":564},") use ",{"type":43,"tag":180,"props":566,"children":568},{"className":567},[],[569],{"type":49,"value":570},"onlyInitializing",{"type":49,"value":572}," internally — call them explicitly, the compiler does not auto-linearize initializers like constructors",{"type":43,"tag":63,"props":574,"children":575},{},[576,578,584],{"type":49,"value":577},"Always call ",{"type":43,"tag":180,"props":579,"children":581},{"className":580},[],[582],{"type":49,"value":583},"_disableInitializers()",{"type":49,"value":585}," in a constructor to prevent attackers from initializing the implementation directly",{"type":43,"tag":63,"props":587,"children":588},{},[589,591,597,599,605,607,613,615,621],{"type":49,"value":590},"Do not set initial values in field declarations (e.g., ",{"type":43,"tag":180,"props":592,"children":594},{"className":593},[],[595],{"type":49,"value":596},"uint256 x = 42",{"type":49,"value":598},") — these compile into the constructor and won't execute for the proxy. ",{"type":43,"tag":180,"props":600,"children":602},{"className":601},[],[603],{"type":49,"value":604},"constant",{"type":49,"value":606}," is safe (inlined at compile time). ",{"type":43,"tag":180,"props":608,"children":610},{"className":609},[],[611],{"type":49,"value":612},"immutable",{"type":49,"value":614}," values are stored in bytecode and shared across all proxies — the plugins flag them as unsafe by default; use ",{"type":43,"tag":180,"props":616,"children":618},{"className":617},[],[619],{"type":49,"value":620},"\u002F\u002F\u002F @custom:oz-upgrades-unsafe-allow state-variable-immutable",{"type":49,"value":622}," to opt in when a shared value is intended",{"type":43,"tag":384,"props":624,"children":626},{"id":625},"use-the-upgradeable-package",[627],{"type":49,"value":628},"Use the upgradeable package",{"type":43,"tag":256,"props":630,"children":631},{},[632,634,640,642,648,650,656,658,664,666,672,674,679,681,686],{"type":49,"value":633},"Import from ",{"type":43,"tag":180,"props":635,"children":637},{"className":636},[],[638],{"type":49,"value":639},"@openzeppelin\u002Fcontracts-upgradeable",{"type":49,"value":641}," for base contracts (e.g., ",{"type":43,"tag":180,"props":643,"children":645},{"className":644},[],[646],{"type":49,"value":647},"ERC20Upgradeable",{"type":49,"value":649},", ",{"type":43,"tag":180,"props":651,"children":653},{"className":652},[],[654],{"type":49,"value":655},"OwnableUpgradeable",{"type":49,"value":657},"). Import interfaces and libraries from ",{"type":43,"tag":180,"props":659,"children":661},{"className":660},[],[662],{"type":49,"value":663},"@openzeppelin\u002Fcontracts",{"type":49,"value":665},". In v5.5+, ",{"type":43,"tag":180,"props":667,"children":669},{"className":668},[],[670],{"type":49,"value":671},"Initializable",{"type":49,"value":673}," and ",{"type":43,"tag":180,"props":675,"children":677},{"className":676},[],[678],{"type":49,"value":185},{"type":49,"value":680}," should also be imported directly from ",{"type":43,"tag":180,"props":682,"children":684},{"className":683},[],[685],{"type":49,"value":663},{"type":49,"value":687}," — aliases in the upgradeable package will be removed in the next major release.",{"type":43,"tag":384,"props":689,"children":691},{"id":690},"storage-layout-rules",[692],{"type":49,"value":693},"Storage layout rules",{"type":43,"tag":256,"props":695,"children":696},{},[697],{"type":49,"value":698},"When upgrading, the new implementation must be storage-compatible with the old one:",{"type":43,"tag":59,"props":700,"children":701},{},[702,712,721,731],{"type":43,"tag":63,"props":703,"children":704},{},[705,710],{"type":43,"tag":172,"props":706,"children":707},{},[708],{"type":49,"value":709},"Never",{"type":49,"value":711}," reorder, remove, or change the type of existing state variables",{"type":43,"tag":63,"props":713,"children":714},{},[715,719],{"type":43,"tag":172,"props":716,"children":717},{},[718],{"type":49,"value":709},{"type":49,"value":720}," insert new variables before existing ones",{"type":43,"tag":63,"props":722,"children":723},{},[724,729],{"type":43,"tag":172,"props":725,"children":726},{},[727],{"type":49,"value":728},"Only",{"type":49,"value":730}," append new variables at the end",{"type":43,"tag":63,"props":732,"children":733},{},[734,738],{"type":43,"tag":172,"props":735,"children":736},{},[737],{"type":49,"value":709},{"type":49,"value":739}," change the inheritance order of base contracts",{"type":43,"tag":384,"props":741,"children":743},{"id":742},"namespaced-storage-erc-7201",[744],{"type":49,"value":745},"Namespaced storage (ERC-7201)",{"type":43,"tag":256,"props":747,"children":748},{},[749,751,756],{"type":49,"value":750},"The modern approach — all ",{"type":43,"tag":180,"props":752,"children":754},{"className":753},[],[755],{"type":49,"value":639},{"type":49,"value":757}," contracts (v5+) use this. State variables are grouped into a struct at a deterministic storage slot, isolating each contract's storage and eliminating the need for storage gaps. Recommended for all contracts that may be imported as base contracts.",{"type":43,"tag":396,"props":759,"children":761},{"className":398,"code":760,"language":24,"meta":400,"style":400},"\u002F\u002F\u002F @custom:storage-location erc7201:example.main\nstruct MainStorage {\n    uint256 value;\n    mapping(address => uint256) balances;\n}\n\n\u002F\u002F keccak256(abi.encode(uint256(keccak256(\"example.main\")) - 1)) & ~bytes32(uint256(0xff))\nbytes32 private constant MAIN_STORAGE_LOCATION = 0x...;\n\nfunction _getMainStorage() private pure returns (MainStorage storage $) {\n    assembly { $.slot := MAIN_STORAGE_LOCATION }\n}\n",[762],{"type":43,"tag":180,"props":763,"children":764},{"__ignoreMap":400},[765,773,781,789,797,804,811,819,827,834,842,850],{"type":43,"tag":406,"props":766,"children":767},{"class":408,"line":409},[768],{"type":43,"tag":406,"props":769,"children":770},{},[771],{"type":49,"value":772},"\u002F\u002F\u002F @custom:storage-location erc7201:example.main\n",{"type":43,"tag":406,"props":774,"children":775},{"class":408,"line":418},[776],{"type":43,"tag":406,"props":777,"children":778},{},[779],{"type":49,"value":780},"struct MainStorage {\n",{"type":43,"tag":406,"props":782,"children":783},{"class":408,"line":428},[784],{"type":43,"tag":406,"props":785,"children":786},{},[787],{"type":49,"value":788},"    uint256 value;\n",{"type":43,"tag":406,"props":790,"children":791},{"class":408,"line":437},[792],{"type":43,"tag":406,"props":793,"children":794},{},[795],{"type":49,"value":796},"    mapping(address => uint256) balances;\n",{"type":43,"tag":406,"props":798,"children":799},{"class":408,"line":446},[800],{"type":43,"tag":406,"props":801,"children":802},{},[803],{"type":49,"value":522},{"type":43,"tag":406,"props":805,"children":806},{"class":408,"line":455},[807],{"type":43,"tag":406,"props":808,"children":809},{"emptyLinePlaceholder":422},[810],{"type":49,"value":425},{"type":43,"tag":406,"props":812,"children":813},{"class":408,"line":464},[814],{"type":43,"tag":406,"props":815,"children":816},{},[817],{"type":49,"value":818},"\u002F\u002F keccak256(abi.encode(uint256(keccak256(\"example.main\")) - 1)) & ~bytes32(uint256(0xff))\n",{"type":43,"tag":406,"props":820,"children":821},{"class":408,"line":473},[822],{"type":43,"tag":406,"props":823,"children":824},{},[825],{"type":49,"value":826},"bytes32 private constant MAIN_STORAGE_LOCATION = 0x...;\n",{"type":43,"tag":406,"props":828,"children":829},{"class":408,"line":481},[830],{"type":43,"tag":406,"props":831,"children":832},{"emptyLinePlaceholder":422},[833],{"type":49,"value":425},{"type":43,"tag":406,"props":835,"children":836},{"class":408,"line":490},[837],{"type":43,"tag":406,"props":838,"children":839},{},[840],{"type":49,"value":841},"function _getMainStorage() private pure returns (MainStorage storage $) {\n",{"type":43,"tag":406,"props":843,"children":844},{"class":408,"line":499},[845],{"type":43,"tag":406,"props":846,"children":847},{},[848],{"type":49,"value":849},"    assembly { $.slot := MAIN_STORAGE_LOCATION }\n",{"type":43,"tag":406,"props":851,"children":852},{"class":408,"line":508},[853],{"type":43,"tag":406,"props":854,"children":855},{},[856],{"type":49,"value":522},{"type":43,"tag":256,"props":858,"children":859},{},[860],{"type":49,"value":861},"Using a variable from namespaced storage:",{"type":43,"tag":396,"props":863,"children":865},{"className":398,"code":864,"language":24,"meta":400,"style":400},"function _getBalance(address account) internal view returns (uint256) {\n    MainStorage storage $ = _getMainStorage();\n    return $.balances[account];\n}\n",[866],{"type":43,"tag":180,"props":867,"children":868},{"__ignoreMap":400},[869,877,885,893],{"type":43,"tag":406,"props":870,"children":871},{"class":408,"line":409},[872],{"type":43,"tag":406,"props":873,"children":874},{},[875],{"type":49,"value":876},"function _getBalance(address account) internal view returns (uint256) {\n",{"type":43,"tag":406,"props":878,"children":879},{"class":408,"line":418},[880],{"type":43,"tag":406,"props":881,"children":882},{},[883],{"type":49,"value":884},"    MainStorage storage $ = _getMainStorage();\n",{"type":43,"tag":406,"props":886,"children":887},{"class":408,"line":428},[888],{"type":43,"tag":406,"props":889,"children":890},{},[891],{"type":49,"value":892},"    return $.balances[account];\n",{"type":43,"tag":406,"props":894,"children":895},{"class":408,"line":437},[896],{"type":43,"tag":406,"props":897,"children":898},{},[899],{"type":49,"value":522},{"type":43,"tag":256,"props":901,"children":902},{},[903],{"type":49,"value":904},"Benefits over legacy storage gaps: safe to add variables to base contracts, inheritance order changes don't break layout, each contract's storage is fully isolated.",{"type":43,"tag":256,"props":906,"children":907},{},[908,910,916],{"type":49,"value":909},"When upgrading, never remove a namespace by dropping it from the inheritance chain. The plugin flags deleted namespaces as an error — the state stored in that namespace becomes orphaned: the data remains on-chain but the new implementation has no way to read or write it. If a namespace is no longer actively used, keep the old contract in the inheritance chain. An unused namespace adds no runtime cost and causes no storage conflict. There is no targeted flag to suppress this error; the only bypass is ",{"type":43,"tag":180,"props":911,"children":913},{"className":912},[],[914],{"type":49,"value":915},"unsafeSkipStorageCheck",{"type":49,"value":917},", which disables all storage layout compatibility checks and is a dangerous last resort.",{"type":43,"tag":919,"props":920,"children":922},"h4",{"id":921},"computing-erc-7201-storage-locations",[923],{"type":49,"value":924},"Computing ERC-7201 storage locations",{"type":43,"tag":256,"props":926,"children":927},{},[928,930,936,938,943,945,951],{"type":49,"value":929},"When generating namespaced storage code, always compute the actual ",{"type":43,"tag":180,"props":931,"children":933},{"className":932},[],[934],{"type":49,"value":935},"STORAGE_LOCATION",{"type":49,"value":937}," constant. ",{"type":43,"tag":172,"props":939,"children":940},{},[941],{"type":49,"value":942},"Use the Bash tool to run the command below",{"type":49,"value":944}," with the actual namespace id and embed the computed value directly in the generated code. Never leave placeholder values like ",{"type":43,"tag":180,"props":946,"children":948},{"className":947},[],[949],{"type":49,"value":950},"0x...",{"type":49,"value":952},".",{"type":43,"tag":256,"props":954,"children":955},{},[956,958,964,966,972,974,980],{"type":49,"value":957},"The formula is: ",{"type":43,"tag":180,"props":959,"children":961},{"className":960},[],[962],{"type":49,"value":963},"keccak256(abi.encode(uint256(keccak256(id)) - 1)) & ~bytes32(uint256(0xff))",{"type":49,"value":965}," where ",{"type":43,"tag":180,"props":967,"children":969},{"className":968},[],[970],{"type":49,"value":971},"id",{"type":49,"value":973}," is the namespace string (e.g., ",{"type":43,"tag":180,"props":975,"children":977},{"className":976},[],[978],{"type":49,"value":979},"\"example.main\"",{"type":49,"value":981},").",{"type":43,"tag":256,"props":983,"children":984},{},[985,990],{"type":43,"tag":172,"props":986,"children":987},{},[988],{"type":49,"value":989},"Node.js with ethers",{"type":49,"value":991},":",{"type":43,"tag":396,"props":993,"children":997},{"className":994,"code":995,"language":996,"meta":400,"style":400},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","node -e \"const{keccak256,toUtf8Bytes,zeroPadValue,toBeHex}=require('ethers');const id=process.argv[1];const h=BigInt(keccak256(toUtf8Bytes(id)))-1n;console.log(toBeHex(BigInt(keccak256(zeroPadValue(toBeHex(h),32)))&~0xffn,32))\" \"example.main\"\n","bash",[998],{"type":43,"tag":180,"props":999,"children":1000},{"__ignoreMap":400},[1001],{"type":43,"tag":406,"props":1002,"children":1003},{"class":408,"line":409},[1004,1010,1016,1022,1027,1032,1036,1041],{"type":43,"tag":406,"props":1005,"children":1007},{"style":1006},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[1008],{"type":49,"value":1009},"node",{"type":43,"tag":406,"props":1011,"children":1013},{"style":1012},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[1014],{"type":49,"value":1015}," -e",{"type":43,"tag":406,"props":1017,"children":1019},{"style":1018},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[1020],{"type":49,"value":1021}," \"",{"type":43,"tag":406,"props":1023,"children":1024},{"style":1012},[1025],{"type":49,"value":1026},"const{keccak256,toUtf8Bytes,zeroPadValue,toBeHex}=require('ethers');const id=process.argv[1];const h=BigInt(keccak256(toUtf8Bytes(id)))-1n;console.log(toBeHex(BigInt(keccak256(zeroPadValue(toBeHex(h),32)))&~0xffn,32))",{"type":43,"tag":406,"props":1028,"children":1029},{"style":1018},[1030],{"type":49,"value":1031},"\"",{"type":43,"tag":406,"props":1033,"children":1034},{"style":1018},[1035],{"type":49,"value":1021},{"type":43,"tag":406,"props":1037,"children":1038},{"style":1012},[1039],{"type":49,"value":1040},"example.main",{"type":43,"tag":406,"props":1042,"children":1043},{"style":1018},[1044],{"type":49,"value":1045},"\"\n",{"type":43,"tag":256,"props":1047,"children":1048},{},[1049,1051,1056],{"type":49,"value":1050},"Replace ",{"type":43,"tag":180,"props":1052,"children":1054},{"className":1053},[],[1055],{"type":49,"value":979},{"type":49,"value":1057}," with the actual namespace id, run the command, and use the output as the constant value.",{"type":43,"tag":384,"props":1059,"children":1061},{"id":1060},"unsafe-operations",[1062],{"type":49,"value":1063},"Unsafe operations",{"type":43,"tag":59,"props":1065,"children":1066},{},[1067,1090],{"type":43,"tag":63,"props":1068,"children":1069},{},[1070,1081,1083,1088],{"type":43,"tag":172,"props":1071,"children":1072},{},[1073,1075],{"type":49,"value":1074},"No ",{"type":43,"tag":180,"props":1076,"children":1078},{"className":1077},[],[1079],{"type":49,"value":1080},"selfdestruct",{"type":49,"value":1082}," — on pre-Dencun chains, destroys the implementation and bricks all proxies. Post-Dencun (EIP-6780), ",{"type":43,"tag":180,"props":1084,"children":1086},{"className":1085},[],[1087],{"type":49,"value":1080},{"type":49,"value":1089}," only destroys code if called in the same transaction as creation, but the plugins still flag it as unsafe",{"type":43,"tag":63,"props":1091,"children":1092},{},[1093,1103,1105,1110],{"type":43,"tag":172,"props":1094,"children":1095},{},[1096,1097],{"type":49,"value":1074},{"type":43,"tag":180,"props":1098,"children":1100},{"className":1099},[],[1101],{"type":49,"value":1102},"delegatecall",{"type":49,"value":1104}," to untrusted contracts — a malicious target could ",{"type":43,"tag":180,"props":1106,"children":1108},{"className":1107},[],[1109],{"type":49,"value":1080},{"type":49,"value":1111}," or corrupt storage",{"type":43,"tag":256,"props":1113,"children":1114},{},[1115,1117,1123],{"type":49,"value":1116},"Additionally, avoid using ",{"type":43,"tag":180,"props":1118,"children":1120},{"className":1119},[],[1121],{"type":49,"value":1122},"new",{"type":49,"value":1124}," to create contracts inside an upgradeable contract — the created contract won't be upgradeable. Inject pre-deployed addresses instead.",{"type":43,"tag":52,"props":1126,"children":1128},{"id":1127},"hardhat-upgrades-workflow",[1129],{"type":49,"value":99},{"type":43,"tag":256,"props":1131,"children":1132},{},[1133],{"type":49,"value":1134},"Install the plugin:",{"type":43,"tag":396,"props":1136,"children":1138},{"className":994,"code":1137,"language":996,"meta":400,"style":400},"npm install --save-dev @openzeppelin\u002Fhardhat-upgrades\nnpm install --save-dev @nomicfoundation\u002Fhardhat-ethers ethers  # peer dependencies\n",[1139],{"type":43,"tag":180,"props":1140,"children":1141},{"__ignoreMap":400},[1142,1165],{"type":43,"tag":406,"props":1143,"children":1144},{"class":408,"line":409},[1145,1150,1155,1160],{"type":43,"tag":406,"props":1146,"children":1147},{"style":1006},[1148],{"type":49,"value":1149},"npm",{"type":43,"tag":406,"props":1151,"children":1152},{"style":1012},[1153],{"type":49,"value":1154}," install",{"type":43,"tag":406,"props":1156,"children":1157},{"style":1012},[1158],{"type":49,"value":1159}," --save-dev",{"type":43,"tag":406,"props":1161,"children":1162},{"style":1012},[1163],{"type":49,"value":1164}," @openzeppelin\u002Fhardhat-upgrades\n",{"type":43,"tag":406,"props":1166,"children":1167},{"class":408,"line":418},[1168,1172,1176,1180,1185,1190],{"type":43,"tag":406,"props":1169,"children":1170},{"style":1006},[1171],{"type":49,"value":1149},{"type":43,"tag":406,"props":1173,"children":1174},{"style":1012},[1175],{"type":49,"value":1154},{"type":43,"tag":406,"props":1177,"children":1178},{"style":1012},[1179],{"type":49,"value":1159},{"type":43,"tag":406,"props":1181,"children":1182},{"style":1012},[1183],{"type":49,"value":1184}," @nomicfoundation\u002Fhardhat-ethers",{"type":43,"tag":406,"props":1186,"children":1187},{"style":1012},[1188],{"type":49,"value":1189}," ethers",{"type":43,"tag":406,"props":1191,"children":1193},{"style":1192},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[1194],{"type":49,"value":1195},"  # peer dependencies\n",{"type":43,"tag":256,"props":1197,"children":1198},{},[1199,1201,1207],{"type":49,"value":1200},"Register in ",{"type":43,"tag":180,"props":1202,"children":1204},{"className":1203},[],[1205],{"type":49,"value":1206},"hardhat.config",{"type":49,"value":991},{"type":43,"tag":396,"props":1209,"children":1213},{"className":1210,"code":1211,"language":1212,"meta":400,"style":400},"language-javascript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","require('@openzeppelin\u002Fhardhat-upgrades'); \u002F\u002F JS\nimport '@openzeppelin\u002Fhardhat-upgrades';   \u002F\u002F TS\n","javascript",[1214],{"type":43,"tag":180,"props":1215,"children":1216},{"__ignoreMap":400},[1217,1260],{"type":43,"tag":406,"props":1218,"children":1219},{"class":408,"line":409},[1220,1226,1232,1237,1242,1246,1250,1255],{"type":43,"tag":406,"props":1221,"children":1223},{"style":1222},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[1224],{"type":49,"value":1225},"require",{"type":43,"tag":406,"props":1227,"children":1229},{"style":1228},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[1230],{"type":49,"value":1231},"(",{"type":43,"tag":406,"props":1233,"children":1234},{"style":1018},[1235],{"type":49,"value":1236},"'",{"type":43,"tag":406,"props":1238,"children":1239},{"style":1012},[1240],{"type":49,"value":1241},"@openzeppelin\u002Fhardhat-upgrades",{"type":43,"tag":406,"props":1243,"children":1244},{"style":1018},[1245],{"type":49,"value":1236},{"type":43,"tag":406,"props":1247,"children":1248},{"style":1228},[1249],{"type":49,"value":187},{"type":43,"tag":406,"props":1251,"children":1252},{"style":1018},[1253],{"type":49,"value":1254},";",{"type":43,"tag":406,"props":1256,"children":1257},{"style":1192},[1258],{"type":49,"value":1259}," \u002F\u002F JS\n",{"type":43,"tag":406,"props":1261,"children":1262},{"class":408,"line":418},[1263,1269,1274,1278,1282,1286],{"type":43,"tag":406,"props":1264,"children":1266},{"style":1265},"--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic",[1267],{"type":49,"value":1268},"import",{"type":43,"tag":406,"props":1270,"children":1271},{"style":1018},[1272],{"type":49,"value":1273}," '",{"type":43,"tag":406,"props":1275,"children":1276},{"style":1012},[1277],{"type":49,"value":1241},{"type":43,"tag":406,"props":1279,"children":1280},{"style":1018},[1281],{"type":49,"value":1236},{"type":43,"tag":406,"props":1283,"children":1284},{"style":1018},[1285],{"type":49,"value":1254},{"type":43,"tag":406,"props":1287,"children":1288},{"style":1192},[1289],{"type":49,"value":1290},"   \u002F\u002F TS\n",{"type":43,"tag":256,"props":1292,"children":1293},{},[1294,1296,1302,1304,1310,1311,1317,1318,1324,1325,1331,1332,1338],{"type":49,"value":1295},"Workflow concept — the plugin provides functions on the ",{"type":43,"tag":180,"props":1297,"children":1299},{"className":1298},[],[1300],{"type":49,"value":1301},"upgrades",{"type":49,"value":1303}," object (",{"type":43,"tag":180,"props":1305,"children":1307},{"className":1306},[],[1308],{"type":49,"value":1309},"deployProxy",{"type":49,"value":649},{"type":43,"tag":180,"props":1312,"children":1314},{"className":1313},[],[1315],{"type":49,"value":1316},"upgradeProxy",{"type":49,"value":649},{"type":43,"tag":180,"props":1319,"children":1321},{"className":1320},[],[1322],{"type":49,"value":1323},"deployBeacon",{"type":49,"value":649},{"type":43,"tag":180,"props":1326,"children":1328},{"className":1327},[],[1329],{"type":49,"value":1330},"upgradeBeacon",{"type":49,"value":649},{"type":43,"tag":180,"props":1333,"children":1335},{"className":1334},[],[1336],{"type":49,"value":1337},"deployBeaconProxy",{"type":49,"value":1339},"). Each function:",{"type":43,"tag":1341,"props":1342,"children":1343},"ol",{},[1344,1349,1354,1359],{"type":43,"tag":63,"props":1345,"children":1346},{},[1347],{"type":49,"value":1348},"Validates the implementation for upgrade safety (storage layout, initializer patterns, unsafe opcodes)",{"type":43,"tag":63,"props":1350,"children":1351},{},[1352],{"type":49,"value":1353},"Deploys the implementation (reuses if already deployed)",{"type":43,"tag":63,"props":1355,"children":1356},{},[1357],{"type":49,"value":1358},"Deploys or updates the proxy\u002Fbeacon",{"type":43,"tag":63,"props":1360,"children":1361},{},[1362],{"type":49,"value":1363},"Calls the initializer (on deploy)",{"type":43,"tag":256,"props":1365,"children":1366},{},[1367,1369,1375],{"type":49,"value":1368},"The plugin tracks deployed implementations in ",{"type":43,"tag":180,"props":1370,"children":1372},{"className":1371},[],[1373],{"type":49,"value":1374},".openzeppelin\u002F",{"type":49,"value":1376}," per-network files. Commit non-development network files to version control.",{"type":43,"tag":256,"props":1378,"children":1379},{},[1380,1382,1388],{"type":49,"value":1381},"Use ",{"type":43,"tag":180,"props":1383,"children":1385},{"className":1384},[],[1386],{"type":49,"value":1387},"prepareUpgrade",{"type":49,"value":1389}," to validate and deploy a new implementation without executing the upgrade — useful when a multisig or governance contract holds upgrade rights.",{"type":43,"tag":262,"props":1391,"children":1392},{},[1393],{"type":43,"tag":256,"props":1394,"children":1395},{},[1396],{"type":49,"value":1397},"Read the installed plugin's README or source for exact API signatures and options, as these evolve across versions.",{"type":43,"tag":52,"props":1399,"children":1401},{"id":1400},"foundry-upgrades-workflow",[1402],{"type":49,"value":108},{"type":43,"tag":256,"props":1404,"children":1405},{},[1406],{"type":49,"value":1407},"Install dependencies:",{"type":43,"tag":396,"props":1409,"children":1411},{"className":994,"code":1410,"language":996,"meta":400,"style":400},"forge install foundry-rs\u002Fforge-std\nforge install OpenZeppelin\u002Fopenzeppelin-foundry-upgrades\nforge install OpenZeppelin\u002Fopenzeppelin-contracts-upgradeable\n",[1412],{"type":43,"tag":180,"props":1413,"children":1414},{"__ignoreMap":400},[1415,1432,1448],{"type":43,"tag":406,"props":1416,"children":1417},{"class":408,"line":409},[1418,1423,1427],{"type":43,"tag":406,"props":1419,"children":1420},{"style":1006},[1421],{"type":49,"value":1422},"forge",{"type":43,"tag":406,"props":1424,"children":1425},{"style":1012},[1426],{"type":49,"value":1154},{"type":43,"tag":406,"props":1428,"children":1429},{"style":1012},[1430],{"type":49,"value":1431}," foundry-rs\u002Fforge-std\n",{"type":43,"tag":406,"props":1433,"children":1434},{"class":408,"line":418},[1435,1439,1443],{"type":43,"tag":406,"props":1436,"children":1437},{"style":1006},[1438],{"type":49,"value":1422},{"type":43,"tag":406,"props":1440,"children":1441},{"style":1012},[1442],{"type":49,"value":1154},{"type":43,"tag":406,"props":1444,"children":1445},{"style":1012},[1446],{"type":49,"value":1447}," OpenZeppelin\u002Fopenzeppelin-foundry-upgrades\n",{"type":43,"tag":406,"props":1449,"children":1450},{"class":408,"line":428},[1451,1455,1459],{"type":43,"tag":406,"props":1452,"children":1453},{"style":1006},[1454],{"type":49,"value":1422},{"type":43,"tag":406,"props":1456,"children":1457},{"style":1012},[1458],{"type":49,"value":1154},{"type":43,"tag":406,"props":1460,"children":1461},{"style":1012},[1462],{"type":49,"value":1463}," OpenZeppelin\u002Fopenzeppelin-contracts-upgradeable\n",{"type":43,"tag":256,"props":1465,"children":1466},{},[1467,1469,1475],{"type":49,"value":1468},"Configure ",{"type":43,"tag":180,"props":1470,"children":1472},{"className":1471},[],[1473],{"type":49,"value":1474},"foundry.toml",{"type":49,"value":991},{"type":43,"tag":396,"props":1477,"children":1481},{"className":1478,"code":1479,"language":1480,"meta":400,"style":400},"language-toml shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","[profile.default]\nffi = true\nast = true\nbuild_info = true\nextra_output = [\"storageLayout\"]\n","toml",[1482],{"type":43,"tag":180,"props":1483,"children":1484},{"__ignoreMap":400},[1485,1493,1501,1509,1517],{"type":43,"tag":406,"props":1486,"children":1487},{"class":408,"line":409},[1488],{"type":43,"tag":406,"props":1489,"children":1490},{},[1491],{"type":49,"value":1492},"[profile.default]\n",{"type":43,"tag":406,"props":1494,"children":1495},{"class":408,"line":418},[1496],{"type":43,"tag":406,"props":1497,"children":1498},{},[1499],{"type":49,"value":1500},"ffi = true\n",{"type":43,"tag":406,"props":1502,"children":1503},{"class":408,"line":428},[1504],{"type":43,"tag":406,"props":1505,"children":1506},{},[1507],{"type":49,"value":1508},"ast = true\n",{"type":43,"tag":406,"props":1510,"children":1511},{"class":408,"line":437},[1512],{"type":43,"tag":406,"props":1513,"children":1514},{},[1515],{"type":49,"value":1516},"build_info = true\n",{"type":43,"tag":406,"props":1518,"children":1519},{"class":408,"line":446},[1520],{"type":43,"tag":406,"props":1521,"children":1522},{},[1523],{"type":49,"value":1524},"extra_output = [\"storageLayout\"]\n",{"type":43,"tag":262,"props":1526,"children":1527},{},[1528],{"type":43,"tag":256,"props":1529,"children":1530},{},[1531],{"type":49,"value":1532},"Node.js is required — the library shells out to the OpenZeppelin Upgrades CLI for validation.",{"type":43,"tag":256,"props":1534,"children":1535},{},[1536],{"type":49,"value":1537},"Import and use in scripts\u002Ftests:",{"type":43,"tag":396,"props":1539,"children":1541},{"className":398,"code":1540,"language":24,"meta":400,"style":400},"import {Upgrades} from \"openzeppelin-foundry-upgrades\u002FUpgrades.sol\";\n\n\u002F\u002F Deploy\naddress proxy = Upgrades.deployUUPSProxy(\n    \"MyContract.sol\",\n    abi.encodeCall(MyContract.initialize, (args))\n);\n\n\u002F\u002F IMPORTANT: Before upgrading, annotate MyContractV2 with: \u002F\u002F\u002F @custom:oz-upgrades-from MyContract\n\n\u002F\u002F Upgrade and call a function\nUpgrades.upgradeProxy(proxy, \"MyContractV2.sol\", abi.encodeCall(MyContractV2.foo, (\"arguments for foo\")));\n\n\u002F\u002F Upgrade without calling a function\nUpgrades.upgradeProxy(proxy, \"MyContractV2.sol\", \"\");\n",[1542],{"type":43,"tag":180,"props":1543,"children":1544},{"__ignoreMap":400},[1545,1553,1560,1568,1576,1584,1592,1600,1607,1620,1627,1635,1643,1650,1659],{"type":43,"tag":406,"props":1546,"children":1547},{"class":408,"line":409},[1548],{"type":43,"tag":406,"props":1549,"children":1550},{},[1551],{"type":49,"value":1552},"import {Upgrades} from \"openzeppelin-foundry-upgrades\u002FUpgrades.sol\";\n",{"type":43,"tag":406,"props":1554,"children":1555},{"class":408,"line":418},[1556],{"type":43,"tag":406,"props":1557,"children":1558},{"emptyLinePlaceholder":422},[1559],{"type":49,"value":425},{"type":43,"tag":406,"props":1561,"children":1562},{"class":408,"line":428},[1563],{"type":43,"tag":406,"props":1564,"children":1565},{},[1566],{"type":49,"value":1567},"\u002F\u002F Deploy\n",{"type":43,"tag":406,"props":1569,"children":1570},{"class":408,"line":437},[1571],{"type":43,"tag":406,"props":1572,"children":1573},{},[1574],{"type":49,"value":1575},"address proxy = Upgrades.deployUUPSProxy(\n",{"type":43,"tag":406,"props":1577,"children":1578},{"class":408,"line":446},[1579],{"type":43,"tag":406,"props":1580,"children":1581},{},[1582],{"type":49,"value":1583},"    \"MyContract.sol\",\n",{"type":43,"tag":406,"props":1585,"children":1586},{"class":408,"line":455},[1587],{"type":43,"tag":406,"props":1588,"children":1589},{},[1590],{"type":49,"value":1591},"    abi.encodeCall(MyContract.initialize, (args))\n",{"type":43,"tag":406,"props":1593,"children":1594},{"class":408,"line":464},[1595],{"type":43,"tag":406,"props":1596,"children":1597},{},[1598],{"type":49,"value":1599},");\n",{"type":43,"tag":406,"props":1601,"children":1602},{"class":408,"line":473},[1603],{"type":43,"tag":406,"props":1604,"children":1605},{"emptyLinePlaceholder":422},[1606],{"type":49,"value":425},{"type":43,"tag":406,"props":1608,"children":1609},{"class":408,"line":481},[1610,1615],{"type":43,"tag":406,"props":1611,"children":1612},{},[1613],{"type":49,"value":1614},"\u002F\u002F IMPORTANT: Before upgrading, annotate MyContractV2 with:",{"type":43,"tag":406,"props":1616,"children":1617},{},[1618],{"type":49,"value":1619}," \u002F\u002F\u002F @custom:oz-upgrades-from MyContract\n",{"type":43,"tag":406,"props":1621,"children":1622},{"class":408,"line":490},[1623],{"type":43,"tag":406,"props":1624,"children":1625},{"emptyLinePlaceholder":422},[1626],{"type":49,"value":425},{"type":43,"tag":406,"props":1628,"children":1629},{"class":408,"line":499},[1630],{"type":43,"tag":406,"props":1631,"children":1632},{},[1633],{"type":49,"value":1634},"\u002F\u002F Upgrade and call a function\n",{"type":43,"tag":406,"props":1636,"children":1637},{"class":408,"line":508},[1638],{"type":43,"tag":406,"props":1639,"children":1640},{},[1641],{"type":49,"value":1642},"Upgrades.upgradeProxy(proxy, \"MyContractV2.sol\", abi.encodeCall(MyContractV2.foo, (\"arguments for foo\")));\n",{"type":43,"tag":406,"props":1644,"children":1645},{"class":408,"line":516},[1646],{"type":43,"tag":406,"props":1647,"children":1648},{"emptyLinePlaceholder":422},[1649],{"type":49,"value":425},{"type":43,"tag":406,"props":1651,"children":1653},{"class":408,"line":1652},14,[1654],{"type":43,"tag":406,"props":1655,"children":1656},{},[1657],{"type":49,"value":1658},"\u002F\u002F Upgrade without calling a function\n",{"type":43,"tag":406,"props":1660,"children":1662},{"class":408,"line":1661},15,[1663],{"type":43,"tag":406,"props":1664,"children":1665},{},[1666],{"type":49,"value":1667},"Upgrades.upgradeProxy(proxy, \"MyContractV2.sol\", \"\");\n",{"type":43,"tag":256,"props":1669,"children":1670},{},[1671],{"type":49,"value":1672},"Key differences from Hardhat:",{"type":43,"tag":59,"props":1674,"children":1675},{},[1676,1681,1710,1721],{"type":43,"tag":63,"props":1677,"children":1678},{},[1679],{"type":49,"value":1680},"Contracts are referenced by name string, not factory object",{"type":43,"tag":63,"props":1682,"children":1683},{},[1684,1686,1692,1694,1700,1702,1708],{"type":49,"value":1685},"No automatic implementation tracking — annotate new versions with ",{"type":43,"tag":180,"props":1687,"children":1689},{"className":1688},[],[1690],{"type":49,"value":1691},"@custom:oz-upgrades-from",{"type":49,"value":1693}," or pass ",{"type":43,"tag":180,"props":1695,"children":1697},{"className":1696},[],[1698],{"type":49,"value":1699},"referenceContract",{"type":49,"value":1701}," in the ",{"type":43,"tag":180,"props":1703,"children":1705},{"className":1704},[],[1706],{"type":49,"value":1707},"Options",{"type":49,"value":1709}," struct",{"type":43,"tag":63,"props":1711,"children":1712},{},[1713,1719],{"type":43,"tag":180,"props":1714,"children":1716},{"className":1715},[],[1717],{"type":49,"value":1718},"UnsafeUpgrades",{"type":49,"value":1720}," variant skips all validation (takes addresses instead of names) — never use in production scripts",{"type":43,"tag":63,"props":1722,"children":1723},{},[1724,1726,1732,1734,1740],{"type":49,"value":1725},"Run ",{"type":43,"tag":180,"props":1727,"children":1729},{"className":1728},[],[1730],{"type":49,"value":1731},"forge clean",{"type":49,"value":1733}," or use ",{"type":43,"tag":180,"props":1735,"children":1737},{"className":1736},[],[1738],{"type":49,"value":1739},"--force",{"type":49,"value":1741}," before running scripts",{"type":43,"tag":262,"props":1743,"children":1744},{},[1745],{"type":43,"tag":256,"props":1746,"children":1747},{},[1748,1750,1756,1758,1763],{"type":49,"value":1749},"Read the installed library's ",{"type":43,"tag":180,"props":1751,"children":1753},{"className":1752},[],[1754],{"type":49,"value":1755},"Upgrades.sol",{"type":49,"value":1757}," for the full API and ",{"type":43,"tag":180,"props":1759,"children":1761},{"className":1760},[],[1762],{"type":49,"value":1707},{"type":49,"value":1764}," struct.",{"type":43,"tag":52,"props":1766,"children":1768},{"id":1767},"handling-upgrade-validation-issues",[1769],{"type":49,"value":117},{"type":43,"tag":256,"props":1771,"children":1772},{},[1773],{"type":49,"value":1774},"When the plugins flag a warning or error, work through this hierarchy:",{"type":43,"tag":1341,"props":1776,"children":1777},{},[1778,1788,1798,1808],{"type":43,"tag":63,"props":1779,"children":1780},{},[1781,1786],{"type":43,"tag":172,"props":1782,"children":1783},{},[1784],{"type":49,"value":1785},"Fix the root cause.",{"type":49,"value":1787}," Determine whether the code can be restructured to eliminate the concern entirely — remove the problematic pattern or refactor storage. This is always the right first step.",{"type":43,"tag":63,"props":1789,"children":1790},{},[1791,1796],{"type":43,"tag":172,"props":1792,"children":1793},{},[1794],{"type":49,"value":1795},"Use in-code annotations if the situation is genuinely safe.",{"type":49,"value":1797}," If restructuring isn't appropriate and you've determined the flagged pattern is actually safe, the plugins support annotations that let you document that judgment directly at the source. Check the installed plugin's docs for what's available. These annotations create a clear audit trail of intentional exceptions — use them only after evaluating the safety, not as a shortcut.",{"type":43,"tag":63,"props":1799,"children":1800},{},[1801,1806],{"type":43,"tag":172,"props":1802,"children":1803},{},[1804],{"type":49,"value":1805},"Use a narrow flag if an annotation won't work.",{"type":49,"value":1807}," Some cases (e.g., a third-party base contract you can't modify) can't be addressed in source. Use the most targeted flag available, scoped to the specific construct.",{"type":43,"tag":63,"props":1809,"children":1810},{},[1811,1816,1818,1823,1825,1831],{"type":43,"tag":172,"props":1812,"children":1813},{},[1814],{"type":49,"value":1815},"Broad bypass as a last resort, with full awareness of the risk.",{"type":49,"value":1817}," Options like ",{"type":43,"tag":180,"props":1819,"children":1821},{"className":1820},[],[1822],{"type":49,"value":1718},{"type":49,"value":1824}," (Foundry) or blanket ",{"type":43,"tag":180,"props":1826,"children":1828},{"className":1827},[],[1829],{"type":49,"value":1830},"unsafeAllow",{"type":49,"value":1832}," entries skip all validation for the affected scope. If you use them, comment why, and verify manually — the plugin is no longer protecting you.",{"type":43,"tag":52,"props":1834,"children":1836},{"id":1835},"upgrade-safety-checklist",[1837],{"type":49,"value":126},{"type":43,"tag":59,"props":1839,"children":1842},{"className":1840},[1841],"contains-task-list",[1843,1862,1897,1925,1954,1969,1997,2012,2042],{"type":43,"tag":63,"props":1844,"children":1847},{"className":1845},[1846],"task-list-item",[1848,1853,1855,1860],{"type":43,"tag":1849,"props":1850,"children":1852},"input",{"disabled":422,"type":1851},"checkbox",[],{"type":49,"value":1854}," ",{"type":43,"tag":172,"props":1856,"children":1857},{},[1858],{"type":49,"value":1859},"Storage compatibility",{"type":49,"value":1861},": No reordering, removal, or type changes of existing variables. Only append new variables (or add fields to namespaced structs).",{"type":43,"tag":63,"props":1863,"children":1865},{"className":1864},[1846],[1866,1869,1870,1875,1877,1882,1884,1889,1891,1896],{"type":43,"tag":1849,"props":1867,"children":1868},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":1871,"children":1872},{},[1873],{"type":49,"value":1874},"Initializer protection",{"type":49,"value":1876},": Top-level ",{"type":43,"tag":180,"props":1878,"children":1880},{"className":1879},[],[1881],{"type":49,"value":541},{"type":49,"value":1883}," uses ",{"type":43,"tag":180,"props":1885,"children":1887},{"className":1886},[],[1888],{"type":49,"value":549},{"type":49,"value":1890}," modifier. Implementation constructor calls ",{"type":43,"tag":180,"props":1892,"children":1894},{"className":1893},[],[1895],{"type":49,"value":583},{"type":49,"value":952},{"type":43,"tag":63,"props":1898,"children":1900},{"className":1899},[1846],[1901,1904,1905,1910,1912,1917,1919,1924],{"type":43,"tag":1849,"props":1902,"children":1903},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":1906,"children":1907},{},[1908],{"type":49,"value":1909},"Parent initializers called",{"type":49,"value":1911},": Every inherited upgradeable contract's ",{"type":43,"tag":180,"props":1913,"children":1915},{"className":1914},[],[1916],{"type":49,"value":562},{"type":49,"value":1918}," is called exactly once in ",{"type":43,"tag":180,"props":1920,"children":1922},{"className":1921},[],[1923],{"type":49,"value":541},{"type":49,"value":952},{"type":43,"tag":63,"props":1926,"children":1928},{"className":1927},[1846],[1929,1932,1933,1938,1940,1945,1947,1952],{"type":43,"tag":1849,"props":1930,"children":1931},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":1934,"children":1935},{},[1936],{"type":49,"value":1937},"No unsafe opcodes",{"type":49,"value":1939},": No ",{"type":43,"tag":180,"props":1941,"children":1943},{"className":1942},[],[1944],{"type":49,"value":1080},{"type":49,"value":1946}," or ",{"type":43,"tag":180,"props":1948,"children":1950},{"className":1949},[],[1951],{"type":49,"value":1102},{"type":49,"value":1953}," to untrusted targets.",{"type":43,"tag":63,"props":1955,"children":1957},{"className":1956},[1846],[1958,1961,1962,1967],{"type":43,"tag":1849,"props":1959,"children":1960},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":1963,"children":1964},{},[1965],{"type":49,"value":1966},"Function selector clashes",{"type":49,"value":1968},": Proxy admin functions and implementation functions must not share selectors. UUPS and Transparent patterns handle this by design; custom proxies need manual review.",{"type":43,"tag":63,"props":1970,"children":1972},{"className":1971},[1846],[1973,1976,1977,1987,1989,1995],{"type":43,"tag":1849,"props":1974,"children":1975},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":1978,"children":1979},{},[1980,1982],{"type":49,"value":1981},"UUPS ",{"type":43,"tag":180,"props":1983,"children":1985},{"className":1984},[],[1986],{"type":49,"value":198},{"type":49,"value":1988},": Overridden with proper access control (e.g., ",{"type":43,"tag":180,"props":1990,"children":1992},{"className":1991},[],[1993],{"type":49,"value":1994},"onlyOwner",{"type":49,"value":1996},"). Forgetting this makes the proxy non-upgradeable or upgradeable by anyone.",{"type":43,"tag":63,"props":1998,"children":2000},{"className":1999},[1846],[2001,2004,2005,2010],{"type":43,"tag":1849,"props":2002,"children":2003},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":2006,"children":2007},{},[2008],{"type":49,"value":2009},"Test the upgrade path",{"type":49,"value":2011},": Deploy V1, upgrade to V2, verify state is preserved and new logic works. Both Hardhat and Foundry plugins can validate upgrades in test suites.",{"type":43,"tag":63,"props":2013,"children":2015},{"className":2014},[1846],[2016,2019,2020,2025,2027,2033,2035,2040],{"type":43,"tag":1849,"props":2017,"children":2018},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":2021,"children":2022},{},[2023],{"type":49,"value":2024},"Reinitializer for V2+",{"type":49,"value":2026},": If V2 needs new initialization logic, use ",{"type":43,"tag":180,"props":2028,"children":2030},{"className":2029},[],[2031],{"type":49,"value":2032},"reinitializer(2)",{"type":49,"value":2034}," modifier (not ",{"type":43,"tag":180,"props":2036,"children":2038},{"className":2037},[],[2039],{"type":49,"value":549},{"type":49,"value":2041},", which can only run once).",{"type":43,"tag":63,"props":2043,"children":2045},{"className":2044},[1846],[2046,2049,2050,2055],{"type":43,"tag":1849,"props":2047,"children":2048},{"disabled":422,"type":1851},[],{"type":49,"value":1854},{"type":43,"tag":172,"props":2051,"children":2052},{},[2053],{"type":49,"value":2054},"Unique ERC-7201 namespace ids",{"type":49,"value":2056},": No two contracts in the inheritance chain share the same namespace id. Colliding ids map to the same storage slot, causing silent storage corruption.",{"type":43,"tag":2058,"props":2059,"children":2060},"style",{},[2061],{"type":49,"value":2062},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"items":2064,"total":499},[2065,2078,2095,2109,2122,2132,2142],{"slug":2066,"name":2066,"fn":2067,"description":2068,"org":2069,"tags":2070,"stars":25,"repoUrl":26,"updatedAt":2077},"develop-secure-contracts","develop secure smart contracts with OpenZeppelin","Develop secure smart contracts using OpenZeppelin Contracts libraries. Use when users need to integrate OpenZeppelin library components — including token standards (ERC20, ERC721, ERC1155), access control (Ownable, AccessControl, AccessManager), security primitives (Pausable, ReentrancyGuard), governance (Governor, timelocks), or accounts (multisig, account abstraction) — into existing or new contracts. Covers pattern discovery from library source, CLI contract generators, and library-first integration. Supports Solidity, Cairo, Stylus, Stellar, and Sui Move.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2071,2074,2075,2076],{"name":2072,"slug":2073,"type":15},"Access Control","access-control",{"name":13,"slug":14,"type":15},{"name":20,"slug":21,"type":15},{"name":23,"slug":24,"type":15},"2026-07-13T06:04:32.666273",{"slug":2079,"name":2079,"fn":2080,"description":2081,"org":2082,"tags":2083,"stars":25,"repoUrl":26,"updatedAt":2094},"review-sui-contracts","review Sui Move smart contracts","Review Sui Move code that integrates OpenZeppelin Contracts for Sui against the library's own patterns and conventions. Use this when a developer wants their integration checked before shipping. Triggers: \"review my Sui Move code\", \"am I using OpenZeppelin correctly\", \"check this integration\", \"is this idiomatic\", \"review before audit\". Checks correct use of OZ primitives, deviations from examples\u002Fdoc-comments, upheld invariants, test coverage, and code-quality\u002Fstyle. This is an AI code review, not a formal security audit.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2084,2087,2090,2093],{"name":2085,"slug":2086,"type":15},"Blockchain","blockchain",{"name":2088,"slug":2089,"type":15},"Code Review","code-review",{"name":2091,"slug":2092,"type":15},"Rust","rust",{"name":20,"slug":21,"type":15},"2026-07-16T06:00:49.17387",{"slug":2096,"name":2096,"fn":2097,"description":2098,"org":2099,"tags":2100,"stars":25,"repoUrl":26,"updatedAt":2108},"setup-cairo-contracts","set up Cairo smart contract projects","Set up a Cairo smart contract project with OpenZeppelin Contracts for Cairo on Starknet. Use when users need to: (1) create a new Scarb\u002FStarknet project, (2) add OpenZeppelin Contracts for Cairo dependencies to Scarb.toml, (3) configure individual or umbrella OpenZeppelin packages, or (4) understand Cairo import conventions and component patterns for OpenZeppelin.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2101,2104,2105],{"name":2102,"slug":2103,"type":15},"Engineering","engineering",{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},"Web3","web3","2026-07-13T06:04:17.186825",{"slug":2110,"name":2110,"fn":2111,"description":2112,"org":2113,"tags":2114,"stars":25,"repoUrl":26,"updatedAt":2121},"setup-solidity-contracts","set up Solidity smart contract projects","Set up a Solidity smart contract project with OpenZeppelin Contracts. Use when users need to: (1) create a new Hardhat or Foundry project, (2) install OpenZeppelin Contracts dependencies for Solidity, (3) configure remappings for Foundry, or (4) understand Solidity import conventions for OpenZeppelin.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2115,2116,2119,2120],{"name":2102,"slug":2103,"type":15},{"name":2117,"slug":2118,"type":15},"Foundry","foundry",{"name":20,"slug":21,"type":15},{"name":23,"slug":24,"type":15},"2026-07-13T06:04:29.360325",{"slug":2123,"name":2123,"fn":2124,"description":2125,"org":2126,"tags":2127,"stars":25,"repoUrl":26,"updatedAt":2131},"setup-stellar-contracts","set up Stellar Soroban smart contract projects","Set up a Stellar\u002FSoroban smart contract project with OpenZeppelin Contracts for Stellar. Use when users need to: (1) install Stellar CLI and Rust toolchain for Soroban, (2) create a new Soroban project, (3) add OpenZeppelin Stellar dependencies to Cargo.toml, or (4) understand Soroban import conventions and contract patterns for OpenZeppelin.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2128,2129,2130],{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},"2026-07-13T06:04:23.807685",{"slug":2133,"name":2133,"fn":2134,"description":2135,"org":2136,"tags":2137,"stars":25,"repoUrl":26,"updatedAt":2141},"setup-stylus-contracts","set up Stylus smart contract projects","Set up a Stylus smart contract project with OpenZeppelin Contracts for Stylus on Arbitrum. Use when users need to: (1) install Rust toolchain and WASM target for Stylus, (2) create a new Cargo Stylus project, (3) add OpenZeppelin Stylus dependencies to Cargo.toml, or (4) understand Stylus import conventions and storage patterns for OpenZeppelin.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2138,2139,2140],{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},"2026-07-13T06:04:18.638516",{"slug":2143,"name":2143,"fn":2144,"description":2145,"org":2146,"tags":2147,"stars":25,"repoUrl":26,"updatedAt":2154},"setup-sui-contracts","set up Sui Move smart contracts","Set up a Sui Move smart contract project with OpenZeppelin Contracts for Sui. Use when users need to: (1) install the Sui CLI and Move toolchain, (2) create a new Sui Move package, (3) discover and add OpenZeppelin Sui dependencies to Move.toml via the Move Registry (MVR), (4) learn the integration pattern from the library's examples and API docs before implementing, or (5) understand Sui Move import conventions and build\u002Ftest commands for OpenZeppelin.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2148,2149,2152,2153],{"name":2085,"slug":2086,"type":15},{"name":2150,"slug":2151,"type":15},"CLI","cli",{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},"2026-07-16T05:59:21.671811",{"items":2156,"total":499},[2157,2164,2171,2177,2184,2190,2196,2203,2213,2220,2231],{"slug":2066,"name":2066,"fn":2067,"description":2068,"org":2158,"tags":2159,"stars":25,"repoUrl":26,"updatedAt":2077},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2160,2161,2162,2163],{"name":2072,"slug":2073,"type":15},{"name":13,"slug":14,"type":15},{"name":20,"slug":21,"type":15},{"name":23,"slug":24,"type":15},{"slug":2079,"name":2079,"fn":2080,"description":2081,"org":2165,"tags":2166,"stars":25,"repoUrl":26,"updatedAt":2094},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2167,2168,2169,2170],{"name":2085,"slug":2086,"type":15},{"name":2088,"slug":2089,"type":15},{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},{"slug":2096,"name":2096,"fn":2097,"description":2098,"org":2172,"tags":2173,"stars":25,"repoUrl":26,"updatedAt":2108},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2174,2175,2176],{"name":2102,"slug":2103,"type":15},{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},{"slug":2110,"name":2110,"fn":2111,"description":2112,"org":2178,"tags":2179,"stars":25,"repoUrl":26,"updatedAt":2121},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2180,2181,2182,2183],{"name":2102,"slug":2103,"type":15},{"name":2117,"slug":2118,"type":15},{"name":20,"slug":21,"type":15},{"name":23,"slug":24,"type":15},{"slug":2123,"name":2123,"fn":2124,"description":2125,"org":2185,"tags":2186,"stars":25,"repoUrl":26,"updatedAt":2131},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2187,2188,2189],{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},{"slug":2133,"name":2133,"fn":2134,"description":2135,"org":2191,"tags":2192,"stars":25,"repoUrl":26,"updatedAt":2141},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2193,2194,2195],{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},{"slug":2143,"name":2143,"fn":2144,"description":2145,"org":2197,"tags":2198,"stars":25,"repoUrl":26,"updatedAt":2154},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2199,2200,2201,2202],{"name":2085,"slug":2086,"type":15},{"name":2150,"slug":2151,"type":15},{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},{"slug":2204,"name":2204,"fn":2205,"description":2206,"org":2207,"tags":2208,"stars":25,"repoUrl":26,"updatedAt":2212},"upgrade-cairo-contracts","upgrade Cairo smart contracts on Starknet","Upgrade Cairo smart contracts using OpenZeppelin's UpgradeableComponent on Starknet. Use when users need to: (1) make Cairo contracts upgradeable via replace_class_syscall, (2) integrate the OpenZeppelin UpgradeableComponent, (3) understand Starknet's class-based upgrade model vs EVM proxy patterns, (4) ensure storage compatibility across upgrades, (5) guard upgrade functions with access control, or (6) test upgrade paths for Cairo contracts.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2209,2210,2211],{"name":17,"slug":18,"type":15},{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},"2026-07-13T06:04:25.126377",{"slug":4,"name":4,"fn":5,"description":6,"org":2214,"tags":2215,"stars":25,"repoUrl":26,"updatedAt":27},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2216,2217,2218,2219],{"name":17,"slug":18,"type":15},{"name":13,"slug":14,"type":15},{"name":20,"slug":21,"type":15},{"name":23,"slug":24,"type":15},{"slug":2221,"name":2221,"fn":2222,"description":2223,"org":2224,"tags":2225,"stars":25,"repoUrl":26,"updatedAt":2230},"upgrade-stellar-contracts","upgrade Stellar Soroban smart contracts","Upgrade Stellar\u002FSoroban smart contracts using OpenZeppelin's upgradeable module. Use when users need to: (1) make Soroban contracts upgradeable via native WASM replacement, (2) use Upgradeable or UpgradeableMigratable derive macros, (3) implement atomic upgrade-and-migrate patterns with an Upgrader contract, (4) ensure storage key compatibility across upgrades, or (5) test upgrade paths for Soroban contracts.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2226,2227,2228,2229],{"name":2085,"slug":2086,"type":15},{"name":17,"slug":18,"type":15},{"name":13,"slug":14,"type":15},{"name":20,"slug":21,"type":15},"2026-07-13T06:04:31.398663",{"slug":2232,"name":2232,"fn":2233,"description":2234,"org":2235,"tags":2236,"stars":25,"repoUrl":26,"updatedAt":2241},"upgrade-stylus-contracts","upgrade Stylus smart contracts","Upgrade Stylus smart contracts using OpenZeppelin proxy patterns on Arbitrum. Use when users need to: (1) make Stylus Rust contracts upgradeable with UUPS or Beacon proxies, (2) understand Stylus-specific proxy mechanics (logic_flag, WASM reactivation), (3) integrate UUPSUpgradeable with access control, (4) ensure storage compatibility across upgrades, or (5) test upgrade paths for Stylus contracts.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2237,2238,2239,2240],{"name":17,"slug":18,"type":15},{"name":2091,"slug":2092,"type":15},{"name":20,"slug":21,"type":15},{"name":2106,"slug":2107,"type":15},"2026-07-13T06:04:28.005287"]