{"record":{"id":"a981797551d8fc13","repo":"hyperledger/fabric","slug":"unmarshalling-of-chaincodedata-failed-error-s-a98179","errorCode":null,"errorMessage":"unmarshalling of ChaincodeData failed, error %s","messagePattern":"unmarshalling of ChaincodeData failed, error (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/v13/lscc_validation_logic.go","lineNumber":471,"sourceCode":"\t\t/* security check 0 - validation of rwset */\n\t\t/******************************************/\n\t\t// there has to be a write-set\n\t\tif lsccrwset == nil {\n\t\t\treturn policyErr(fmt.Errorf(\"No read write set for lscc was found\"))\n\t\t}\n\t\t// there must be at least one write\n\t\tif len(lsccrwset.Writes) < 1 {\n\t\t\treturn policyErr(fmt.Errorf(\"LSCC must issue at least one single putState upon deploy/upgrade\"))\n\t\t}\n\t\t// the first key name must be the chaincode id provided in the deployment spec\n\t\tif lsccrwset.Writes[0].Key != cdsArgs.ChaincodeSpec.ChaincodeId.Name {\n\t\t\treturn policyErr(fmt.Errorf(\"expected key %s, found %s\", cdsArgs.ChaincodeSpec.ChaincodeId.Name, lsccrwset.Writes[0].Key))\n\t\t}\n\t\t// the value must be a ChaincodeData struct\n\t\tcdRWSet := &ccprovider.ChaincodeData{}\n\t\terr = proto.Unmarshal(lsccrwset.Writes[0].Value, cdRWSet)\n\t\tif err != nil {\n\t\t\treturn policyErr(fmt.Errorf(\"unmarshalling of ChaincodeData failed, error %s\", err))\n\t\t}\n\t\t// the chaincode name in the lsccwriteset must match the chaincode name in the deployment spec\n\t\tif cdRWSet.Name != cdsArgs.ChaincodeSpec.ChaincodeId.Name {\n\t\t\treturn policyErr(fmt.Errorf(\"expected cc name %s, found %s\", cdsArgs.ChaincodeSpec.ChaincodeId.Name, cdRWSet.Name))\n\t\t}\n\t\t// the chaincode version in the lsccwriteset must match the chaincode version in the deployment spec\n\t\tif cdRWSet.Version != cdsArgs.ChaincodeSpec.ChaincodeId.Version {\n\t\t\treturn policyErr(fmt.Errorf(\"expected cc version %s, found %s\", cdsArgs.ChaincodeSpec.ChaincodeId.Version, cdRWSet.Version))\n\t\t}\n\t\t// it must only write to 2 namespaces: LSCC's and the cc that we are deploying/upgrading\n\t\tfor _, ns := range txRWSet.NsRwSets {\n\t\t\tif ns.NameSpace != \"lscc\" && ns.NameSpace != cdRWSet.Name && len(ns.KvRwSet.Writes) > 0 {\n\t\t\t\treturn policyErr(fmt.Errorf(\"LSCC invocation is attempting to write to namespace %s\", ns.NameSpace))\n\t\t\t}\n\t\t}\n\n\t\tlogger.Debugf(\"Validating %s for cc %s version %s\", lsccFunc, cdRWSet.Name, cdRWSet.Version)\n","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v13/lscc_validation_logic.go#L453-L489","documentation":"During LSCC (lifecycle system chaincode) validation, the validator unmarshals the first write value from the lscc write-set into a ChaincodeData protobuf. This error means that value is not a valid serialized ChaincodeData message, so Fabric rejects the transaction as a policy violation. It protects the ledger from malformed or tampered lifecycle records.","triggerScenarios":"Submitting an lscc deploy/upgrade transaction whose rwset writes a value at the chaincode key that is corrupt, truncated, serialized with an incompatible proto schema, or not a ChaincodeData at all.","commonSituations":"Manually crafted or third-party-modified deployment transactions, cross-version Fabric upgrades where the ChaincodeData proto changed, custom chaincode lifecycle tooling writing raw bytes to the lscc namespace, ledger corruption or a buggy shim implementation.","solutions":["Regenerate the deployment/upgrade proposal so lscc produces a correctly serialized ChaincodeData value (use the standard SDK/lifecycle flow, not hand-built rwsets).","Check that the peer, SDK, and the code that created the proposal use compatible Fabric/proto versions.","Verify the transaction payload was not truncated or re-encoded in transit (e.g. by a proxy or custom ordering logic).","If the ledger record itself is corrupt, restore from a checkpoint/snapshot or re-deploy the chaincode on a corrected channel."],"exampleFix":"// before: hand-crafting the lscc value\nvalue := []byte(\"mychaincode-v1\")\n// after: serialize a proper ChaincodeData\ncd := &ccprovider.ChaincodeData{Name: \"mychaincode\", Version: \"1.0\", ...}\nvalue, _ := proto.Marshal(cd)","handlingStrategy":"validation","validationCode":"// before submitting: verify the lscc write value decodes as ChaincodeData\ncd := &ccprovider.ChaincodeData{}\nif err := proto.Unmarshal(lsccWriteValue, cd); err != nil {\n    return fmt.Errorf(\"lscc value is not a valid ChaincodeData: %v\", err)\n}","typeGuard":"func isChaincodeData(b []byte) bool { cd := &ccprovider.ChaincodeData{}; return proto.Unmarshal(b, cd) == nil && cd.Name != \"\" }","tryCatchPattern":"err := validateLSCC(txRWSet); if err != nil { if strings.Contains(err.Error(), \"unmarshalling of ChaincodeData failed\") { /* rebuild proposal / regenerate rwset */ } return err }","preventionTips":["Never hand-craft lscc rwsets; use the standard SDK/lifecycle flow","Keep peer, SDK, and proto versions aligned","Validate transaction payloads before submission in custom tooling"],"tags":["hyperledger-fabric","protobuf","lscc","chaincode-lifecycle"],"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"}