Skip to content

Commit

Permalink
feat: Sync from aztec-packages (#4439)
Browse files Browse the repository at this point in the history
BEGIN_COMMIT_OVERRIDE
chore(aztec): Change function limit to private function limit
(AztecProtocol/aztec-packages#4785)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <tom@tomfren.ch>
Co-authored-by: Álvaro Rodríguez <sirasistant@gmail.com>
  • Loading branch information
3 people authored Feb 27, 2024
1 parent a25d5da commit a112b30
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e69b58660ff843350e1e098d8f1a84f4ce3d3c34
24 changes: 18 additions & 6 deletions aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
ContractHasTooManyPrivateFunctions { span: Span },
ContractConstructorMissing { span: Span },
UnsupportedFunctionArgumentType { span: Span, typ: UnresolvedTypeData },
UnsupportedStorageType { span: Option<Span>, typ: UnresolvedTypeData },
Expand All @@ -84,8 +84,8 @@ impl From<AztecMacroError> 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::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),
},
Expand Down Expand Up @@ -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::ContractHasTooManyPrivateFunctions { span: Span::default() },
crate_graph.root_file_id,
));
}
Expand Down
2 changes: 0 additions & 2 deletions bootstrap_cache.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -eu

[ -z "${NO_CACHE:-}" ] && type docker &> /dev/null && [ -f ~/.aws/credentials ] || exit 1

cd "$(dirname "$0")"
source ../build-system/scripts/setup_env '' '' mainframe_$USER > /dev/null

Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/collections/map.nr
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl<K, V, N, B, H> HashMap<K, V, N, B> {
// n * MAX_LOAD_FACTOR_DEN0MINATOR >= m * MAX_LOAD_FACTOR_NUMERATOR
fn assert_load_factor(self) {
let lhs = self._len * MAX_LOAD_FACTOR_DEN0MINATOR;
let rhs = self._table.len() as u64 * MAX_LOAD_FACTOR_NUMERATOR;
let rhs = self._table.len() * MAX_LOAD_FACTOR_NUMERATOR;
let exceeded = lhs >= rhs;
assert(!exceeded, "Load factor is exceeded, consider increasing the capacity.");
}
Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/sha256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn digest<N>(msg: [u8; N]) -> [u8; 32] {
msg_block[i as Field] = 0;
i = i + 1;
} else if i < 64 {
let mut len = 8 * msg.len() as u64;
let mut len = 8 * msg.len();
for j in 0..8 {
msg_block[63 - j] = len as u8;
len >>= 8;
Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/sha512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn digest<N>(msg: [u8; N]) -> [u8; 64] {
msg_block[i as Field] = 0;
i += 1;
} else if i < 128 {
let mut len = 8 * msg.len() as u64; // u128 unsupported
let mut len = 8 * msg.len();
for j in 0..16 {
msg_block[127 - j] = len as u8;
len >>= 8;
Expand Down
6 changes: 3 additions & 3 deletions test_programs/execution_success/regression/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global NIBBLE_LENGTH: Field = 16;
global NIBBLE_LENGTH: u64 = 16;

struct U4 {
inner: u8,
Expand All @@ -21,8 +21,8 @@ impl Eq for U4 {
}

fn compact_decode<N>(input: [u8; N], length: Field) -> ([U4; NIBBLE_LENGTH], Field) {
assert(2 * input.len() as u64 <= NIBBLE_LENGTH as u64);
assert(length as u64 <= input.len() as u64);
assert(2 * input.len() <= NIBBLE_LENGTH);
assert(length as u64 <= input.len());

let mut nibble = [U4::zero(); NIBBLE_LENGTH];

Expand Down

0 comments on commit a112b30

Please sign in to comment.