upgradeable-proxy
できること
この手順書は、アップグレード可能なコントラクトの設計によくある弱点を扱います。プロキシのパターンを使う監査人と開発者向けです。
使う場面
- ✓コントラクトがプロキシの背後に配置され、管理者がアップグレードできるとき。
- ✓実装のコントラクトが、プロキシ以外の人によって初期化されうるとき。
- ✓アップグレードの後にストレージのレイアウトを確認する必要があるとき。
スキルのリンク
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/upgradeable-proxy/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“当社のトークンのコントラクトにアップグレード可能なプロキシを使っています。その設定とアップグレードの権限を確認してもらえますか。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、実装が直接の初期化からロックされているか、ストレージのスロットが衝突しうるか、誰がアップグレードを承認できるかを確認します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Upgradeable Proxy Playbook
Proxies separate storage (proxy) from logic (implementation). The
proxy delegatecalls into the implementation, executing logic in the
proxy's storage context. Three common patterns:
- Transparent Proxy (OZ TransparentUpgradeableProxy)
- UUPS (OZ UUPSUpgradeable, OZ 4.1+)
- Diamond / EIP-2535 (multi-facet, much more complex)
Each has distinct bug classes.
Audit checklist
1. Uninitialized implementation
Implementations should be initialized at deployment to prevent third-party initialization:
// Vulnerable — anyone can call initialize() on the implementation
// directly (not via proxy) and become its owner
contract VulnImpl {
function initialize(address owner_) external {
owner = owner_;
}
}
// Safe — disable initializers on impl deployment
contract SafeImpl is Initializable {
constructor() { _disableInitializers(); }
function initialize(address owner_) external initializer {
owner = owner_;
}
}
Attack: attacker calls initialize on the impl contract → becomes
"owner" of the impl. While this doesn't immediately drain the proxy,
it CAN matter if _authorizeUpgrade reads impl-side state, or if
selfdestruct is exposed and impl auth is on owner. Past incident:
Parity multisig 2017 — $280M frozen.
# Find unprotected impl
grep -rn 'initialize\|_disableInitializers' src/
2. Storage slot collisions
Proxy and impl share storage. New impl versions must lay storage identical to old:
// V1
contract LogicV1 {
address public owner; // slot 0
uint256 public total; // slot 1
}
// V2 — BUG: inserted new var at top
contract LogicV2 {
uint256 public newVar; // slot 0 — overwrites owner!
address public owner; // slot 1
uint256 public total; // slot 2
}
After upgrade, owner is read from where total was; arbitrary value.
Check:
- New vars only appended at the end
- Inheritance order unchanged
- OZ
__gapreserved slots used in upgradeable libs
# OZ provides a tool
slither-check-upgradeability V1.sol V2.sol --proxy-name MyProxy
3. Function selector collisions (Transparent Proxy specifically)
Transparent proxy: if caller is admin → proxy admin functions; else → delegatecall to impl. If impl has function with selector matching a proxy admin selector → admin sees impl, user sees impl, admin can never call admin functions. Or worse, ABI-trickery.
Common collisions:
upgradeTo(address): selector0x3659cfe6— what if impl defines atransferOwnership(address)that hashes to the same selector?
Slither auto-detects:
slither --print human-summary src/ | grep -i selector
4. _authorizeUpgrade empty / wrong
UUPS pattern: implementation contains the upgrade authorization. Default
OZ _authorizeUpgrade is internal virtual {} — empty body that
reverts, but the function itself is empty. Devs override it:
// VULNERABLE — empty body, no actual auth check
function _authorizeUpgrade(address newImplementation) internal override {}
// SAFE
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
Attack: anyone calls upgradeTo(maliciousImpl) → all storage now
controlled by malicious code.
grep -rn '_authorizeUpgrade' src/
5. delegatecall to attacker-controlled address
If the impl contains a function that performs delegatecall(arbitrary_address),
attackers can pass their own contract → execute arbitrary code in
proxy storage context, including selfdestruct.
grep -rn 'delegatecall' src/
6. Constructor logic in upgradeable contracts
Constructors run on the implementation only — proxy storage is
untouched. Storage initialization must happen in initialize(). If
critical state is set in the constructor, the proxy will read zero
values:
// VULNERABLE — admin set in constructor, proxy reads 0x0
contract Impl {
address public admin;
constructor() { admin = msg.sender; } // sets admin on IMPL only
}
7. Diamond / EIP-2535 specific bugs
- Facet selector collisions — two facets define same selector
- Diamond storage position not unique → cross-facet storage corruption
diamondCutaccess control — must be gated, often forgotten
# Inspect facet selectors
slither . --print function-summary | grep -A1 'Facet'
8. Storage gap for inheritance
OZ upgradeable libs use `
よくある質問
主なプロキシのパターンは何ですか?
Transparent Proxy、UUPS、Diamondのパターンが、手順書で挙げられています。
なぜ実装をロックするのですか?
外部の人が初期化して、その設定を乗っ取ることを防ぐためです。
ストレージの衝突とは何ですか?
プロキシとロジックのコントラクトが同じストレージの位置を使い、データが上書きされてしまうことです。
詳細
作者による元の説明
Proxy upgrade patterns and their bugs — uninitialized implementation, storage slot collisions, selector clashes, unprotected upgrade auth.
人気
- GitHubのスター
- 6.5k
- ランキング
- #14014
- ライセンス
- Apache-2.0
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
detector-overview
6.5kエージェントが、スキャナーが指摘したコードを読み、本物のセキュリティバグと誤検知を見分けられるよう支援します。
exploiter-overview
6.5kエージェントが、確認済みの複数のセキュリティ上の弱点を一つのテストの連鎖にまとめ、その影響がどこまで及ぶかを確認できるよう支援します。
llm-redteam-overview
6.5kエージェントが、プロンプトインジェクションからモデルの悪用まで、15の戦術グループの中から適切なAIレッドチーム用ガイドを見つけられるよう支援します。
aatmf-t01-prompt-injection
6.5kプロンプトインジェクションを説明します。隠された指示でAIシステムを乗っ取ろうとする手口を、セキュリティテスターが確認できるようにします。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。