# BRAINIAC Contract Bytecode Compare

> BRAINIAC Contract Bytecode Compare is a paid API for AI agents from www.brainiac.software, paid per call via x402, $0.05/call, status unknown (last checked 2026-11-13).

Compares two EVM contract bytecodes byte-by-byte, returning a similarity score and structured difference findings with optional normalization for immutables and compiler metadata.

## Facts

- Endpoint: POST https://www.brainiac.software/api/v1/contract-security/contract-bytecode-compare?utm_source=zero.xyz
- Price: $0.05/call
- Payment: x402
- Status: unknown
- Last checked: 2026-11-13
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/brainiac-contract-bytecode-compare-6d3e46ae
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_NxP-VVBLa5JpFv5wI4BjD

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability brainiac-contract-bytecode-compare-6d3e46ae -d '<json body>'
```

Example prompt: Compare these two contract bytecodes for me and tell me how similar they are — the reference is 0xabc123... and the candidate I want to audit is 0xdef456... ; use normalized mode on runtime bytecode and mask the immutable range from byte 10 to 20.

## When to prefer this

Use this endpoint when you need a programmatic, byte-level similarity and difference analysis between two EVM contract bytecodes — especially when you want to mask compiler metadata suffixes or immutable value slots for a fair comparison. It is preferable to manual diffing tools when working in an agentic pipeline that needs structured findings and severity codes. It does not perform source-code verification or fetch bytecode from chain — use it after you have already retrieved the raw hex bytecodes.

## Known failure modes

- Invalid hex bytecode format (must match ^0x([0-9a-fA-F]{2})*$) returns 400
- Bytecode exceeding 131072 bytes (262146 hex chars) is rejected
- Immutable or expected-difference ranges with end <= start or values out of bounds return validation errors
- Unsupported mode or bytecodeKind enum values return 400
- Payment not received or insufficient USDC causes 402 response before processing
- Empty or missing candidate/reference fields cause schema validation failure

## How this service works

Pay-per-call APIs for AI agents: OFAC sanctions screening, compliance checks, token security, and Base chain data via x402. No account. Fixed USDC price. MCP-ready.

## Output

Returns a JSON object with: a similarity percentage (truncated to 4 decimal places), a comparison_status (e.g. 'identical' or 'different'), an array of findings (each with a code, detail, and severity), difference_ranges listing byte offsets that differ, keccak256 hashes of both inputs before masking, byte lengths of both inputs, and a limitations array explaining the caveats of the analysis.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "mode": {
   "enum": [
    "exact",
    "normalized"
   ],
   "type": "string"
  },
  "candidate": {
   "type": "string",
   "pattern": "^0x(?:[0-9a-fA-F]{2})*$",
   "maxLength": 262146
  },
  "reference": {
   "type": "string",
   "pattern": "^0x(?:[0-9a-fA-F]{2})*$",
   "maxLength": 262146
  },
  "bytecodeKind": {
   "enum": [
    "runtime",
    "creation"
   ],
   "type": "string"
  },
  "immutableRanges": {
   "type": "array",
   "items": {
    "type": "object",
    "required": [
     "start",
     "end"
    ],
    "properties": {
     "end": {
      "type": "integer",
      "maximum": 131072,
      "exclusiveMinimum": 0
     },
     "start": {
      "type": "integer",
      "maximum": 131072,
      "minimum": 0
     }
    },
    "additionalProperties": false
   },
   "maxItems": 32
  },
  "compilerMetadata": {
   "type": "object",
   "properties": {
    "version": {
     "type": "string",
     "maxLength": 40,
     "minLength": 1
    },
    "compiler": {
     "type": "string",
     "maxLength": 80,
     "minLength": 1
    }
   },
   "additionalProperties": false
  },
  "expectedDifferences": {
   "type": "array",
   "items": {
    "type": "object",
    "required": [
     "start",
     "end"
    ],
    "properties": {
     "end": {
      "type": "integer",
      "maximum": 131072,
      "exclusiveMinimum": 0
     },
     "start": {
      "type": "integer",
      "maximum": 131072,
      "minimum": 0
     }
    },
    "additionalProperties": false
   },
   "maxItems": 32
  },
  "constructorArguments": {
   "type": "string",
   "pattern": "^0x(?:[0-9a-fA-F]{2})*$",
   "maxLength": 262146
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "findings": [
   {
    "code": "immutable_ranges_masked",
    "detail": "The supplied immutable ranges were masked before the byte comparison.",
    "severity": "low"
   },
   {
    "code": "difference_expected",
    "detail": "The changed bytes at 1:2 fall inside expectedDifferences.",
    "severity": "low"
   },
   {
    "code": "bytecode_differs",
    "detail": "1 unmasked byte ranges differ. A difference is not a judgment that either contract is malicious.",
    "severity": "medium"
   },
   {
    "code": "metadata_differs",
    "detail": "The identified compiler metadata differs. This is not a source-code verification.",
    "severity": "medium"
   },
   {
    "code": "comparison_normalized",
    "detail": "Normalized comparison masked only the supplied immutable ranges and a compiler metadata suffix when that suffix was identified on both bytecodes.",
    "severity": "low"
   }
  ],
  "similarity": "80.0000",
  "limitations": [
   "Hashes are keccak256 of the supplied bytes before any masking.",
   "Similarity is the share of equal compared bytes, truncated to 4 decimal places with integer division. Masked bytes are left out of the count.",
   "A high similarity does not mean the contracts behave the same way.",
   "A difference is not a judgment that either bytecode is malicious.",
   "No source code was verified. Compiler metadata in the request is not a source match.",
   "Normalization masks only caller-supplied immutable ranges and a trailing compiler metadata suffix when bytecodeKind is not creation and the Solidity CBOR pattern is present on both bytecodes.",
   "Other bytecode is not removed. Creation bytecode is not split into init code and runtime code.",
   "Constructor arguments are checked as a suffix only when bytecodeKind is creation and the arguments are supplied.",
   "No chain state was read, and neither bytecode was executed."
  ],
  "candidate_hash": "0xa39f1cb59ec90edd47f46c666deb79f2aef5e485023e84f1586a677d13ff88a0",
  "reference_hash": "0xc8a324f6d1a8d63a729defc4c20b624f17d7dae1fdf4b5eec5f7c03a54a8da45",
  "candidate_length": 60,
  "reference_length": 60,
  "comparison_status": "different",
  "difference_ranges": [
   {
    "end": 2,
    "kind": "changed",
    "start": 1,
    "length": 1
   }
  ],
  "metadata_differences": [
   {
    "field": "metadata",
    "detail": "The compiler metadata suffixes differ.",
    "candidate": "0xa2646970667358220000000000000000000000000000000000000000000000000
… (truncated)
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/brainiac-contract-bytecode-compare-6d3e46ae/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from www.brainiac.software](https://www.zero.xyz/host/www.brainiac.software/llms.txt)
