Skip to content

Commit

Permalink
Ensure MAX_DEPLOYMENT_VARIABLES limits the total number of variables …
Browse files Browse the repository at this point in the history
…in a program
  • Loading branch information
vicsn committed Apr 12, 2024
1 parent 614cf9c commit 07ac80c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion console/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub trait Network:
/// The maximum number of constraints in a deployment.
const MAX_DEPLOYMENT_CONSTRAINTS: u64 = 1 << 20; // 1,048,576 constraints
/// The maximum number of variables in a deployment.
const MAX_DEPLOYMENT_VARIABLES: u64 = 1 << 20; // 1,048,576 variables
const MAX_DEPLOYMENT_VARIABLES: u64 = 1 << 22; // 4,194,304 variables
/// The maximum number of microcredits that can be spent as a fee.
const MAX_FEE: u64 = 1_000_000_000_000_000;
/// The maximum number of microcredits that can be spent on a finalize block.
Expand Down
4 changes: 3 additions & 1 deletion synthesizer/process/src/stack/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ impl<N: Network> Stack<N> {
lap!(timer, "Compute the request for {}", function.name());
// Initialize the assignments.
let assignments = Assignments::<N>::default();
// Initialize the variable limit.
let variable_limit = N::MAX_DEPLOYMENT_VARIABLES / N::MAX_FUNCTIONS as u64;
// Initialize the constraint limit. Account for the constraint added after synthesis that makes the Varuna zerocheck hiding.
let Some(constraint_limit) = verifying_key.circuit_info.num_constraints.checked_sub(1) else {
// Since a deployment must always pay non-zero fee, it must always have at least one constraint.
Expand All @@ -143,7 +145,7 @@ impl<N: Network> Stack<N> {
burner_private_key,
assignments.clone(),
Some(constraint_limit as u64),
Some(N::MAX_DEPLOYMENT_VARIABLES),
Some(variable_limit),
);
// Append the function name, callstack, and assignments.
call_stacks.push((function.name(), call_stack, assignments));
Expand Down
6 changes: 6 additions & 0 deletions synthesizer/process/src/stack/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ impl<N: Network> StackExecute<N> for Stack<N> {
);
}

// Determine the number of variables allocated in the circuit.
let num_variables = A::num_variables();

// Eject the circuit assignment and reset the circuit.
let assignment = A::eject_assignment_and_reset();

Expand Down Expand Up @@ -445,6 +448,7 @@ impl<N: Network> StackExecute<N> for Stack<N> {
let metrics = CallMetrics {
program_id: *self.program_id(),
function_name: *function.name(),
num_variables,
num_instructions: function.instructions().len(),
num_request_constraints,
num_function_constraints,
Expand All @@ -467,6 +471,7 @@ impl<N: Network> StackExecute<N> for Stack<N> {
let metrics = CallMetrics {
program_id: *self.program_id(),
function_name: *function.name(),
num_variables,
num_instructions: function.instructions().len(),
num_request_constraints,
num_function_constraints,
Expand All @@ -487,6 +492,7 @@ impl<N: Network> StackExecute<N> for Stack<N> {
let metrics = CallMetrics {
program_id: *self.program_id(),
function_name: *function.name(),
num_variables,
num_instructions: function.instructions().len(),
num_request_constraints,
num_function_constraints,
Expand Down
1 change: 1 addition & 0 deletions synthesizer/process/src/trace/call_metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct CallMetrics<N: Network> {
pub program_id: ProgramID<N>,
pub function_name: Identifier<N>,
pub num_instructions: usize,
pub num_variables: u64,
pub num_request_constraints: u64,
pub num_function_constraints: u64,
pub num_response_constraints: u64,
Expand Down
9 changes: 8 additions & 1 deletion synthesizer/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,14 @@ program synthesis_num_constants.aleo;
function do:
cast 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 into r0 as [u32; 32u32];
cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r1 as [[u32; 32u32]; 32u32];
cast r1 r1 r1 r1 r1 r1 r1 r1 r1 r1 r1 r1 r1 r1 r1 r1 into r2 as [[[u32; 32u32]; 32u32]; 16u32];
cast r1 r1 r1 r1 r1 into r2 as [[[u32; 32u32]; 32u32]; 5u32];
hash.bhp1024 r2 into r3 as u32;
output r3 as u32.private;
function do2:
cast 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 0u32 into r0 as [u32; 32u32];
cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r1 as [[u32; 32u32]; 32u32];
cast r1 r1 r1 r1 r1 into r2 as [[[u32; 32u32]; 32u32]; 5u32];
hash.bhp1024 r2 into r3 as u32;
output r3 as u32.private;",
)
Expand Down

0 comments on commit 07ac80c

Please sign in to comment.