Comparing TON cell payloads across two BOC encoders

Two services export the same signed message as a bag of cells (BOC), but a bytewise comparison fails. Determine whether the discrepancy is in the transport container or the root cell.

Serialize the same cell twice

In this @ton/core example, changing the index and checksum options changes the encoded bytes. The first comparison prints false. After decoding, the second prints true: both root cells have the same representation hash.

import { beginCell, Cell } from "@ton/core";
const root = beginCell().storeUint(42, 8).endCell();
const bare = root.toBoc({ idx: false, crc32: false });
const indexed = root.toBoc({ idx: true, crc32: true });
console.log(bare.equals(indexed));
console.log(Cell.fromBoc(bare)[0].hash().equals(Cell.fromBoc(indexed)[0].hash()));

Define the equality your importer needs

When identifying the single-root payload, check the root count first, then compare the decoded root hashes. Reading only the first root of a multi-root archive silently drops input. If your external manifest signs the exact BOC file, verify the byte digest specified by that manifest as well. The root hash and file digest answer different questions about what was transported.

docs.ton.org Bag of cells