Leonardo Custodio
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Why "almost" deterministic isn't enough > This is a collaborative post with Rebecca Turner, she was amazing in reviewing, compiling and improving all the text! Thank you Rebecca!!! In the previous posts exploring data serialization for Web3 ([Part 1: JSON vs CBOR](https://hackmd.io/@leonardocustodio/json-vs-cbor) and [Part 2: An Intro to dCBOR](https://hackmd.io/@leonardocustodio/deterministic-data-intro-to-dcbor), we introduced dCBOR and touched on the high-level need for deterministic data in blockchains. Today in part 3, we want to go deeper, and explore some concrete examples that show **why** determinism is non-negotiable for blockchain applications, and why dCBOR's strict rules exist to solve real-world engineering problems \- not just for abstract mathematical purity. This article covers: * the core problem with non-determinism * some real-world examples: * breakdowns with distributed consensus * failures verifying digital signatures * deduplication and storage loss in content-addressable systems * cache invalidation * breaking Gordian Envelopes. * how the above informs dCBOR’s strict rules * what this means for us as developers. ## 1\. The core problem: bytes, not objects As we saw in the first post, logically identical data can produce completely different hashes when serialized differently. In blockchain systems, **we sign bytes, not objects**. If the bytes drift, the signature breaks. This creates a class of bugs that are a nightmare to debug: they appear intermittent, platform-dependent, version-dependent, and often non-reproducible. The root cause lies not in application logic but in a layer that developers typically assume to be transparent and reliable. Let's look at five real-world scenarios where this breaks systems. ## 2\. Why does this matter? Real-world failure scenarios ### 2.1. Distributed consensus breakdowns: transaction ordering In a blockchain system (i.e. where nodes must independently verify, hash, then reach consensus on the state of transactions), non-determinism introduces transaction ordering disagreements. **What should happen:** ``` Transaction Data (logical): { "from": "0xAlice", "to": "0xBob", "amount": 100 } All nodes compute hash: 0xabcd1234... (deterministic) All nodes agree ✓ ``` **What happens with non-deterministic serialization:** ``` Node A serializes as: {"from": "0xAlice", "to": "0xBob", "amount": 100} Hash: 0xabcd1234... Node B's CBOR library (different version or language): Encodes the same logical data but in a different byte sequence Because the implementation doesn't enforce map key ordering Hash: 0xdef56789... Node C's serialization (different implementation): Hash: 0x98765432... ``` **The result:** Nodes compute different hashes for the same transaction. They cannot agree on whether a given transaction is in the block. Some nodes accept the block, others reject it. The consensus mechanism breaks. The blockchain forks. This has indeed [happened in blockchain systems](https://github.com/akircanski/coinbugs) where serialization rules weren't strict enough. ### 2.2. Digital signature verification failures Imagine: - Alice signs a transaction using Signing Service A (which uses dCBOR) - The signature is computed as: `Signature = Sign(Hash(Serialize(transaction_data)))` - Bob tries to verify the signature using Verification Service B (which uses less strict CBOR) **What should happen:** ``` Alice: data = {sender: Alice, amount: 100} canonicalized = dCBOR.encode(data) // Deterministic hash = SHA256(canonicalized) // e.g., 0xabcd1234 signature = Sign(private_key, hash) Bob (verifies with same rules): data = {sender: Alice, amount: 100} canonicalized = dCBOR.encode(data) // SAME canonicalization hash = SHA256(canonicalized) // e.g., 0xabcd1234 (SAME!) Verify(public_key, signature, hash) // ✓ SUCCESS ``` **What happens with non-deterministic serialization:** ``` Alice (using deterministic rules): serialized = encode(data) // Gets specific byte sequence A hash = SHA256(sequence A) // 0xabcd1234 signature = Sign(private_key, hash) Bob (using different library/version): serialized = encode(same data) // Gets DIFFERENT byte sequence B! hash = SHA256(sequence B) // 0xdef56789 (DIFFERENT!) Verify(public_key, signature, 0xdef56789) // ✗ FAILS! ``` **The result:** A perfectly valid transaction signed by Alice cannot be verified by Bob's system. In a blockchain context the transaction is rejected as invalid, user funds might be lost, and the entire transaction validity model breaks. This failure is particularly dangerous because it can be exploited, not just occur accidentally. ### 2.3. Deduplication and storage loss in content-addressable systems In a blockchain system that uses IPFS or similar content-addressable storage, multiple users store what is logically identical Envelope data. The system should deduplicate (store only once, reference many times). **What should happen:** ``` User A stores Envelope: {id: 1, metadata: {created: 2023}} hash = SHA256(dCBOR.encode(envelope)) // 0xabcd1234 stored_at = "ipfs://Qm..." (keyed by 0xabcd1234) User B stores same Envelope: {id: 1, metadata: {created: 2023}} hash = SHA256(dCBOR.encode(envelope)) // 0xabcd1234 (SAME!) storage_check: "ipfs://Qm..." already exists references_count = 2, storage_used = 1x Total storage: 1 copy, 2 references ✓ ``` **What happens with non-deterministic serialization:** ``` User A stores: {id: 1, metadata: {created: 2023}} Serialized by System 1: 0xabcd1234... Hash: QmAAA... User B stores same logical data: Serialized by System 2: 0xdef56789... Hash: QmBBB... (DIFFERENT!) storage_check: doesn't find QmAAA... stores as new entry Total storage: 2 copies of identical data Storage wasted: 100% ``` **The result:** This failure mode affects not just correctness but economics and resource efficiency. - Storage space is wasted by redundant copies - Bandwidth is wasted transmitting duplicates - Deduplication is completely ineffective - In large-scale systems, this adds significant cost. ### 2.4. Cache invalidation and computation waste: query cache can't find previous results A blockchain system maintains a cache of computed query results. The cache key is a hash of the query parameters, so the same query reuses cached results. **What should happen:** ``` Query 1: get_balance(user: Alice, block: 100) Serialize: produces same bytes every time Hash: 0xabcd1234 Cache miss: compute balance Store result in cache[0xabcd1234] = 1000 tokens Query 2: get_balance(user: Alice, block: 100) // Same query Serialize: produces SAME bytes Hash: 0xabcd1234 Cache hit: return 1000 tokens ✓ (no computation needed) Cache effectiveness: 50% hit rate ✓ ``` **What happens with non-deterministic serialization:** ``` Query 1: get_balance(user: Alice, block: 100) Serialized as: {...} Hash: 0xabcd1234 Cache miss: compute balance Store in cache[0xabcd1234] = 1000 Query 2: get_balance(user: Alice, block: 100) // Same query Serialized differently by different system: {...} Hash: 0xdef56789 (DIFFERENT!) Cache miss: recompute balance Store in cache[0xdef56789] = 1000 Query 3: get_balance(user: Alice, block: 100) // Still same query Hash: 0x98765432 (DIFFERENT again!) Cache miss: recompute yet again Now we have cache entries for 0xabcd, 0xdef5, 0x9876... all duplicate results Cache effectiveness: 0% hit rate ✗ ``` **The result:** This is a subtler failure that causes performance degradation rather than correctness issues. - Every identical query is computed multiple times; cache becomes useless - Computational load increases proportionally; system performance degrades - For a high-traffic blockchain system, this could mean 10x-100x increase in CPU usage. ### 2.5. Breaking Gordian Envelopes: elided data cannot be verified **Setup:** - Alice creates a Gordian Envelope with sensitive financial data - She computes cryptographic digests of each component - She can later elide (redact) components while proving they were in the original - Bob wants to verify the proof **What should happen (simplified):** ``` Original Envelope tree: Root hash = hash(metadata + contents) Contents = hash(transaction A) + hash(transaction B) + hash(transaction C) Alice elides transaction B, shares: - transaction A (unredacted) - hash(transaction B) (proof it was there) - transaction C (unredacted) - Root hash (to prove against) Bob verifies: - Computes hash of transaction A → matches expected - Uses provided hash(transaction B) - Computes hash of transaction C → matches expected - Rebuilds root hash from all three → should match provided root hash - ✓ Verification succeeds, proves B was original ``` **What happens with non-deterministic serialization:** ``` Alice creates envelope with deterministic encoding Computes hashes: hash(A), hash(B), hash(C), root_hash She sends to Bob, but Bob's system uses less strict CBOR When Bob receives transaction A and tries to verify: Bob's system re-encodes transaction A → Different byte sequence! Bob computes hash → doesn't match expected hash Verification fails: either data was tampered with, or proof is invalid Bob cannot prove data integrity, even though data is legitimate ``` **The result:** This failure mode is specific to systems like Gordian Envelope that depend on cryptographic proofs for selective disclosure. For privacy-preserving systems: - Privacy mechanism breaks down - Users cannot selectively disclose information with cryptographic proofs - Either transactions cannot be verified (false negatives), or - Legitimate transactions fail verification (false positives) - The entire Gordian Envelope system becomes unusable. ## 3\. Why dCBOR's Strict Rules Exist To support these use cases, dCBOR is opinionated. It doesn't just suggest "good practices"; it invalidates choices. Each rule is there because **each rule prevents a specific category of failures at scale**. Based on the *CBOR, dCBOR, and Gordian Envelope Book*, here are the critical constraints: | Rule | What It Prevents | | :---- | :---- | | **Numeric Reduction** (2.0 → 2\) | Cache misses from equivalent numbers with different encodings | | **Mandatory Map Key Sorting** | Consensus failure, signature verification failure, deduplication breakdown | | **NFC String Normalization** | Hash mismatches from Unicode-equivalent strings | | **No Indefinite Lengths** | Arrays/maps encoded differently with/without length prefix | | **Restricted Simple Values** | Cross-implementation ambiguity in reserved values | | **Mandatory Decoder Validation** | Systems accepting non-deterministic encodings | ## 4\. Conclusion Determinism isn't just about data hygiene; it's the bedrock of verifiable computing. Using dCBOR provides: 1. **Correctness guarantees** \- Cryptographic operations work as designed 2. **Interoperability** \- Systems in different languages/versions agree 3. **Efficiency** \- Caching and deduplication work correctly 4. **Debuggability** \- Non-determinism cannot be the root cause of failures 5. **Scalability** \- These guarantees hold as systems grow Watch this space for the next post in this series where we'll explore **Gordian Envelopes** and how they leverage dCBOR's deterministic guarantees to build privacy-preserving, verifiable data structures.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully