From 5a2c5bd9fd235776a0eb2029f4019504f148f849 Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 10 Jul 2024 13:40:34 +0200 Subject: [PATCH] feat: module length verification --- .../contracts/isms/aggregation/aggregation.cairo | 2 ++ contracts/src/tests/isms/test_aggregation.cairo | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/contracts/src/contracts/isms/aggregation/aggregation.cairo b/contracts/src/contracts/isms/aggregation/aggregation.cairo index 6455cdc..7532bdc 100644 --- a/contracts/src/contracts/isms/aggregation/aggregation.cairo +++ b/contracts/src/contracts/isms/aggregation/aggregation.cairo @@ -46,11 +46,13 @@ pub mod aggregation { pub const THRESHOLD_NOT_SET: felt252 = 'Threshold not set'; pub const MODULES_ALREADY_STORED: felt252 = 'Modules already stored'; pub const NO_MODULES_PROVIDED: felt252 = 'No modules provided'; + pub const TOO_MANY_MODULES_PROVIDED: felt252 = 'Too many modules provided'; } #[constructor] fn constructor(ref self: ContractState, _owner: ContractAddress, _modules: Span) { self.ownable.initializer(_owner); + assert(_modules.len()<255, Errors::TOO_MANY_MODULES_PROVIDED); self.set_modules(_modules); } diff --git a/contracts/src/tests/isms/test_aggregation.cairo b/contracts/src/tests/isms/test_aggregation.cairo index ffb3033..fbe99fc 100644 --- a/contracts/src/tests/isms/test_aggregation.cairo +++ b/contracts/src/tests/isms/test_aggregation.cairo @@ -35,6 +35,22 @@ fn test_aggregation_set_threshold() { aggregation.set_threshold(threshold); } +#[test] +#[should_panic] +fn test_aggregation_initialize_with_too_many_modules(){ + let mut modules = array![]; + let mut cur_idx = 0; + loop{ + if (cur_idx == 256) { + break; + } + modules.append('module_1'.into()); + cur_idx +=1; + }; + setup_aggregation(modules.span()); +} + + #[test] #[should_panic(expected: ('Threshold not set',))] fn test_aggregation_verify_fails_if_treshold_not_set() {