-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lite refresh reserve #59
Conversation
clock: &Clock, | ||
) -> ProgramResult { | ||
let mut reserve = Reserve::unpack(&reserve_info.data.borrow())?; | ||
if reserve_info.owner != program_id { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also check that the reserve belongs to the same lending market?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess probably doesn't need since the original refresh_reserve also doesn't. That one instead checks that Pyth and Switchboard oracles match, which I guess isn't needed here since it doesn't actually use the feeds.
@@ -1046,6 +1061,11 @@ fn process_deposit_reserve_liquidity_and_obligation_collateral( | |||
clock, | |||
token_program_id, | |||
)?; | |||
// mark the reserve as stale to make sure no weird bugs happen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which weird bugs does this prevent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can think of one, bad liquidations using a very old price but appears to be up-to-date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since refresh_reserve_lite doesn't update the actual price, an attacker could exploit the stale price on a refreshed reserve
if we mark it as stale, this is mitigated
basically, an attacker can't do anything with the reserve until the refresh it the legit way
@@ -419,6 +419,26 @@ fn _refresh_reserve<'a>( | |||
Ok(()) | |||
} | |||
|
|||
/// Lite version of refresh_reserve that should be used when the oracle price doesn't need to be updated | |||
/// BE CAREFUL WHEN USING THIS | |||
fn _refresh_reserve_lite<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an internal function, which is good. If it were publicly callable could result in some weird stuff (e.g. attacker might be able to use a really stale price to liquidate someone since this marks the reserve as up to date).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah 100%
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By internal I mean it's not invokable since there's no process_refresh_reserve_lite
matcher in process_instruction
.
switchboard_feed_info, | ||
clock, | ||
)?; | ||
_refresh_reserve_lite(program_id, reserve_info, clock)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One side effect I can think of is the allowedBorrowValue
on the Obligation would be slightly off. Are we still reading this to display borrow power on the frontend? @0xodia
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, until the reserve is refreshed the legit way i believe bc the value of the obligation isn't updated with a new price
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allowed borrow value would still be correct when actually borrowing because that requires a full reserve refresh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is still heavily used in FE as the borrow limit. The use is only visual though so not the worse thing if it's slightly off from a stale price (if i'm understanding this PR correctly)
remove the need to refresh reserves/read oracle data when depositing liquidity/collateral