hyperledger/fabric · error · VSCCEndorsementPolicyError

Wrong number of arguments for invocation lscc(%s): expected

Error message

Wrong number of arguments for invocation lscc(%s): expected at least 2, received %d

What it means

For lscc DEPLOY or UPGRADE invocations, VSCC requires at least two arguments after the function name (typically the chaincode name and the ChaincodeDeploymentSpec). This error is returned when len(lsccArgs) < 2, i.e. the invoke supplied fewer arguments than the minimum, so validation cannot proceed and the transaction fails policy.

Source

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

	if cis.ChaincodeSpec == nil ||
		cis.ChaincodeSpec.Input == nil ||
		cis.ChaincodeSpec.Input.Args == nil {
		logger.Errorf("VSCC error: committing invalid vscc invocation")
		return policyErr(fmt.Errorf("malformed chaincode invocation spec"))
	}

	lsccFunc := string(cis.ChaincodeSpec.Input.Args[0])
	lsccArgs := cis.ChaincodeSpec.Input.Args[1:]

	logger.Debugf("VSCC info: ValidateLSCCInvocation acting on %s %#v", lsccFunc, lsccArgs)

	switch lsccFunc {
	case lscc.UPGRADE, lscc.DEPLOY:
		logger.Debugf("VSCC info: validating invocation of lscc function %s on arguments %#v", lsccFunc, lsccArgs)

		if len(lsccArgs) < 2 {
			return policyErr(fmt.Errorf("Wrong number of arguments for invocation lscc(%s): expected at least 2, received %d", lsccFunc, len(lsccArgs)))
		}

		if (!ac.PrivateChannelData() && len(lsccArgs) > 5) ||
			(ac.PrivateChannelData() && len(lsccArgs) > 6) {
			return policyErr(fmt.Errorf("Wrong number of arguments for invocation lscc(%s): received %d", lsccFunc, len(lsccArgs)))
		}

		cdsArgs, err := protoutil.UnmarshalChaincodeDeploymentSpec(lsccArgs[1])
		if err != nil {
			return policyErr(fmt.Errorf("GetChaincodeDeploymentSpec error %s", err))
		}

		if cdsArgs == nil || cdsArgs.ChaincodeSpec == nil || cdsArgs.ChaincodeSpec.ChaincodeId == nil ||
			cap.Action == nil || cap.Action.ProposalResponsePayload == nil {
			return policyErr(fmt.Errorf("VSCC error: invocation of lscc(%s) does not have appropriate arguments", lsccFunc))
		}

		switch cdsArgs.ChaincodeSpec.Type.String() {

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Supply at least 2 arguments after the function name: the chaincode name and a marshaled ChaincodeDeploymentSpec.
  2. Prefer the CLI ('peer chaincode install/instantiate/upgrade') or SDK lifecycle APIs which build the correct argument list.
  3. Dump the args array length before invoking to confirm arity matches the expected layout (2-5 args, or up to 6 with private channel data).
  4. Re-submit a corrected transaction after the failed one is marked invalid.

Example fix

// before: missing the deployment spec argument
args := [][]byte{[]byte("deploy"), []byte("mycc")}
// after: include name + ChaincodeDeploymentSpec
args := [][]byte{[]byte("deploy"), []byte("mycc"), cdsBytes}
Defensive patterns

Strategy: validation

Validate before calling

// lsccFunc args: everything after the function name
if len(lsccArgs) < 2 {
    return errors.New("lscc deploy/upgrade requires at least 2 args: chaincode name and ChaincodeDeploymentSpec")
}

Prevention

When it happens

Trigger: Invoking lscc deploy/upgrade with only 0 or 1 arguments after the function name — e.g. missing the ChaincodeDeploymentSpec argument, or building the args array incorrectly so the spec ends up in the wrong position.

Common situations: Client SDK code assembling deploy/upgrade args by hand and dropping the deployment spec; automated scripts invoking lscc directly with the wrong arity; upgrading Fabric and changing call layout without updating the client.

Related errors


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