Elastic-Finance-DAO / eefi_contracts

0 stars 0 forks source link

[DLL-02M] Insecure Subtraction of Timestamps #74

Closed stalker474 closed 4 months ago

stalker474 commented 5 months ago

DLL-02M: Insecure Subtraction of Timestamps

Type Severity Location
Mathematical Operations DepositsLinkedList.sol:L63

Description:

The DepositsLinkedList::sumExpiredDeposits function will perform a subtraction insecurely between the current timestamp and the timestamp the deposit was performed in.

Impact:

The referenced subtraction should never underflow per the integration of DepositsLinkedList::insertEnd by ElasticVault::makeDeposit, however, we still advise the operation to be safely performed as an assertion-type security check.

Example:

function sumExpiredDeposits(List storage list, uint256 lock_duration) internal view returns (uint256 sum) {
    uint current = list.head;
    sum = 0;

    while (current != NULL) {
        if (lock_duration == 0 || ((block.timestamp - list.nodes[current].deposit.timestamp) > lock_duration)) {
            sum = sum.add(list.nodes[current].deposit.amount);
        }
        current = list.nodes[current].next;
    }

    return sum;
}

Recommendation:

We advise the referenced operation to be performed safely as a security precaution, preventing potential timestamp inconsistencies from resulting in an overflow.