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

Guaranteed JSON serialisation and deserialisation for java and javascript chaincodes #182

Open
davidkel opened this issue Mar 1, 2022 · 1 comment
Labels
bug Something isn't working Fabric

Comments

@davidkel
Copy link
Contributor

davidkel commented Mar 1, 2022

In fabric it's important that when serializing an object to a string that it results an a byte exact stream when run on different peers as part of the endorsement process. There are 2 points in a chaincode where this is important

  1. when putting data into the ledger via PutState
  2. when returning data to the caller as the caller my want to submit the proposal response to be committed

The contract api is responsible for converting a JSON string into an object on method entry and for converting objects back to a JSON string on return. Pure Shim chaincode need to perform to perform the serialization themselves as required.

Where the code serializes an Object for PutState we should use a deterministic library to be safe, when returning data we should avoid using the inbuilt serializer provided by the contract api and use a deterministic library. For node non contract api I think the JSON parser is safe because we are in total control of the conversion at method entry and method exit and using JSON functions will be consistent across different peers, what I can't be exact about is what the contract api does which means it could be non deterministic if a slightly different version of a library gets used say if chaincode is deployed at different times (need to consider a package-lock.json) but also what the contract-api might actually do under the covers. I can't vouch for Java at all either shim or contract-api based at this time so might be safer just to use a deterministic library

I don't believe Go chaincode would have that problem as the Go JSON Marshaller is deterministic around how objects are serialized.

see https://hyperledger-fabric.readthedocs.io/en/latest/chaincode4ade.html#json-determinism

@davidkel
Copy link
Contributor Author

Of course this will have an impact on the performance of the chaincode so we should perhaps create a separate fixed-asset version of this again not based on the contract api as it will add overhead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fabric
Projects
None yet
Development

No branches or pull requests

1 participant