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

Authority timelock #3

Merged
merged 5 commits into from
Nov 8, 2023
Merged

Authority timelock #3

merged 5 commits into from
Nov 8, 2023

Conversation

guibescos
Copy link
Contributor

@guibescos guibescos commented Nov 7, 2023

This program implements a timelock for upgrade authorities.
The current_authority transfers the authority to a PDA of the new_authority and the timestamp at which the transfer can happen. The PDA will only sign authority transfer to new_authority after the timestamp.

// Check that the timelock is no longer than 1 year
if Clock::get()?.unix_timestamp.saturating_add(ONE_YEAR) < timestamp {
return Err(ErrorCode::TimestampTooLate.into());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

smart

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

very nice

/// CHECK: Unchecked new authority, can be a native wallet or a PDA of another program
pub new_authority: AccountInfo<'info>,
#[account(seeds = [new_authority.key().as_ref(), timestamp.to_be_bytes().as_ref()], bump)]
pub escrow_authority: SystemAccount<'info>,
Copy link
Contributor

Choose a reason for hiding this comment

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

let me make sure i follow this correctly: escrow_authority holds one or more authorities on behalf of new_authority.key(), but all of those authorities can only be claimed after timestamp.

i.e., this logic works even if multiple programs are transferred to the same new_authority at the same timestamp

Copy link
Contributor Author

@guibescos guibescos Nov 8, 2023

Choose a reason for hiding this comment

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

Yes exactly, you send any number of authorities to the PDA seeded by new_authority and timestamp.
This PDA will only ever sign to send the authorities to new_authority after timestamp.

pub struct Commit<'info> {
pub current_authority: Signer<'info>,
/// CHECK: Unchecked new authority, can be a native wallet or a PDA of another program
pub new_authority: AccountInfo<'info>,
Copy link
Contributor

Choose a reason for hiding this comment

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

we have to be super careful about setting this key correctly right?

Copy link
Contributor

Choose a reason for hiding this comment

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

(i'm not sure if there's anything better we can do here, since it's not like we can sign as the governance authority anyway)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have a strategy

programs/program-authority-timelock/src/lib.rs Outdated Show resolved Hide resolved
@guibescos guibescos merged commit 9693677 into main Nov 8, 2023
1 check passed
@guibescos guibescos deleted the authority-timelock branch November 8, 2023 18:19
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.

2 participants