hyperledger/fabric · error

instantiation policy cannot be nil for chaincode (%s:%s)

Error message

instantiation policy cannot be nil for chaincode (%s:%s)

What it means

A SignedChaincodeDeploymentSpec must carry an instantiation policy: getCDSData hashes it together with owner endorsements to build MetaDataHash used for signature verification. If scds.InstantiationPolicy is nil, hashing is impossible, so InitFromBuffer aborts with this error. It means the package was constructed without a policy, not that the policy failed validation.

Source

Thrown at core/common/ccprovider/sigcdspackage.go:153

	scdsdata := &SignedCDSData{}

	// get the code hash
	hash.Write(cds.CodePackage)
	scdsdata.CodeHash = hash.Sum(nil)

	hash.Reset()

	// get the metadata hash
	hash.Write([]byte(cds.ChaincodeSpec.ChaincodeId.Name))
	hash.Write([]byte(cds.ChaincodeSpec.ChaincodeId.Version))

	scdsdata.MetaDataHash = hash.Sum(nil)

	hash.Reset()

	// get the signature hashes
	if scds.InstantiationPolicy == nil {
		return nil, nil, nil, fmt.Errorf("instantiation policy cannot be nil for chaincode (%s:%s)", cds.ChaincodeSpec.ChaincodeId.Name, cds.ChaincodeSpec.ChaincodeId.Version)
	}

	hash.Write(scds.InstantiationPolicy)
	for _, o := range scds.OwnerEndorsements {
		hash.Write(o.Endorser)
	}
	scdsdata.SignatureHash = hash.Sum(nil)

	// marshall data
	b, err := proto.Marshal(scdsdata)
	if err != nil {
		return nil, nil, nil, err
	}

	hash.Reset()

	// compute the id
	hash.Write(scdsdata.CodeHash)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Rebuild the package ensuring SignedChaincodeDeploymentSpec.InstantiationPolicy is set (e.g. a SignedBy policy via cauthdsl) before signing.
  2. Upgrade the packaging tool/SDK to a version that always populates InstantiationPolicy.
  3. In test/tooling code set it explicitly, e.g. scds.InstantiationPolicy = utils.MarshalOrPanic(cauthdsl.SignedByAnyMember([]string{"Org"})).
  4. If the package comes from untrusted input, check InstantiationPolicy != nil before calling InitFromBuffer and reject with a clear message.

Example fix

// before
scds := &pb.SignedChaincodeDeploymentSpec{ChaincodeDeploymentSpec: cdsBytes}
// after
policy := utils.MarshalOrPanic(cauthdsl.SignedByAnyMember([]string{"SampleOrg"}))
scds := &pb.SignedChaincodeDeploymentSpec{ChaincodeDeploymentSpec: cdsBytes, InstantiationPolicy: policy}
Defensive patterns

Strategy: validation

Validate before calling

var scds pb.SignedChaincodeDeploymentSpec
if err := proto.Unmarshal(bytes, &scds); err != nil {
    return err
}
if scds.InstantiationPolicy == nil {
    return errors.New("package rejected: instantiation policy missing")
}

Try / catch

if err := pack.InitFromBuffer(buf, hasher); err != nil {
    if strings.Contains(err.Error(), "instantiation policy cannot be nil") {
        // regenerate package with a policy attached
    }
    return err
}

Prevention

When it happens

Trigger: Calling InitFromBuffer with a signed CDS package whose SignedChaincodeDeploymentSpec.InstantiationPolicy is nil/empty — packages built with an old SDK/tool, hand-crafted protobuf, or tests that sign the spec without setting a policy.

Common situations: Packages generated by a tool or SDK version that omitted InstantiationPolicy; deserializing a partially populated SignedChaincodeDeploymentSpec from a file or ledger; manually constructing a signed package in tests and forgetting to attach a cauthdsl policy.

Related errors


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