hats-finance / Kintsu-0x7d70f9442af3a9a0a734fa6a1b4857f25518e9d2

Smart contracts for Kintsu
Other
0 stars 0 forks source link

Wrong Value in Compound Emit Event #56

Open hats-bug-reporter[bot] opened 1 month ago

hats-bug-reporter[bot] commented 1 month ago

Github username: @0xmahdirostami Twitter username: 0xmahdirostami Submission hash (on-chain): 0xa7b802180377584a8120bb8c77be2c40527d175d5e5cc4f57a2bbeb49806028a Severity: low

Description: Description The vault::compound function emits an event with an incorrect value for virtual shares. The current implementation directly uses self.data.total_shares_virtual instead of calculating the virtual shares at the current time.

Impact Incorrect event data can mislead users or systems relying on event logs for accurate information regarding virtual shares.

Revised Code File (Optional) Calculate the virtual shares at the current time before emitting the event.

Revised Code

+            let now = Self::env().block_timestamp();
+            let virtual_shares = self.data.get_virtual_shares_at_time(now);

             Self::emit_event(
                 Self::env(),
                 Event::Compounded(Compounded {
                     caller,
                     azero: compounded,
                     incentive,
-                    virtual_shares: self.data.total_shares_virtual,
+                    virtual_shares: virtual_shares,
                 }),
             );

Explanation

  1. Calculate Virtual Shares:

    • Before emitting the event, we calculate the virtual shares at the current timestamp using self.data.get_virtual_shares_at_time(now).
  2. Emit Correct Event Data:

    • Use the calculated virtual_shares in the event data to ensure the emitted event contains the correct value for virtual shares.

This change ensures that the Compounded event accurately reflects the state of virtual shares at the time of compounding.

0xmahdirostami commented 1 month ago

More notes: we have this implementation in emitting events in stake, send_batch_unlock_request functions as well. However, in those functions self.data.total_shares_virtual is updated before emitting, but in the compound function, not updated and emits an old balance.

bmino commented 3 weeks ago

Addressed in kintsu-contracts@409154