{"record":{"id":"e063865e76ca9047","repo":"hyperledger/fabric","slug":"unmarshalling-of-chaincodedata-failed-error-s","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/v12/validation_logic.go","lineNumber":613,"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":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v12/validation_logic.go#L595-L631","documentation":"ValidateLSCCInvocation failed to unmarshal the value written under the chaincode key into ChaincodeData — the committed chaincode data blob is not a valid ChaincodeData protobuf, indicating a corrupted or malicious LSCC write.","triggerScenarios":"lscc's putState value is not valid ChaincodeData protobuf — e.g. a custom lscc wrote raw JSON/text, or the write value was corrupted or produced by a different lscc version with a different serialization.","commonSituations":"Forked/modified lscc implementations; rwset manipulated by middleware; Fabric version mismatch where old lscc wrote a legacy format being validated by newer validator code.","solutions":["Reject the transaction that produced the malformed ChaincodeData","Investigate how the invalid bytes entered the write-set (client SDK version mismatch or tampering)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"cd := &ccprovider.ChaincodeData{}\nif err := proto.Unmarshal(ns.KvRwSet.Writes[0].Value, cd); err != nil {\n    return fmt.Errorf(\"lscc write value is not ChaincodeData: %v\", err)\n}","typeGuard":"func isChaincodeData(val []byte) (*ccprovider.ChaincodeData, bool) {\n    cd := &ccprovider.ChaincodeData{}\n    if err := proto.Unmarshal(val, cd); err != nil || cd.Name == \"\" {\n        return nil, false\n    }\n    return cd, true\n}","tryCatchPattern":"if err := submitTx(envelope); err != nil {\n    if strings.Contains(err.Error(), \"unmarshalling of ChaincodeData failed\") {\n        // verify stock lscc wrote the value; align peer versions\n    }\n}","preventionTips":["Do not fork or patch lscc serialization","Keep all peers on the same Fabric release","Avoid middleware that rewrites rwset values"],"tags":["hyperledger-fabric","lscc","protobuf","chaincodedata"],"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"}