@@ -36,15 +36,15 @@ pub fn transform_function(
3636 is_internal : bool ,
3737 is_static : bool ,
3838) -> Result < ( ) , AztecMacroError > {
39+ assert ! ( matches!( ty, "Private" | "Public" ) ) ;
3940 let context_name = format ! ( "{}Context" , ty) ;
4041 let inputs_name = format ! ( "{}ContextInputs" , ty) ;
4142 let return_type_name = format ! ( "{}CircuitPublicInputs" , ty) ;
42- let is_avm = ty == "Avm" ;
4343 let is_private = ty == "Private" ;
4444
4545 // Force a static context if the function is static
4646 if is_static {
47- let is_static_check = create_static_check ( func. name ( ) , is_avm ) ;
47+ let is_static_check = create_static_check ( func. name ( ) , is_private ) ;
4848 func. def . body . statements . insert ( 0 , is_static_check) ;
4949 }
5050
@@ -72,10 +72,10 @@ pub fn transform_function(
7272 }
7373
7474 // Insert the context creation as the first action
75- let create_context = if !is_avm {
76- create_context ( & context_name, & func. def . parameters ) ?
75+ let create_context = if is_private {
76+ create_context_private ( & context_name, & func. def . parameters ) ?
7777 } else {
78- create_context_avm ( ) ?
78+ create_context_public ( ) ?
7979 } ;
8080 func. def . body . statements . splice ( 0 ..0 , ( create_context) . iter ( ) . cloned ( ) ) ;
8181
@@ -84,7 +84,7 @@ pub fn transform_function(
8484 func. def . parameters . insert ( 0 , input) ;
8585
8686 // Abstract return types such that they get added to the kernel's return_values
87- if !is_avm {
87+ if is_private {
8888 if let Some ( return_values_statements) = abstract_return_values ( func) ? {
8989 // In case we are pushing return values to the context, we remove the statement that originated it
9090 // This avoids running duplicate code, since blocks like if/else can be value returning statements
@@ -101,13 +101,13 @@ pub fn transform_function(
101101 }
102102
103103 // Push the finish method call to the end of the function
104- if !is_avm {
104+ if is_private {
105105 let finish_def = create_context_finish ( ) ;
106106 func. def . body . statements . push ( finish_def) ;
107107 }
108108
109109 // The AVM doesn't need a return type yet.
110- if !is_avm {
110+ if is_private {
111111 let return_type = create_return_type ( & return_type_name) ;
112112 func. def . return_type = return_type;
113113 func. def . return_visibility = Visibility :: Public ;
@@ -116,7 +116,7 @@ pub fn transform_function(
116116 }
117117
118118 // Public functions should have unconstrained auto-inferred
119- func. def . is_unconstrained = matches ! ( ty , "Public" | "Avm" ) ;
119+ func. def . is_unconstrained = !is_private ;
120120
121121 // Private functions need to be recursive
122122 if is_private {
@@ -285,8 +285,8 @@ fn create_mark_as_initialized(ty: &str) -> Statement {
285285/// ```noir
286286/// assert(context.inputs.call_context.is_static_call == true, "Function can only be called statically")
287287/// ```
288- fn create_static_check ( fname : & str , is_avm : bool ) -> Statement {
289- let is_static_call_expr = if !is_avm {
288+ fn create_static_check ( fname : & str , is_private : bool ) -> Statement {
289+ let is_static_call_expr = if is_private {
290290 [ "inputs" , "call_context" , "is_static_call" ]
291291 . iter ( )
292292 . fold ( variable ( "context" ) , |acc, member| member_access ( acc, member) )
@@ -410,7 +410,7 @@ fn serialize_to_hasher(
410410/// let mut context = PrivateContext::new(inputs, hasher.hash());
411411/// }
412412/// ```
413- fn create_context ( ty : & str , params : & [ Param ] ) -> Result < Vec < Statement > , AztecMacroError > {
413+ fn create_context_private ( ty : & str , params : & [ Param ] ) -> Result < Vec < Statement > , AztecMacroError > {
414414 let mut injected_statements: Vec < Statement > = vec ! [ ] ;
415415
416416 let hasher_name = "args_hasher" ;
@@ -471,30 +471,33 @@ fn create_context(ty: &str, params: &[Param]) -> Result<Vec<Statement>, AztecMac
471471 Ok ( injected_statements)
472472}
473473
474- /// Creates the private context object to be accessed within the function, the parameters need to be extracted to be
475- /// appended into the args hash object.
474+ /// Creates the public context object to be accessed within the function.
476475///
477476/// The replaced code:
478477/// ```noir
479- /// #[aztec(public-vm )]
480- /// fn foo(inputs: AvmContextInputs , ...) -> Field {
481- /// let mut context = AvmContext ::new(inputs);
478+ /// #[aztec(public)]
479+ /// fn foo(inputs: PublicContextInputs , ...) -> Field {
480+ /// let mut context = PublicContext ::new(inputs);
482481/// }
483482/// ```
484- fn create_context_avm ( ) -> Result < Vec < Statement > , AztecMacroError > {
483+ fn create_context_public ( ) -> Result < Vec < Statement > , AztecMacroError > {
485484 let mut injected_expressions: Vec < Statement > = vec ! [ ] ;
486485
487486 // Create the inputs to the context
488- let ty = "AvmContext" ;
489487 let inputs_expression = variable ( "inputs" ) ;
490- let path_snippet = ty. to_case ( Case :: Snake ) ; // e.g. private_context
491488
492489 // let mut context = {ty}::new(inputs, hash);
493490 let let_context = mutable_assignment (
494491 "context" , // Assigned to
495492 call (
496- variable_path ( chained_dep ! ( "aztec" , "context" , & path_snippet, ty, "new" ) ) , // Path
497- vec ! [ inputs_expression] , // args
493+ variable_path ( chained_dep ! (
494+ "aztec" ,
495+ "context" ,
496+ "public_context" ,
497+ "PublicContext" ,
498+ "new"
499+ ) ) , // Path
500+ vec ! [ inputs_expression] , // args
498501 ) ,
499502 ) ;
500503 injected_expressions. push ( let_context) ;
0 commit comments