{
  "openapi": "3.1.1",
  "info": {
    "title": "Smart Contract Upgrade Explorer API",
    "version": "1.0.0",
    "summary": "Is this smart contract upgradeable, who controls upgrades, and what changed?",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://contractupgradeexplorer.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Is this smart contract upgradeable, who controls upgrades, and what changed?",
        "description": "Reads a contract straight from the chain and identifies its proxy pattern (EIP-1967 transparent, UUPS, beacon, EIP-1167 clone, Safe proxy, legacy ZeppelinOS, EIP-7702 delegated account), the current implementation, who controls upgrades (single key, Safe multisig with threshold, timelock with delay, ProxyAdmin and its owner), the Upgraded/AdminChanged event history, and whether the code is verified on Sourcify. Paste raw bytecode for an offline scan.\n\nMethodology:\n- Storage slots read with eth_getStorageAt: EIP-1967 implementation/admin/beacon (keccak256(\"eip1967.proxy.*\") − 1), EIP-1822 PROXIABLE, the legacy ZeppelinOS implementation/admin slots (keccak256(\"org.zeppelinos.proxy.*\")), and slot 0 for Safe proxies.\n- Bytecode scan (PUSH data skipped): EIP-1167 clone pattern, EIP-7702 delegation designator (0xef0100…), DELEGATECALL/SELFDESTRUCT opcodes, dispatcher selectors (PUSH4 followed by EQ) and EIP-1967 slot constants.\n- Classification: beacon slot set → beacon proxy; admin slot set → transparent; implementation slot set and implementation exposes proxiableUUID() → UUPS; Safe proxy if slot 0 holds a contract and masterCopy() is dispatched.\n- Controller: EOA (single key), Safe (getThreshold/getOwners), TimelockController (getMinDelay), or ProxyAdmin (owner() is analysed one level deep).\n- History: Upgraded / AdminChanged / BeaconUpgraded logs of the proxy via eth_getLogs; public nodes may limit the range, which is reported.",
        "tags": [
          "web3"
        ],
        "x-mcp-tool": "contract_upgrade_explorer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContractUpgradeExplorerInput"
              },
              "examples": {
                "example1": {
                  "summary": "EIP-1167 minimal proxy clone (offline)",
                  "value": {
                    "mode": "bytecode",
                    "chain": "ethereum",
                    "bytecode": "0x363d3d373d3d3d363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3"
                  }
                },
                "example2": {
                  "summary": "Dispatcher with upgradeTo (offline)",
                  "value": {
                    "mode": "bytecode",
                    "chain": "ethereum",
                    "bytecode": "0x608060405260043610633659cfe61461005757634f1ef28614610060577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54f4"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractUpgradeExplorerResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ContractUpgradeExplorerInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "What do you have?",
            "type": "string",
            "enum": [
              "lookup",
              "bytecode"
            ],
            "default": "lookup"
          },
          "chain": {
            "title": "Chain",
            "type": "string",
            "enum": [
              "ethereum",
              "base",
              "arbitrum",
              "optimism",
              "polygon",
              "avalanche",
              "bsc"
            ],
            "default": "ethereum"
          },
          "address": {
            "title": "Contract address",
            "type": "string",
            "maxLength": 42
          },
          "bytecode": {
            "title": "Runtime bytecode",
            "type": "string",
            "maxLength": 100000
          }
        },
        "required": []
      },
      "ContractUpgradeExplorerResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mode",
              "chain",
              "address",
              "proxyType",
              "upgradeable",
              "implementation",
              "beacon",
              "admin",
              "history",
              "verification",
              "bytecode",
              "findings",
              "graph"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "lookup",
                  "bytecode"
                ]
              },
              "chain": {
                "type": "string"
              },
              "address": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "proxyType": {
                "type": "string",
                "enum": [
                  "eip1967-transparent",
                  "eip1967-uups",
                  "eip1967-beacon",
                  "eip1167-minimal-proxy",
                  "safe-proxy",
                  "legacy-zeppelinos",
                  "eip7702-delegated-eoa",
                  "eoa",
                  "not-a-proxy",
                  "unknown-delegatecall"
                ]
              },
              "upgradeable": {
                "type": "string",
                "enum": [
                  "yes",
                  "no",
                  "unknown"
                ]
              },
              "implementation": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "beacon": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "admin": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "address",
                  "kind",
                  "safe",
                  "timelockDelaySeconds",
                  "owner"
                ],
                "properties": {
                  "address": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string"
                  },
                  "owner": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "timelockDelaySeconds": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "safe": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "additionalProperties": false,
                    "required": [
                      "threshold",
                      "owners"
                    ],
                    "properties": {
                      "threshold": {
                        "type": "integer"
                      },
                      "owners": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              },
              "history": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "events",
                  "complete",
                  "range"
                ],
                "properties": {
                  "complete": {
                    "type": "boolean"
                  },
                  "range": {
                    "type": "string"
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "kind",
                        "blockNumber",
                        "txHash",
                        "value",
                        "timestamp"
                      ],
                      "properties": {
                        "kind": {
                          "type": "string"
                        },
                        "blockNumber": {
                          "type": "integer"
                        },
                        "txHash": {
                          "type": "string"
                        },
                        "value": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "verification": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "proxy",
                  "implementation"
                ],
                "properties": {
                  "proxy": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "additionalProperties": false,
                    "required": [
                      "name",
                      "match"
                    ],
                    "properties": {
                      "name": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "match": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  },
                  "implementation": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "additionalProperties": false,
                    "required": [
                      "name",
                      "match"
                    ],
                    "properties": {
                      "name": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "match": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                }
              },
              "bytecode": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "size",
                  "minimalProxyTarget",
                  "eip7702Delegate",
                  "hasDelegatecall",
                  "hasSelfdestruct",
                  "selectors",
                  "upgradeFunctions",
                  "referencesSlots"
                ],
                "properties": {
                  "size": {
                    "type": "integer"
                  },
                  "minimalProxyTarget": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "eip7702Delegate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "hasDelegatecall": {
                    "type": "boolean"
                  },
                  "hasSelfdestruct": {
                    "type": "boolean"
                  },
                  "selectors": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "upgradeFunctions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "referencesSlots": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              },
              "findings": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "severity",
                    "finding"
                  ],
                  "properties": {
                    "severity": {
                      "type": "string",
                      "enum": [
                        "high",
                        "medium",
                        "low",
                        "info"
                      ]
                    },
                    "finding": {
                      "type": "string"
                    }
                  }
                }
              },
              "graph": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "nodes",
                  "edges"
                ],
                "properties": {
                  "nodes": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "id",
                        "kind",
                        "label"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "kind": {
                          "type": "string"
                        },
                        "label": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "edges": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "from",
                        "to",
                        "relation"
                      ],
                      "properties": {
                        "from": {
                          "type": "string"
                        },
                        "to": {
                          "type": "string"
                        },
                        "relation": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}