{"record":{"id":"d99a5e1c3f682a04","repo":"hyperledger/fabric","slug":"chaincode-s-has-bad-definition","errorCode":null,"errorMessage":"chaincode %s has bad definition","messagePattern":"chaincode (.+?) has bad definition","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/scc/lscc/lscc.go","lineNumber":268,"sourceCode":"\t}\n\n\treturn nil\n}\n\nfunc (lscc *SCC) ChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*lifecycle.ChaincodeEndorsementInfo, error) {\n\tchaincodeDataBytes, err := qe.GetState(\"lscc\", chaincodeName)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"could not retrieve state for chaincode %s\", chaincodeName)\n\t}\n\n\tif chaincodeDataBytes == nil {\n\t\treturn nil, errors.Errorf(\"chaincode %s not found\", chaincodeName)\n\t}\n\n\tchaincodeData := &ccprovider.ChaincodeData{}\n\terr = proto.Unmarshal(chaincodeDataBytes, chaincodeData)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"chaincode %s has bad definition\", chaincodeName)\n\t}\n\n\tls := &LegacySecurity{\n\t\tSupport:      lscc.Support,\n\t\tPackageCache: &lscc.PackageCache,\n\t}\n\n\terr = ls.SecurityCheckLegacyChaincode(chaincodeData)\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"failed security checks\")\n\t}\n\n\treturn &lifecycle.ChaincodeEndorsementInfo{\n\t\tVersion:           chaincodeData.Version,\n\t\tEndorsementPlugin: chaincodeData.Escc,\n\t\tChaincodeID:       chaincodeData.Name + \":\" + chaincodeData.Version,\n\t}, nil\n}","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/scc/lscc/lscc.go#L250-L286","documentation":"ChaincodeEndorsementInfo raises this when the bytes stored under the chaincode name in lscc state exist but fail proto.Unmarshal into ccprovider.ChaincodeData — i.e. the chaincode definition on the ledger is malformed ('bad definition'). The wrapped error identifies the protobuf decode failure.","triggerScenarios":"Calling ChaincodeEndorsementInfo where GetState(\"lscc\", chaincodeName) returns non-nil bytes that cannot be decoded as ChaincodeData.","commonSituations":"Corrupted lscc state entries; definitions written by an incompatible Fabric version (schema drift); ledger restores/hand-edits that left invalid ChaincodeData under the lscc key.","solutions":["Read the wrapped proto error to identify the malformed field","Re-approve/re-commit (or re-instantiate in legacy flow) the chaincode definition so valid ChaincodeData is written","Restore lscc state from a consistent backup or rebuild the state DB","Check Fabric version compatibility between the data and the running peer"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Go: sanity-decode ChaincodeData before trusting the definition\nraw, err := qe.GetState(\"lscc\", chaincodeName)\nif err != nil || raw == nil { return err }\ndata := &ccprovider.ChaincodeData{}\nif err := proto.Unmarshal(raw, data); err != nil {\n    return fmt.Errorf(\"definition for %s is corrupt: %w\", chaincodeName, err)\n}\nif data.GetName() == \"\" || data.GetVersion() == \"\" {\n    return fmt.Errorf(\"definition for %s missing required fields\", chaincodeName)\n}","typeGuard":null,"tryCatchPattern":"// Go\ninfo, err := lscc.ChaincodeEndorsementInfo(channelID, name, qe)\nif err != nil && strings.Contains(err.Error(), \"has bad definition\") {\n    return fmt.Errorf(\"corrupt ChaincodeData for %s; re-approve/re-commit the definition: %w\", name, err)\n}","preventionTips":["Write chaincode definitions only through supported lscc/lifecycle APIs","Keep ledger data within Fabric versions whose ChaincodeData schema matches the peer","Rebuild the state DB from the blockchain if corruption is detected","Avoid hand-editing or partial restores of ledger state"],"tags":["hyperledger-fabric","protobuf","unmarshal","chaincode-definition"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}