From f180c85fe95733e9cdb7ae3c0f1cba614a168e05 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 27 Feb 2024 12:03:21 +0000 Subject: [PATCH 1/3] fix: Change function limit to private function limit --- .../contracts/token_contract/src/main.nr | 10 ++++++++ noir/aztec_macros/src/lib.rs | 24 ++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index 7a20030245a..ca174b69277 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -66,6 +66,16 @@ contract Token { } // docs:end:constructor + #[aztec(private)] + fn foo(decimals: u8) { + assert(decimals == 0); + } + + #[aztec(private)] + fn bar(decimals: u64) { + assert(decimals == 0); + } + // docs:start:set_admin #[aztec(public)] fn set_admin(new_admin: AztecAddress) { diff --git a/noir/aztec_macros/src/lib.rs b/noir/aztec_macros/src/lib.rs index 07dca820fd9..5333f4455d1 100644 --- a/noir/aztec_macros/src/lib.rs +++ b/noir/aztec_macros/src/lib.rs @@ -63,12 +63,12 @@ impl MacroProcessor for AztecMacro { } const FUNCTION_TREE_HEIGHT: u32 = 5; -const MAX_CONTRACT_FUNCTIONS: usize = 2_usize.pow(FUNCTION_TREE_HEIGHT); +const MAX_CONTRACT_PRIVATE_FUNCTIONS: usize = 2_usize.pow(FUNCTION_TREE_HEIGHT); #[derive(Debug, Clone)] pub enum AztecMacroError { AztecDepNotFound, - ContractHasTooManyFunctions { span: Span }, + ContractHasTooManyPrivaeFunctions { span: Span }, ContractConstructorMissing { span: Span }, UnsupportedFunctionArgumentType { span: Span, typ: UnresolvedTypeData }, UnsupportedStorageType { span: Option, typ: UnresolvedTypeData }, @@ -84,8 +84,8 @@ impl From for MacroError { secondary_message: None, span: None, }, - AztecMacroError::ContractHasTooManyFunctions { span } => MacroError { - primary_message: format!("Contract can only have a maximum of {} functions", MAX_CONTRACT_FUNCTIONS), + AztecMacroError::ContractHasTooManyPrivaeFunctions { span } => MacroError { + primary_message: format!("Contract can only have a maximum of {} private functions", MAX_CONTRACT_PRIVATE_FUNCTIONS), secondary_message: None, span: Some(span), }, @@ -456,10 +456,22 @@ fn transform_module( if has_transformed_module { // We only want to run these checks if the macro processor has found the module to be an Aztec contract. - if module.functions.len() > MAX_CONTRACT_FUNCTIONS { + let private_functions_count = module + .functions + .iter() + .filter(|func| { + func.def + .attributes + .secondary + .iter() + .any(|attr| is_custom_attribute(attr, "aztec(private)")) + }) + .count(); + + if private_functions_count > MAX_CONTRACT_PRIVATE_FUNCTIONS { let crate_graph = &context.crate_graph[crate_id]; return Err(( - AztecMacroError::ContractHasTooManyFunctions { span: Span::default() }, + AztecMacroError::ContractHasTooManyPrivaeFunctions { span: Span::default() }, crate_graph.root_file_id, )); } From 85a8d6a0acaa7ef0fc485d6d52a17bdbd1953bec Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 27 Feb 2024 12:07:50 +0000 Subject: [PATCH 2/3] fix typo --- noir/aztec_macros/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/noir/aztec_macros/src/lib.rs b/noir/aztec_macros/src/lib.rs index 5333f4455d1..d08f1c81e2d 100644 --- a/noir/aztec_macros/src/lib.rs +++ b/noir/aztec_macros/src/lib.rs @@ -68,7 +68,7 @@ const MAX_CONTRACT_PRIVATE_FUNCTIONS: usize = 2_usize.pow(FUNCTION_TREE_HEIGHT); #[derive(Debug, Clone)] pub enum AztecMacroError { AztecDepNotFound, - ContractHasTooManyPrivaeFunctions { span: Span }, + ContractHasTooManyPrivateFunctions { span: Span }, ContractConstructorMissing { span: Span }, UnsupportedFunctionArgumentType { span: Span, typ: UnresolvedTypeData }, UnsupportedStorageType { span: Option, typ: UnresolvedTypeData }, @@ -84,7 +84,7 @@ impl From for MacroError { secondary_message: None, span: None, }, - AztecMacroError::ContractHasTooManyPrivaeFunctions { span } => MacroError { + AztecMacroError::ContractHasTooManyPrivateFunctions { span } => MacroError { primary_message: format!("Contract can only have a maximum of {} private functions", MAX_CONTRACT_PRIVATE_FUNCTIONS), secondary_message: None, span: Some(span), @@ -471,7 +471,7 @@ fn transform_module( if private_functions_count > MAX_CONTRACT_PRIVATE_FUNCTIONS { let crate_graph = &context.crate_graph[crate_id]; return Err(( - AztecMacroError::ContractHasTooManyPrivaeFunctions { span: Span::default() }, + AztecMacroError::ContractHasTooManyPrivateFunctions { span: Span::default() }, crate_graph.root_file_id, )); } From 6e87079655c430e35fadd5500b499f6079fedeea Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 27 Feb 2024 13:56:11 +0000 Subject: [PATCH 3/3] chore: remove added functions for test --- .../contracts/token_contract/src/main.nr | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index ca174b69277..7a20030245a 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -66,16 +66,6 @@ contract Token { } // docs:end:constructor - #[aztec(private)] - fn foo(decimals: u8) { - assert(decimals == 0); - } - - #[aztec(private)] - fn bar(decimals: u64) { - assert(decimals == 0); - } - // docs:start:set_admin #[aztec(public)] fn set_admin(new_admin: AztecAddress) {