hyperledger/fabric · error · VSCCEndorsementPolicyError

invalid chaincode version '%s'

Error message

invalid chaincode version '%s'

What it means

The chaincode version in the deployment spec must match lscc.ChaincodeVersionRegExp. A version string with disallowed characters in a deploy/upgrade transaction causes VSCC to reject it with this policy error.

Source

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

			return policyErr(fmt.Errorf("unexpected chaincode spec type: %s", cdsArgs.ChaincodeSpec.Type.String()))
		}

		// validate chaincode name
		ccName := cdsArgs.ChaincodeSpec.ChaincodeId.Name
		// it must comply with the lscc.ChaincodeNameRegExp
		if !lscc.ChaincodeNameRegExp.MatchString(ccName) {
			return policyErr(errors.Errorf("invalid chaincode name '%s'", ccName))
		}
		// it can't match the name of one of the system chaincodes
		if _, in := systemChaincodeNames[ccName]; in {
			return policyErr(errors.Errorf("chaincode name '%s' is reserved for system chaincodes", ccName))
		}

		// validate chaincode version
		ccVersion := cdsArgs.ChaincodeSpec.ChaincodeId.Version
		// it must comply with the lscc.ChaincodeVersionRegExp
		if !lscc.ChaincodeVersionRegExp.MatchString(ccVersion) {
			return policyErr(errors.Errorf("invalid chaincode version '%s'", ccVersion))
		}

		// get the rwset
		pRespPayload, err := protoutil.UnmarshalProposalResponsePayload(cap.Action.ProposalResponsePayload)
		if err != nil {
			return policyErr(fmt.Errorf("GetProposalResponsePayload error %s", err))
		}
		if pRespPayload.Extension == nil {
			return policyErr(fmt.Errorf("nil pRespPayload.Extension"))
		}
		respPayload, err := protoutil.UnmarshalChaincodeAction(pRespPayload.Extension)
		if err != nil {
			return policyErr(fmt.Errorf("GetChaincodeAction error %s", err))
		}
		txRWSet := &rwsetutil.TxRwSet{}
		if err = txRWSet.FromProtoBytes(respPayload.Results); err != nil {
			return policyErr(fmt.Errorf("txRWSet.FromProtoBytes error %s", err))
		}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Use a version string matching ChaincodeVersionRegExp, e.g. "1.0", "1.0.1", "1.0-beta".
  2. Sanitize version strings in CI/deploy scripts before passing -v to `peer chaincode deploy`.
  3. Re-run the upgrade with a corrected version if a bad version slipped into the channel.

Example fix

// before
version := "v1.0 (beta)"
// after
version := "1.0-beta"
Defensive patterns

Strategy: validation

Validate before calling

var chaincodeVersionRegexp = regexp.MustCompile("^[A-Za-z0-9_.+-]+$")
if !chaincodeVersionRegexp.MatchString(ccVersion) {
    return fmt.Errorf("version %q will be rejected by VSCC", ccVersion)
}

Type guard

func isValidChaincodeVersion(v string) bool {
    return regexp.MustCompile("^[A-Za-z0-9_.+-]+$").MatchString(v)
}

Try / catch

if !isValidChaincodeVersion(version) {
    return fmt.Errorf("refusing to deploy: invalid chaincode version %q", version)
}

Prevention

When it happens

Trigger: Deploying/upgrading with ChaincodeId.Version containing characters outside the allowed set (alphanumeric, '-', '.', '+', '~' patterns), e.g. spaces, underscores, or tags like "v 1.0 beta".

Common situations: Passing a git tag or branch name with slashes/spaces as the -v flag, build scripts injecting un sanitized versions, or using semver build metadata unsupported by the peer's regex.

Related errors


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