Uploaded image for project: 'Fabric'
  1. Fabric
  2. FAB-18518

Improve re JSON determinism (private data hash not matching hashed data)



    • Unset
    • Unset
    • Unset


      Hello everyone, i am currently using node chaincode version 2.0, i am passing some transient data through node sdk to the chaincode and storing it using stub.putPrivateData(). in another chaincode method i pass the same transient object, hash it using sha256 and i use getPrivateDataHash to compare the hashes. What i expected is for them to be the same but i am getting different values.

      transient data: { class: 'org.pagare', amount: '100', id: '125', owner: 'org1' }
      transient hash: c29b9b457ec73633c5b99ffbef2ac27329c0762871f5471978a08d408c97df4b
      privatedatahash: 027d798fa011fc64a90f87d0546a377cdbd3649782d3980e02403c2706a6c319
      privatedata: { class: 'org.pagare', amount: '100', id: '125', owner: 'org1' }

      Cont: From what i could gather this behavior is because the privatedata hash is not the same as if you hash the privatedata in couchdb, i have another example.

      transient data: {"class":"org.pagare","idChain":"126","owner":"org1","amount":"100"}
      transient hash:   88ac0e128ad40d748a692c243c88fcd761cf0f41fd053b898275b41c71fe19d4
      privatedata hash: 88ac0e128ad40d748a692c243c88fcd761cf0f41fd053b898275b41c71fe19d4
      privatedata: {"amount":"100","class":"org.pagare","idChain":"126","owner":"org1"}

      1.- transient data object attributes follow the same order as how the object was created and passed to putPrivateData method.

      2.- transient hash is the sha256 hash of the transient data object
      3.- privatedata hash is the hash retrieved by the method getPrivateDataHash
      4.- both transient hash and privatedata hash are the same, meaning that the object using for hashing is the same as the one for creation
      5.- privatedata object is the object retrieved by the method getPrivateData, as you can see this object does not have the same order of attributes meaning that using this one to verify hash would give a different value. So, the object attributes are being reordered when it is stored in  privatedata couch db.
      6.- This behaviour doesnt happen if you use go chaincode.





            calanais Matthew B White
            icarrascol italo carrasco
            0 Vote for this issue
            6 Start watching this issue