{"record":{"id":"b8828b478e80ae82","repo":"hyperledger/fabric","slug":"expected-cc-version-s-found-s-b8828b","errorCode":null,"errorMessage":"expected cc version %s, found %s","messagePattern":"expected cc version (.+?), found (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/v13/lscc_validation_logic.go","lineNumber":479,"sourceCode":"\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\n\t\tswitch lsccFunc {\n\t\tcase lscc.DEPLOY:\n\n\t\t\t/******************************************************************/\n\t\t\t/* security check 1 - cc not in the LCCC table of instantiated cc */\n\t\t\t/******************************************************************/\n\t\t\tif ccExistsOnLedger {\n\t\t\t\treturn policyErr(fmt.Errorf(\"Chaincode %s is already instantiated\", cdsArgs.ChaincodeSpec.ChaincodeId.Name))","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v13/lscc_validation_logic.go#L461-L497","documentation":"The validator compares the Version in the ChaincodeData produced by lscc against the Version in the submitted ChaincodeDeploymentSpec. If they differ, the write-set does not faithfully reflect the deployment spec and the transaction fails validation. This prevents an attacker from deploying one version while recording another on the ledger.","triggerScenarios":"An upgrade transaction where the new version in ChaincodeSpec.ChaincodeId.Version does not equal the Version serialized into the lscc ChaincodeData write — e.g. a stale or mismatched proposal.","commonSituations":"Custom lifecycle tooling hard-coding version \"1.0\" while the spec says \"2.0\", reusing an old signed proposal after bumping the version, SDK builds the ChaincodeData from different metadata than the spec, replaying a previous upgrade transaction.","solutions":["Regenerate the upgrade proposal with the correct, matching version in both ChaincodeSpec.ChaincodeId.Version and the lscc write value.","If using custom code, construct ChaincodeData.Version from cds.ChaincodeSpec.ChaincodeId.Version.","Discard cached signed proposals after changing the chaincode version.","Verify the chaincode package/version used by install and instantiate steps is the same."],"exampleFix":"// before\ncd := &ccprovider.ChaincodeData{Name: name, Version: \"1.0\", ...}\n// after\ncd := &ccprovider.ChaincodeData{Name: cds.ChaincodeSpec.ChaincodeId.Name, Version: cds.ChaincodeSpec.ChaincodeId.Version, ...}","handlingStrategy":"validation","validationCode":"// before submit: version in spec must equal version in lscc record\ncd := &ccprovider.ChaincodeData{}\nproto.Unmarshal(lsccWriteValue, cd)\nif cd.Version != cds.ChaincodeSpec.ChaincodeId.Version {\n    return fmt.Errorf(\"spec version %s != lscc record version %s\", cds.ChaincodeSpec.ChaincodeId.Version, cd.Version)\n}","typeGuard":"func versionMatches(cd *ccprovider.ChaincodeData, specVersion string) bool { return cd != nil && cd.Version == specVersion }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"expected cc version\") { /* rebuild proposal with matching version and resubmit */ }","preventionTips":["Bump version in one place and propagate it to spec, package, and proposal","Discard cached signed proposals after version changes","Parameterize versions in deployment scripts"],"tags":["hyperledger-fabric","lscc","chaincode-lifecycle","version-mismatch"],"backgroundTag":"chaincode-version-mismatch","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"}