Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in Byte Size of JSON Assertions Between Python and ot-node #9

Open
u-hubar opened this issue Aug 2, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@u-hubar
Copy link
Member

u-hubar commented Aug 2, 2023

Overview

We've come across an inconsistency in how the byte size of JSON assertions is calculated in the Python and ot-node/dkg.js. This discrepancy has led to an error in verification of the Knowledge Asset (KA) size on the node when trying to create a KA with special characters through the dkg.py.

Details

In the Python version, when encoding a specific character (e.g., \u2022) within a JSON string, I noticed that the resulting byte size of the JSON is calculated as 22. Here's an example code snippet for illustration:

import json

data = {"character": "\u2022"}
number_of_bytes = len(json.dumps(data, separators=(",", ":")).encode("utf-8"))
print(number_of_bytes)  # Outputs: 22

In contrast, using NodeJS, the calculation for the same JSON object yields a different byte size:

const data = { character: '\u2022' };
const numberOfBytes = Buffer.byteLength(JSON.stringify(data));
console.log(numberOfBytes) // Outputs: 19

Expected behaviour

The expected behavior would be a consistent byte size calculation for JSON assertions across both the Python and NodeJS implementations (and all other).

@u-hubar u-hubar added the bug Something isn't working label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant