From acb8f46655d1706095b8193aa15d171c208f198e Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:03:45 -0700 Subject: [PATCH] error if constraint / variable limit is exceeded for deployment on current network --- errors/src/errors/cli/cli_errors.rs | 14 ++++++++++++++ leo/cli/commands/deploy.rs | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index d380de040c..2e604f29b1 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -285,4 +285,18 @@ create_messages!( msg: "Failed to get a network.".to_string(), help: Some(format!("Either make sure you have a `.env` file in current project directory with a `NETWORK` variable set, or set the `--network` flag when invoking the CLI command.\n Example: `NETWORK=testnet` or `leo {command} --network testnet`.")), } + + @backtraced + constraint_limit_exceeded { + args: (program: impl Display, limit: u64, network: impl Display), + msg: format!("Program `{program}` exceeds the constraint limit {limit} for deployment on network {network}."), + help: Some("Reduce the number of constraints in the program by reducing the number of instructions in transition functions.".to_string()), + } + + @backtraced + variable_limit_exceeded { + args: (program: impl Display, limit: u64, network: impl Display), + msg: format!("Program `{program}` exceeds the variable limit {limit} for deployment on network {network}."), + help: Some("Reduce the number of variables in the program by reducing the number of instructions in transition functions.".to_string()), + } ); diff --git a/leo/cli/commands/deploy.rs b/leo/cli/commands/deploy.rs index 11ff4d86f2..443f44b027 100644 --- a/leo/cli/commands/deploy.rs +++ b/leo/cli/commands/deploy.rs @@ -120,6 +120,15 @@ fn handle_deploy, N: Network>( // Generate the deployment let deployment = package.deploy::(None)?; + + // Check if the number of variables and constraints are within the limits. + if deployment.num_combined_variables()? > N::MAX_DEPLOYMENT_VARIABLES { + return Err(CliError::variable_limit_exceeded(name, N::MAX_DEPLOYMENT_VARIABLES, network).into()); + } + if deployment.num_combined_constraints()? > N::MAX_DEPLOYMENT_CONSTRAINTS { + return Err(CliError::constraint_limit_exceeded(name, N::MAX_DEPLOYMENT_CONSTRAINTS, network).into()); + } + let deployment_id = deployment.to_deployment_id()?; let store = ConsensusStore::>::open(StorageMode::Production)?;