{"record":{"id":"ef2c37c945ea5e48","repo":"hyperledger/fabric","slug":"duplicate-namespace-s-in-txrwset","errorCode":null,"errorMessage":"duplicate namespace '%s' in txRWSet","messagePattern":"duplicate namespace '(.+?)' in txRWSet","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/committer/txvalidator/v14/vscc_validator.go","lineNumber":136,"sourceCode":"\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\n\t\tif ns.NameSpace != ccID || !alwaysEnforceOriginalNamespace {\n\t\t\twrNamespace = append(wrNamespace, ns.NameSpace)\n\t\t}\n\n\t\tif !writesToLSCC && ns.NameSpace == \"lscc\" {\n\t\t\twritesToLSCC = true\n\t\t}\n\n\t\tif !writesToNonInvokableSCC && IsSysCCAndNotInvokableCC2CC(ns.NameSpace) {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v14/vscc_validator.go#L118-L154","documentation":"The transaction's read-write set (TxRwSet) contains two NsRwSets with the same NameSpace. VSCC rejects this as TxValidationCode_ILLEGAL_WRITESET because a well-formed rwset produced by the peer must have unique namespaces; duplicates indicate a tampered or malformed write set.","triggerScenarios":"A transaction whose Results bytes in the ChaincodeAction decode to a TxRwSet with repeated namespace entries — produced by custom rwset assembly, merging of rwsets without deduplication, or malicious construction.","commonSituations":"Offline endorsement / custom rwset-building tools concatenating per-chaincode rwsets; chaincode-side or middleware-side rwset manipulation; corruption in crafted transactions for testing.","solutions":["Ensure the rwset comes from real endorsement execution by the peer rather than being assembled or merged client-side.","If merging rwsets is unavoidable, deduplicate NsRwSets by NameSpace before submission.","Investigate the submitting client for rwset tampering if duplicates appear without custom tooling."],"exampleFix":"// before: append both rwsets\nallNs := append(rwsetA.NsRwSets, rwsetB.NsRwSets...)\n// after: dedupe by namespace\nseen := map[string]bool{}\nfor _, ns := range allNs { if seen[ns.NameSpace] { continue }; seen[ns.NameSpace] = true; out = append(out, ns) }","handlingStrategy":"validation","validationCode":"seen := map[string]struct{}{}\nfor _, ns := range txRWSet.NsRwSets {\n    if _, dup := seen[ns.NameSpace]; dup {\n        return fmt.Errorf(\"duplicate namespace %q in rwset; rebuild transaction\", ns.NameSpace)\n    }\n    seen[ns.NameSpace] = struct{}{}\n}","typeGuard":"func namespacesUnique(rwset *rwset.TxRwSet) bool {\n\tseen := map[string]struct{}{}\n\tfor _, ns := range rwset.NsRwSets {\n\t\tif _, ok := seen[ns.NameSpace]; ok {\n\t\t\treturn false\n\t\t}\n\t\tseen[ns.NameSpace] = struct{}{}\n\t}\n\treturn true\n}","tryCatchPattern":"if err != nil {\n    return peer.TxValidationCode_ILLEGAL_WRITESET, errors.Errorf(\"duplicate namespace '%s' in txRWSet\", ns.NameSpace)\n}","preventionTips":["Obtain rwsets from real peer endorsement instead of client-side assembly or merging.","If merging rwsets offline, deduplicate NsRwSets by NameSpace first.","Test custom endorsement pipelines against the peer validator before production."],"tags":["fabric","transaction-validation","rwset"],"backgroundTag":"illegal-writeset","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"}