hats-finance / Tokemak-0x4a2d708ea6b0c04186ecb774cfad1e50fb5efc0b

0 stars 0 forks source link

Event is not emitted #1

Open hats-bug-reporter[bot] opened 5 months ago

hats-bug-reporter[bot] commented 5 months ago

Github username: @https://github.com/Pavel2202 Twitter username: https://twitter.com/timenov_pavel Submission hash (on-chain): 0x6996a376bdfb967f743bdc367f39bf023d8add97faf700dfeb46c17082431f1a Severity: low

Description: Description\ In NavTracking::insert there is a left TODO. It states that an ecent should be emitted. However that is not true.

Attachments

  1. Proof of Concept (PoC) File https://github.com/Tokemak/v2-core-hats/blob/74b397ce988a418a1bd02a45716cfc964922be26/src/strategy/NavTracking.sol#L35
    function insert(State storage self, uint256 navPerShare, uint40 timestamp) internal {
        if (timestamp < self.lastFinalizedTimestamp) revert InvalidNavTimestamp(self.lastFinalizedTimestamp, timestamp);

        // if it's been a day since the last finalized value, then finalize the current value
        // otherwise continue to overwrite the currentIndex
        if (timestamp - self.lastFinalizedTimestamp >= 1 days) {
            if (self.lastFinalizedTimestamp > 0) {
                self.currentIndex = (self.currentIndex + 1) % MAX_NAV_TRACKING;
            }
            self.lastFinalizedTimestamp = timestamp;
        }

        self.history[self.currentIndex] = navPerShare;
        if (self.len < MAX_NAV_TRACKING) {
            self.len += 1;
        }

        @audit emit event
        // TODO: emit an event -- allow us to see if there are frequently gaps in reporting
    }
  1. Revised Code File (Optional)

Create an event and emit it at the end of the function.

    event Inserted(State state, uint256 navPerShare, uint40 timestamp);
    function insert(State storage self, uint256 navPerShare, uint40 timestamp) internal {
        if (timestamp < self.lastFinalizedTimestamp) revert InvalidNavTimestamp(self.lastFinalizedTimestamp, timestamp);

        // if it's been a day since the last finalized value, then finalize the current value
        // otherwise continue to overwrite the currentIndex
        if (timestamp - self.lastFinalizedTimestamp >= 1 days) {
            if (self.lastFinalizedTimestamp > 0) {
                self.currentIndex = (self.currentIndex + 1) % MAX_NAV_TRACKING;
            }
            self.lastFinalizedTimestamp = timestamp;
        }

        self.history[self.currentIndex] = navPerShare;
        if (self.len < MAX_NAV_TRACKING) {
            self.len += 1;
        }

        emit Inserted(self, navPerShare, timestamp);
    }