hyperledger/fabric · error
data mismatch
Error message
data mismatch
What it means
After unmarshaling ccdata.Data into a fresh SignedCDSData, ValidateCC requires it to be proto.Equal to the data computed at package creation. A mismatch means the package's signature data was altered or is inconsistent, so the package is rejected.
Source
Thrown at core/common/ccprovider/sigcdspackage.go:216
// protobuf will gladly deserialize garbage and there are paths where we assume that
// a successful unmarshal means everything works but, if it fails, we try to unmarshal
// into something different.
if !isPrintable(ccdata.Name) {
return fmt.Errorf("invalid chaincode name: %q", ccdata.Name)
}
if ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {
return fmt.Errorf("invalid chaincode data %v (%v)", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)
}
otherdata := &SignedCDSData{}
err := proto.Unmarshal(ccdata.Data, otherdata)
if err != nil {
return err
}
if !proto.Equal(ccpack.data, otherdata) {
return errors.New("data mismatch")
}
return nil
}
// InitFromBuffer sets the buffer if valid and returns ChaincodeData
func (ccpack *SignedCDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {
env := &common.Envelope{}
err := proto.Unmarshal(buf, env)
if err != nil {
return nil, errors.New("failed to unmarshal envelope from bytes")
}
cHdr, sDepSpec, err := ccpackage.ExtractSignedCCDepSpec(env)
if err != nil {
return nil, err
}
if cHdr.Type != int32(common.HeaderType_CHAINCODE_PACKAGE) {View on GitHub (pinned to 2736b63f8f)
Solutions
- Re-run `peer chaincode signpackage` on the original CDS to regenerate consistent data
- Compare the package file checksum against the originally packaged artifact
- Do not hand-edit any field of the packaged ChaincodeData
Example fix
// before ccdata.Data = customSerializedBytes // altered after signing // after ccdata.Data = originalSignedBytes // from peer chaincode signpackage output
Defensive patterns
Strategy: validation
Validate before calling
func verifyPackageIntegrity(signedFile, origFile string) error {
s, err := os.ReadFile(signedFile); if err != nil { return err }
o, err := os.ReadFile(origFile); if err != nil { return err }
if len(s) < len(o) { return errors.New("signed package truncated") }
return nil
} Type guard
func looksTampered(pkgBytes, trustedChecksum string) bool {
sum := sha256.Sum256(pkgBytes)
return hex.EncodeToString(sum[:]) != trustedChecksum
} Try / catch
cd, err := GetCCPackage(buf, idFunc)
if err != nil {
if err.Error() == "data mismatch" {
return fmt.Errorf("package data altered after signing; re-sign with peer chaincode signpackage: %w", err)
}
return err
} Prevention
- Treat signed packages as immutable artifacts
- Record and compare SHA-256 checksums of packages across environments
- Re-sign from the original CDS rather than editing signed output
When it happens
Trigger: GetCCPackage -> ValidateCC where recomputing SignedCDSData from ccdata.Data yields a message different from ccpack.data — tampered or wrongly serialized package bytes.
Common situations: Packages modified after signing; incorrect serialization of the Data field by custom tooling; byte-level corruption of the installed package file.
Related errors
- only applicable for private data
- unknown operation type
- error reading chaincode install package at %s
- data mismatch
- chaincode %s exists
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/3f0e125347635936.
Report an issue: GitHub.