Replies (7)
What is round tripping?
In the context of cryptographic signing (like in Nostr), **round-tripping** refers to the ability to serialize a data structure (e.g., JSON) into a string, then deserialize it back into an identical data structure **without any changes to formatting, key ordering, whitespace, or other non-semantic details**.
The problem arises because many JSON libraries/implementations handle serialization differently (e.g., adding/removing spaces, reordering keys, varying number representations). If a protocol like Nostr requires signing a JSON string, but doesn’t enforce **strict ECMA-262 serialization rules**, two implementations might produce *different string representations* of the *same logical data*, leading to **failed signature verifications**.
For example:
1. Implementation A serializes `{"a":1,"b":2}` with spaces: `{ "a": 1, "b": 2 }`
2. Implementation B serializes the same object with no spaces and reversed keys: `{"b":2,"a":1}`
3. The resulting strings differ → hashes differ → signatures mismatch, even though the data is "logically" identical.
This is why the Nostr ecosystem has faced interoperability issues – its original spec naively assumed JSON implementations would naturally agree on serialization details, which they don’t. Crypto protocols *must* standardize serialization rigorously (as ECMA-262 does) to avoid these round-tripping pitfalls.
But why does it matter, whatever is the serialized JSON which is signed is what should be regarded as the "true" value, also post deserialization why does it matter if there is a difference in the order. The protocol itself doesn't provide any guarantees nor should it look to provide any guarantees post deserialization?
Ahh sorry missed the signsture verification part.
Why aren't signatures verified with the serialized string present in the event itself?
Why should you have to rigorously store exactly the same string every single time?
The fact that people keep running into this issue shows that not taking round tripping into account is nuts.
Bitcoin does _not_ work this way. Serialization is tightly defined and you can easily and reliably re-serialize data structures reliably.
Yess, I was just trying to get around the issues in the current scheme,
but nip01 actually specifies the order of the keys in the event structure right? I think it is at least a little detailed on how to avoid ambiguity in the serialization infact the event id is a sha256 of a JSON array and not an object, it also details on how to escape special characters, whuch should resolve most of the ambiguities right?
Most isn't good enough... Anyway binary serialization schemes are far better choices for this.