Skip to content

Commit aec7d1e

Browse files
committed
feat(pool_logic): add defensive check and improve comments
Add defensive assertion to prevent underflow in index_delta calculation and simplify comments for better readability. - Add assert check: next_index >= curr_index - Simplify verbose comments to concise explanations - Import error_config for assertion error handling
1 parent 3caeb81 commit aec7d1e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

aave-core/sources/aave-pool/pool_logic.move

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)