{
  "openapi": "3.1.1",
  "info": {
    "title": "Blockchain Incident Replay API",
    "version": "1.0.0",
    "summary": "Replay an exploit from tx hashes: ordered timeline, fund-flow graph and who profited.",
    "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://blockchainincidentreplay.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Replay an exploit from tx hashes: ordered timeline, fund-flow graph and who profited.",
        "description": "Reconstructs an on-chain incident from one or more transactions: decodes each one, tries a call trace for internal ETH movements, nets every ETH and token transfer per address, and highlights the likely attacker cluster, its profit and the biggest losers — as an ordered timeline and a value-flow graph. Works offline on pasted receipts.\n\nMethodology:\n- Each transaction is decoded with the Transaction Decoder (function, status, fee, ERC-20 transfers with symbols/decimals); if that is unavailable the receipt is read directly and Transfer(address,address,uint256) logs with 3 topics are parsed.\n- debug_traceTransaction with the callTracer is attempted for internal ETH transfers (calls with value at depth > 0, DELEGATECALL excluded). Public RPC nodes usually do not expose the debug namespace; then only the top-level transaction value is counted and the result says so (set RPC_URL_<CHAIN> to a tracing node for full coverage).\n- Net flow per address and asset = received − sent across all transactions in the incident. Transactions are ordered by block number and transaction index.\n- Attacker heuristic: the transaction senders, contracts they created within the incident, and called contracts that end with a net gain form the suspect cluster; the sender of the earliest transaction is the likely attacker. Victims = addresses outside the cluster with the largest net losses. This is a heuristic, not attribution.\n- USD values (optional): DefiLlama historical prices at the first transaction's timestamp (coins.llama.fi/prices/historical), per token contract and native coin. Unpriced assets are listed.",
        "tags": [
          "web3"
        ],
        "x-mcp-tool": "blockchain_incident_replay",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BlockchainIncidentReplayInput"
              },
              "examples": {
                "example1": {
                  "summary": "Helper deployment + flash-loan drain (offline)",
                  "value": {
                    "mode": "pasted",
                    "chain": "ethereum",
                    "receipts": "[{\"transactionHash\":\"0xd1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1\",\"blockNumber\":\"0x1406f40\",\"transactionIndex\":\"0x3\",\"timestamp\":1791900000,\"from\":\"0xa77ac4e5000000000000000000000000000000a1\",\"to\":null,\"contractAddress\":\"0xc0ffee0000000000000000000000000000000c01\",\"value\":\"0x0\",\"status\":\"0x1\",\"gasUsed\":\"0x7a120\",\"effectiveGasPrice\":\"0x4a817c800\",\"logs\":[]},{\"transactionHash\":\"0xd2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2\",\"blockNumber\":\"0x1406f41\",\"transactionIndex\":\"0x0\",\"timestamp\":1791900012,\"from\":\"0xa77ac4e5000000000000000000000000000000a1\",\"to\":\"0xc0ffee0000000000000000000000000000000c01\",\"value\":\"0x16345785d8a0000\",\"status\":\"0x1\",\"gasUsed\":\"0x1e8480\",\"effectiveGasPrice\":\"0x4a817c800\",\"functionName\":\"attack(uint256)\",\"logs\":[{\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x0000000000000000000000001e4d000000000000000000000000000000000001\",\"0x000000000000000000000000c0ffee0000000000000000000000000000000c01\"],\"data\":\"0x000000000000000000000000000000000000000000000000000000e8d4a51000\",\"logIndex\":\"0x0\"},{\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x000000000000000000000000c0ffee0000000000000000000000000000000c01\",\"0x0000000000000000000000009001000000000000000000000000000000000001\"],\"data\":\"0x000000000000000000000000000000000000000000000000000000e8d4a51000\",\"logIndex\":\"0x1\"},{\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x0000000000000000000000009001000000000000000000000000000000000001\",\"0x000000000000000000000000c0ffee0000000000000000000000000000000c01\"],\"data\":\"0x0000000000000000000000000000000000000000000000000000012309ce5400\",\"logIndex\":\"0x2\"},{\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x000000000000000000000000c0ffee0000000000000000000000000000000c01\",\"0x0000000000000000000000001e4d000000000000000000000000000000000001\"],\"data\":\"0x000000000000000000000000000000000000000000000000000000e8d4a51000\",\"logIndex\":\"0x3\"},{\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x000000000000000000000000c0ffee0000000000000000000000000000000c01\",\"0x000000000000000000000000a77ac4e5000000000000000000000000000000a1\"],\"data\":\"0x0000000000000000000000000000000000000000000000000000003a35294400\",\"logIndex\":\"0x4\"}]}]",
                    "tokens": "{\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\":{\"symbol\":\"USDC\",\"decimals\":6}}"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BlockchainIncidentReplayResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "BlockchainIncidentReplayInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "Data source",
            "type": "string",
            "enum": [
              "live",
              "pasted"
            ],
            "default": "live"
          },
          "chain": {
            "title": "Chain",
            "type": "string",
            "enum": [
              "ethereum",
              "base",
              "arbitrum",
              "optimism",
              "polygon",
              "avalanche",
              "bsc"
            ],
            "default": "ethereum"
          },
          "txHashes": {
            "title": "Transaction hashes (in any order)",
            "description": "Up to 5; they are ordered by block and index.",
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 5
          },
          "receipts": {
            "title": "Pasted receipts JSON",
            "description": "Array of receipts with transactionHash, from, to, value, blockNumber, transactionIndex, status, logs (optionally timestamp, gasUsed, effectiveGasPrice, contractAddress, functionName). Or {\"receipts\":[…],\"tokens\":{address:{symbol,decimals}}}.",
            "type": "string",
            "maxLength": 2000000
          },
          "tokens": {
            "title": "Token metadata JSON (pasted mode)",
            "type": "string",
            "maxLength": 50000
          },
          "prices": {
            "title": "Value in USD at incident time (DefiLlama)",
            "type": "boolean",
            "default": true
          }
        },
        "required": []
      },
      "BlockchainIncidentReplayResult": {
        "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": [
              "chain",
              "transactions",
              "movements",
              "netFlows",
              "suspects",
              "victims",
              "pricing",
              "traceSupport"
            ],
            "properties": {
              "chain": {
                "type": "string"
              },
              "transactions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "hash",
                    "order",
                    "block",
                    "txIndex",
                    "timestamp",
                    "from",
                    "to",
                    "created",
                    "function",
                    "status",
                    "valueWei",
                    "feeWei",
                    "transfers",
                    "trace"
                  ],
                  "properties": {
                    "hash": {
                      "type": "string"
                    },
                    "order": {
                      "type": "integer"
                    },
                    "block": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "txIndex": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "timestamp": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "created": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "function": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "status": {
                      "type": "string"
                    },
                    "valueWei": {
                      "type": "string"
                    },
                    "feeWei": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "transfers": {
                      "type": "integer"
                    },
                    "trace": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "status",
                        "calls",
                        "maxDepth",
                        "internalValueTransfers",
                        "error"
                      ],
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "ok",
                            "unsupported",
                            "skipped"
                          ]
                        },
                        "calls": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        },
                        "maxDepth": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        },
                        "internalValueTransfers": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        },
                        "error": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "movements": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "txHash",
                    "seq",
                    "asset",
                    "symbol",
                    "from",
                    "to",
                    "amount",
                    "raw",
                    "source"
                  ],
                  "properties": {
                    "txHash": {
                      "type": "string"
                    },
                    "seq": {
                      "type": "integer"
                    },
                    "asset": {
                      "type": "string"
                    },
                    "symbol": {
                      "type": "string"
                    },
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number"
                    },
                    "raw": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string",
                      "enum": [
                        "tx-value",
                        "internal-call",
                        "transfer-log"
                      ]
                    }
                  }
                }
              },
              "netFlows": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "address",
                    "role",
                    "netUsd",
                    "gains",
                    "losses"
                  ],
                  "properties": {
                    "address": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string"
                    },
                    "netUsd": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "gains": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "asset",
                          "symbol",
                          "amount",
                          "usd"
                        ],
                        "properties": {
                          "asset": {
                            "type": "string"
                          },
                          "symbol": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number"
                          },
                          "usd": {
                            "type": [
                              "number",
                              "null"
                            ]
                          }
                        }
                      }
                    },
                    "losses": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "asset",
                          "symbol",
                          "amount",
                          "usd"
                        ],
                        "properties": {
                          "asset": {
                            "type": "string"
                          },
                          "symbol": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number"
                          },
                          "usd": {
                            "type": [
                              "number",
                              "null"
                            ]
                          }
                        }
                      }
                    }
                  }
                }
              },
              "suspects": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "likelyAttacker",
                  "cluster",
                  "profitUsd",
                  "profit"
                ],
                "properties": {
                  "likelyAttacker": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "cluster": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "profitUsd": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "profit": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "asset",
                        "symbol",
                        "amount",
                        "usd"
                      ],
                      "properties": {
                        "asset": {
                          "type": "string"
                        },
                        "symbol": {
                          "type": "string"
                        },
                        "amount": {
                          "type": "number"
                        },
                        "usd": {
                          "type": [
                            "number",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "victims": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "address",
                    "lossUsd",
                    "losses"
                  ],
                  "properties": {
                    "address": {
                      "type": "string"
                    },
                    "lossUsd": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "losses": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "asset",
                          "symbol",
                          "amount",
                          "usd"
                        ],
                        "properties": {
                          "asset": {
                            "type": "string"
                          },
                          "symbol": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number"
                          },
                          "usd": {
                            "type": [
                              "number",
                              "null"
                            ]
                          }
                        }
                      }
                    }
                  }
                }
              },
              "pricing": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "available",
                  "at",
                  "priced",
                  "unpriced"
                ],
                "properties": {
                  "available": {
                    "type": "boolean"
                  },
                  "at": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "priced": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "unpriced": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              },
              "traceSupport": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}