Skip to content
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

Merged
merged 6 commits into from
Jan 23, 2022
Merged

Lite refresh reserve #59

merged 6 commits into from
Jan 23, 2022

Conversation

RadiantAeon
Copy link

remove the need to refresh reserves/read oracle data when depositing liquidity/collateral

clock: &Clock,
) -> ProgramResult {
let mut reserve = Reserve::unpack(&reserve_info.data.borrow())?;
if reserve_info.owner != program_id {
Copy link
Member

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?

Copy link
Member

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
Copy link
Member

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?

Copy link
Member

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.

Copy link
Author

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>(
Copy link
Member

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).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah 100%

Copy link
Member

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)?;
Copy link
Member

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

Copy link
Author

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

Copy link
Author

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

Copy link

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)

@nope-finance nope-finance changed the base branch from mainnet to upcoming January 23, 2022 03:13
@nope-finance nope-finance merged commit 8a92aab into upcoming Jan 23, 2022
@nope-finance nope-finance deleted the lite-refresh-reserve branch January 23, 2022 14:07
@nope-finance nope-finance restored the lite-refresh-reserve branch January 23, 2022 14:09
@0xripleys 0xripleys deleted the lite-refresh-reserve branch January 25, 2023 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants