{"record":{"id":"f9baa8a9913ae5e9","repo":"hyperledger/fabric","slug":"chaincode-event-chaincode-id-does-not-match-chainc-f9baa8","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/v20/plugindispatcher/dispatcher.go","lineNumber":167,"sourceCode":"\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn peer.TxValidationCode_INVALID_CHAINCODE, err\n\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_CHAINCODE, err\n\t}\n\n\twrNamespace := map[string]bool{}\n\twrNamespace[ccID] = true\n\tif respPayload.Events != nil {\n\t\tccEvent := &peer.ChaincodeEvent{}\n\t\tif err = proto.Unmarshal(respPayload.Events, ccEvent); err != nil {\n\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Wrapf(err, \"invalid chaincode event\")\n\t\t}\n\t\tif ccEvent.ChaincodeId != ccID {\n\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Errorf(\"chaincode event chaincode id does not match chaincode action chaincode id\")\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\tlogger.Errorf(\"duplicate namespace '%s' in txRWSet\", ns.NameSpace)\n\t\t\treturn peer.TxValidationCode_ILLEGAL_WRITESET,\n\t\t\t\terrors.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\twrNamespace[ns.NameSpace] = true\n\t\t}\n\t}\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v20/plugindispatcher/dispatcher.go#L149-L185","documentation":"During Dispatch validation, the unmarshaled ChaincodeEvent's ChaincodeId does not equal the chaincode ID from the header extension (ccID). Fabric throws this because an event claiming to come from a different chaincode than the executing transaction is inconsistent (spoofing or bug) and invalidates the tx.","triggerScenarios":"Chaincode emits an event whose ChaincodeId field (set by the shim/endorser) differs from the chaincode named in the proposal header — e.g. one chaincode fabricates an event attributed to another, or headers/payloads are mixed.","commonSituations":"Cross-chaincode event spoofing attempts; copy-pasted event-emitting code in shared chaincode repos where the ID constant was not updated; event created through custom serialization that hard-coded another cc ID.","solutions":["Fix the chaincode so events are emitted through shim.SetEvent, letting the shim/endorser stamp the correct ChaincodeId instead of hard-coding it.","Audit shared chaincode code for stale hard-coded chaincode names in events.","Regenerate the failing transaction after the chaincode fix.","If malicious, reject the tx (the validator already does) and investigate the submitter."],"exampleFix":"// before\nccEvent := &peer.ChaincodeEvent{ChaincodeId: \"othercc\", EventName: \"e\"}\n// after\nstub.SetEvent(\"e\", payload) // ChaincodeId derived from executing chaincode","handlingStrategy":"validation","validationCode":"// before endorsing, verify event attribution\nif (ccEvent.chaincodeId && ccEvent.chaincodeId !== invokingChaincodeId) { throw new Error('event chaincode id does not match action'); }","typeGuard":"function eventBelongsToChaincode(ev, ccId) { return !ev?.chaincodeId || ev.chaincodeId === ccId; }","tryCatchPattern":"try { validate(tx); } catch (err) { if (/event chaincode id does not match/.test(err.message)) { /* reject tx; investigate emitting chaincode */ } else { throw err; } }","preventionTips":["Emit events via shim.SetEvent so ChaincodeId is stamped automatically.","Avoid hard-coding chaincode names in event code.","Review shared chaincode libraries for stale IDs.","Treat mismatches as possible spoofing."],"tags":["hyperledger-fabric","validation","chaincode-events"],"backgroundTag":"chaincode-event-id-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"}