Skip to content

fix: drop the dependency on github.com/hyperledger/fabric - #59

Open
mbrandenburger wants to merge 2 commits into
hyperledger-labs:mainfrom
mbrandenburger:fix/drop-fabric-dependency
Open

mbrandenburger wants to merge 2 commits into
hyperledger-labs:mainfrom
mbrandenburger:fix/drop-fabric-dependency

Conversation

@mbrandenburger

@mbrandenburger mbrandenburger commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

cc-tools imports github.com/hyperledger/fabric for a single function: util.ComputeSHA256 in stubwrapper/stubWrapper.go. This PR replaces it with crypto/sha256 from the standard library and removes the Fabric dependency. It also fixes the CI test step, which has been failing since the module was renamed to cc-tools/v2.

Why

  • github.com/hyperledger/fabric is the code base of the Fabric peer and orderer, not a Go library meant to be imported by chaincode. Pulling it into cc-tools adds Fabric's whole dependency tree to every chaincode that uses cc-tools.
  • What cc-tools uses from it is a one-line function. Fabric's ComputeSHA256 computes SHA-256 through its default software BCCSP, which uses crypto/sha256, so sha256.Sum256 returns the same bytes.
  • cc-tools requires github.com/hyperledger/fabric v2.1.1+incompatible. That is the last +incompatible Fabric release; newer releases use the /v2 and /v3 module paths, so the dependency can't be raised to a patched version. Fabric v2.1.1 is affected by 6 published advisories, 5 of them high; 5 are fixed in Fabric 2.2.4 to 2.4.6.
  • For projects using cc-tools this shows up as security alerts they can't resolve. In Hyperledger Fabric Private Chaincode, the confidential-escrow sample has 6 open Dependabot alerts for github.com/hyperledger/fabric v2.1.1 (GHSA-j96p-r523-8r3w, GHSA-vjj6-5m9f-wqjw, GHSA-9w7j-q3xw-p9vh, GHSA-72x4-cq6r-jp4p, GHSA-v9w2-543f-h69m, GHSA-48gg-32q2-4r6m), all coming in through cc-tools.

Changes

  • stubwrapper/stubWrapper.go: GetPrivateDataHash hashes a value from the write set with sha256.Sum256 instead of util.ComputeSHA256.
  • go.mod/go.sum: github.com/hyperledger/fabric and the 11 modules it pulled in are gone.
  • test/stubwrapper_test.go: a test for the write-set path of GetPrivateDataHash, checked against the known SHA-256 of "abc". It passes both before and after this change, so the old and new code return the same hash.

CI fix

The test step in .github/workflows/go.yml ran go test github.com/hyperledger-labs/cc-tools/test. Since #57 renamed the module to github.com/hyperledger-labs/cc-tools/v2, that package path no longer exists in the module, and the step fails with "no required module provides package github.com/hyperledger-labs/cc-tools/test". This happens on main as well, independent of the change above; this PR is the first run of the workflow since the rename. The second commit adds /v2 to the path.

Testing

go build, go vet and go test ./... pass with Go 1.27.3 and with Go 1.22.0, the version in go.mod. The corrected CI test command passes as well, with 60.8% coverage. With this branch, github.com/hyperledger/fabric is no longer in the module graph of FPC's confidential-escrow sample.

stubwrapper used only util.ComputeSHA256 from Fabric, which requires
github.com/hyperledger/fabric v2.1.1+incompatible. That is the newest
+incompatible Fabric release, as later ones need the /v2 module path,
so users of cc-tools cannot move past its known vulnerabilities.

Use crypto/sha256 instead. Fabric's ComputeSHA256 is SHA-256 through
its software BCCSP, which uses crypto/sha256, so GetPrivateDataHash
returns the same hash. Add a test for the write-set path of
GetPrivateDataHash.

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
@mbrandenburger
mbrandenburger requested a review from a team as a code owner October 31, 2026 16:34
Since the module was renamed to github.com/hyperledger-labs/cc-tools/v2,
the test step looked for github.com/hyperledger-labs/cc-tools/test,
which no longer exists in the module, and failed with "no required
module provides package".

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant