-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
bugSomething isn't workingSomething isn't working
Description
The method protoutil.ComputeBlockDataHash from Fabric has a known bug. It calculates the hash on a concatenation of the TXs bytes, which is not crypto safe. A different set of TXs with different boundaries between the concatenated bytes would yield the same hash.
The solution is to break and calculate the hash like fabric-x-orderer calculates the batch digest:
github.com/hyperledger/fabric-x-orderer/common/types/batched_requests.go:L92
i.e.
// Digest calculates a sha256 digest on a safe representation of the BatchedRequests.
// This is equivalent to BatchRequestsDataHashWithSerialize, yet faster, and consumes less extra memory.
func (br *BatchedRequests) Digest() []byte {
if br == nil {
return sha256.New().Sum(nil)
}
sizeBuff := make([]byte, 4)
h := sha256.New()
for _, r := range *br {
binary.BigEndian.PutUint32(sizeBuff, uint32(len(r)))
h.Write(sizeBuff)
h.Write(r)
}
return h.Sum(nil)
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working