{"record":{"id":"8b26a786c5b3cb00","repo":"hyperledger/fabric","slug":"chaincode-event-chaincode-id-does-not-match-chainc","errorCode":null,"errorMessage":"chaincode event chaincode id does not match chaincode action chaincode id","messagePattern":"chaincode event chaincode id does not match chaincode action chaincode id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/committer/txvalidator/v14/vscc_validator.go","lineNumber":127,"sourceCode":"\t}\n\t// sanity check on ccver\n\tif ccVer == \"\" {\n\t\terr = errors.New(\"invalid chaincode version\")\n\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, err\n\t}\n\n\tvar wrNamespace []string\n\talwaysEnforceOriginalNamespace := v.cr.Capabilities().V1_2Validation()\n\tif alwaysEnforceOriginalNamespace {\n\t\twrNamespace = append(wrNamespace, ccID)\n\t\tif respPayload.Events != nil {\n\t\t\tccEvent := &peer.ChaincodeEvent{}\n\t\t\tif err = proto.Unmarshal(respPayload.Events, ccEvent); err != nil {\n\t\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Wrapf(err, \"invalid chaincode event\")\n\t\t\t}\n\t\t\tif ccEvent.ChaincodeId != ccID {\n\t\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Errorf(\"chaincode event chaincode id does not match chaincode action chaincode id\")\n\t\t\t}\n\t\t}\n\t}\n\n\tnamespaces := make(map[string]struct{})\n\tfor _, ns := range txRWSet.NsRwSets {\n\t\t// check to make sure there is no duplicate namespace in txRWSet\n\t\tif _, ok := namespaces[ns.NameSpace]; ok {\n\t\t\treturn peer.TxValidationCode_ILLEGAL_WRITESET, errors.Errorf(\"duplicate namespace '%s' in txRWSet\", ns.NameSpace)\n\t\t}\n\t\tnamespaces[ns.NameSpace] = struct{}{}\n\n\t\tif !v.txWritesToNamespace(ns) {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Check to make sure we did not already populate this chaincode\n\t\t// name to avoid checking the same namespace twice","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v14/vscc_validator.go#L109-L145","documentation":"After successfully unmarshalling the chaincode event, VSCC checks that ccEvent.ChaincodeId equals the invoked chaincode's name (ccID from the header extension). A mismatch means the event claims a different chaincode than the action's chaincode, indicating forged or misattributed events, so the transaction is invalid with TxValidationCode_INVALID_OTHER_REASON.","triggerScenarios":"A chaincode (or payload tamperer) emits an event whose ChaincodeId field differs from the chaincode that produced the action — e.g. copying event structs from another chaincode's stub, or manually constructing events with a wrong ChaincodeId.","commonSituations":"Chaincode code that hardcodes another chaincode's ID in its event struct; generic event-emitting helper libraries setting an incorrect ID; deliberate tampering blocked by validation.","solutions":["Fix the chaincode so events are created only via stub.SetEvent, which sets ChaincodeId to the current chaincode.","Remove or correct any manually populated ChaincodeId in event structs inside the chaincode.","Audit shared helper/SDK code that constructs ChaincodeEvent objects for the whole network."],"exampleFix":"// before\nevt := &peer.ChaincodeEvent{ChaincodeId: \"othercc\", EventName: \"e\"}\n// after\nstub.SetEvent(\"e\", payload) // shim fills ChaincodeId automatically","handlingStrategy":"validation","validationCode":"if ccEvent.ChaincodeId != ccID {\n    return fmt.Errorf(\"event chaincode id %q does not match action chaincode id %q\", ccEvent.ChaincodeId, ccID)\n}","typeGuard":"func eventMatchesChaincode(evt *peer.ChaincodeEvent, expectedID string) bool {\n\treturn evt != nil && evt.ChaincodeId == expectedID\n}","tryCatchPattern":"if ccEvent.ChaincodeId != ccID {\n    logger.Warnf(\"tx rejected: event chaincode id mismatch (%s != %s)\", ccEvent.ChaincodeId, ccID)\n    return peer.TxValidationCode_INVALID_OTHER_REASON, nil\n}","preventionTips":["Create events exclusively via stub.SetEvent so the shim fills ChaincodeId.","Do not hardcode chaincode IDs inside chaincode event structs.","Review any shared event-emitting helpers across your chaincodes."],"tags":["fabric","transaction-validation","chaincode-events"],"backgroundTag":"chaincode-event-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"}