@@ -9,6 +9,7 @@ module aave_pool::pool_logic {
99
1010 use aave_config::reserve_config;
1111 use aave_config::reserve_config::ReserveConfigurationMap ;
12+ use aave_config::error_config;
1213 use aave_math::math_utils;
1314 use aave_math::wad_ray_math;
1415 use aave_pool::default_reserve_interest_rate_strategy;
@@ -418,12 +419,16 @@ module aave_pool::pool_logic {
418419 ) {
419420 if (reserve_cache.reserve_factor == 0 ) { return };
420421
421- // Calculate the index delta (difference between next and current borrow index)
422- // Safety: No underflow risk. The next_variable_borrow_index is calculated in update_indexes()
423- // as: next_index = ray_mul(cumulated_interest, curr_index), where cumulated_interest is
424- // computed by calculate_compounded_interest_now() which always returns >= ray() (1.0).
425- // Therefore: next_index >= ray_mul(ray(), curr_index) >= curr_index, ensuring index_delta >= 0.
426- // If curr_scaled_variable_debt == 0, next_index remains equal to curr_index (from cache initialization).
422+ // Defensive check: ensure next_index >= curr_index to prevent underflow
423+ // This is guaranteed by interest accumulation (next_index always grows or stays equal)
424+ assert !(
425+ reserve_cache.next_variable_borrow_index
426+ >= reserve_cache.curr_variable_borrow_index,
427+ error_config::get_eoverflow ()
428+ );
429+
430+ // Calculate index delta: the difference between next and current borrow index
431+ // This represents the interest accrued since the last update
427432 let index_delta =
428433 reserve_cache.next_variable_borrow_index
429434 - reserve_cache.curr_variable_borrow_index;
0 commit comments