hyperledger/fabric · error

unmarshalling of ChaincodeData failed, error %s

Error message

unmarshalling of ChaincodeData failed, error %s

What it means

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.

Source

Thrown at core/handlers/validation/builtin/v12/validation_logic.go:613

		/* security check 0 - validation of rwset */
		/******************************************/
		// there has to be a write-set
		if lsccrwset == nil {
			return policyErr(fmt.Errorf("No read write set for lscc was found"))
		}
		// there must be at least one write
		if len(lsccrwset.Writes) < 1 {
			return policyErr(fmt.Errorf("LSCC must issue at least one single putState upon deploy/upgrade"))
		}
		// the first key name must be the chaincode id provided in the deployment spec
		if lsccrwset.Writes[0].Key != cdsArgs.ChaincodeSpec.ChaincodeId.Name {
			return policyErr(fmt.Errorf("expected key %s, found %s", cdsArgs.ChaincodeSpec.ChaincodeId.Name, lsccrwset.Writes[0].Key))
		}
		// the value must be a ChaincodeData struct
		cdRWSet := &ccprovider.ChaincodeData{}
		err = proto.Unmarshal(lsccrwset.Writes[0].Value, cdRWSet)
		if err != nil {
			return policyErr(fmt.Errorf("unmarshalling of ChaincodeData failed, error %s", err))
		}
		// the chaincode name in the lsccwriteset must match the chaincode name in the deployment spec
		if cdRWSet.Name != cdsArgs.ChaincodeSpec.ChaincodeId.Name {
			return policyErr(fmt.Errorf("expected cc name %s, found %s", cdsArgs.ChaincodeSpec.ChaincodeId.Name, cdRWSet.Name))
		}
		// the chaincode version in the lsccwriteset must match the chaincode version in the deployment spec
		if cdRWSet.Version != cdsArgs.ChaincodeSpec.ChaincodeId.Version {
			return policyErr(fmt.Errorf("expected cc version %s, found %s", cdsArgs.ChaincodeSpec.ChaincodeId.Version, cdRWSet.Version))
		}
		// it must only write to 2 namespaces: LSCC's and the cc that we are deploying/upgrading
		for _, ns := range txRWSet.NsRwSets {
			if ns.NameSpace != "lscc" && ns.NameSpace != cdRWSet.Name && len(ns.KvRwSet.Writes) > 0 {
				return policyErr(fmt.Errorf("LSCC invocation is attempting to write to namespace %s", ns.NameSpace))
			}
		}

		logger.Debugf("Validating %s for cc %s version %s", lsccFunc, cdRWSet.Name, cdRWSet.Version)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Reject the transaction that produced the malformed ChaincodeData
  2. Investigate how the invalid bytes entered the write-set (client SDK version mismatch or tampering)
Defensive patterns

Strategy: validation

Validate before calling

cd := &ccprovider.ChaincodeData{}
if err := proto.Unmarshal(ns.KvRwSet.Writes[0].Value, cd); err != nil {
    return fmt.Errorf("lscc write value is not ChaincodeData: %v", err)
}

Type guard

func isChaincodeData(val []byte) (*ccprovider.ChaincodeData, bool) {
    cd := &ccprovider.ChaincodeData{}
    if err := proto.Unmarshal(val, cd); err != nil || cd.Name == "" {
        return nil, false
    }
    return cd, true
}

Try / catch

if err := submitTx(envelope); err != nil {
    if strings.Contains(err.Error(), "unmarshalling of ChaincodeData failed") {
        // verify stock lscc wrote the value; align peer versions
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: Forked/modified lscc implementations; rwset manipulated by middleware; Fabric version mismatch where old lscc wrote a legacy format being validated by newer validator code.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/e063865e76ca9047. Report an issue: GitHub.