Writing a space record whose value contains a CID link, bytes, or a large integer produces a different CID than other implementations produce for the same record. Since the space's commit hash is computed from those CIDs, another host can't reproduce it. For example, any record that holds a blob ref ({"ref": {"$link": …}}) can't be migrated into pds.js with its hash intact.
Steps #
Call com.atproto.space.putRecord with each record below, then compare the returned cid:
record |
pds.js | reference PDS |
|---|---|---|
{"$type":"x.y.z","l":{"$link":"bafyreihn37cccblw3mmwmmm6jewugcohecjf5kpzuciirdvisasq7k3siu"}} |
bafyreigun4a37nt6p44ukdfhqf3entqajk3xz6y45oukbajhhxkelzbsuu |
bafyreifmellnasy2yzh6oqv5neyemd42ul2bue5ktuaqy3tplfudd2hlki |
{"$type":"x.y.z","r":{"$bytes":"AAECAwQFBgc"}} |
bafyreieyx42erp3sdfu4uzafoe4lyuaff4ouzxqupvz4a7g7f7mq7h2zby |
bafyreif5yjfrjqzh5p3lzqunrl5ipzy3l7ft5topuxfn2lxw6fwhxffpoa |
{"$type":"x.y.z","n":9007199254740991} |
bafyreidapehd433jxrrrhgwqczcxtee2uowmdn5mn2yqtsqigsj7jzva2a |
bafyreidvgrj72eun7jf35d4bgskkehomonug2nbpvsuppecfiqimhkuszm |
Plain JSON values (strings, small integers, nulls, arrays, nested objects) give matching CIDs.
Cause #
packages/spaces/src/writer.jspasses the record JSON straight tocborEncodeDagCbor.{"$link": …}is encoded as a map instead of a CID, and{"$bytes": …}as a map instead of a byte string. It needs the same JSON-to-data-model conversion used for public records.encodeHeadinpackages/core/src/repo.js(around line 57) has no branch for values >= 2^32, so larger integers aren't encoded correctly.
Dug a bit further into the large-integer case. The value isn't just encoded differently: it gets dropped from the block entirely, so the stored CBOR is malformed.
Repro:
com.atproto.space.putRecordwith{"$type": "com.example.conformance.note", "v": 9007199254740991}.bafyreianpq5ttxqgvpv2bv4t3fxb5jgnc4lcigkwyqpjg6bcghxfyfh32y.com.atproto.space.getRepo, the record's block is:The header says two entries, but there are only three items. The
vvalue is missing, so"$type"gets read as v's value and the NSID as a dangling key. Hashing exactly those bytes gives pds.js's CID, so that's what's being stored and hashed.The correct encoding of
vis1b 00 1f ff ff ff ff ff ff(uint64), givingbafyreiciwjycqqgzdnzlb27b423cbfkwpazbuvwr6cuo2iky2izjpcy47i. Same thing for negatives past 32 bits:-4294967297should be3b 00 00 00 01 00 00 00 00.That fits the
encodeHeadnote in the issue: with no branch for values >= 2^32, it looks like nothing gets written at all rather than a wrong head. Since the record goes into the commit hash, a record like this can't round-trip through any other implementation, and a strict CBOR decoder would refuse the block.The
$link/$bytespart still reproduces at this build too: the CIDs equal DRISL over the lex-JSON as-is (maps).