Skip to content

Fix protoutil.ComputeBlockDataHash calculation #83

@tock-ibm

Description

@tock-ibm

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)
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions