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

solana: allow pools to specify writable accounts #419

Merged
merged 12 commits into from
Jan 9, 2025

Conversation

aalu1418
Copy link
Collaborator

@aalu1418 aalu1418 commented Jan 7, 2025

  • store writable accounts in token admin registry
  • use writable accounts to build transaction accounts
  • validate writable token pool accounts against registry
  • validate accounts in lookup table during SetPool
  • test cases
    • test cases for incorrect write permissions for pool accounts
    • test cases for incorrect pool accounts for SetPool

@aalu1418 aalu1418 marked this pull request as ready for review January 9, 2025 00:00
@aalu1418 aalu1418 requested a review from a team as a code owner January 9, 2025 00:00
expected_is_writable.append(&mut remaining_is_writable);
for (i, is_writable) in expected_is_writable.iter().enumerate() {
require!(
token_admin_registry_account.is_writable(i as u8) == *is_writable,
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 I understand this check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'll add some more comments - but it basically checks that the provided token pool account is (or is not) writable based on what's configured in the token admin registry (based on index)

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: if you use require_eq! instead of require!, the logs will have more info in case the check fails.


// TODO: Validate here that the lookup table has everything
// set writable indexes
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this doing? Any of the accounts passed can be writable? Like the regular accounts and the additionals?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct, since these accounts are token pool specific, we need a way to know how to build the transaction offchain

this way provides an onchain record that admins can use to set which token pool accounts are writable

…v1/token_admin_registry.rs

Co-authored-by: Jonghyeon Park <[email protected]>
@aalu1418 aalu1418 force-pushed the solana/specify-writable-pool-accounts branch from 3a04b12 to 4eba5bd Compare January 9, 2025 16:56

// TODO: Validate here that the lookup table has everything
// validate lookup table contains minimum required accounts if not zero address
if new_pool != Pubkey::zeroed() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: If we use Pubkey::default() it returns the same thing as Pubkey::zeroed() and can make you remove the dependency on bytemuck::Zeroable here

Suggested change
if new_pool != Pubkey::zeroed() {
if new_pool != Pubkey::default() {

AddressLookupTable::deserialize(lookup_table_data)
.map_err(|_| CcipRouterError::InvalidInputsLookupTableAccounts)?;
require!(
lookup_table_account.addresses.len() >= 9,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance you can link that 9 to a constant? It seems like that value is tied to logic in this file and in pools.rs, so it'd be nice if the compiler can check both places stay consistent in case we ever change one of them.

E.g., define a constant, use it here in the check, and use it in an explicit slice type in this line
Said constant could be taken outside of the versioned logic folders if we consider that part of our interface with TokenPools.

Also, if you use require_gte! instead of require!, the logs will print the actual length in case of error, which can help when troubleshooting failed tests for example

expected_is_writable.append(&mut remaining_is_writable);
for (i, is_writable) in expected_is_writable.iter().enumerate() {
require!(
token_admin_registry_account.is_writable(i as u8) == *is_writable,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: if you use require_eq! instead of require!, the logs will have more info in case the check fails.

Comment on lines +21 to 45
impl TokenAdminRegistry {
// set writable inserts bits from left to right
// index 0 is left-most bit
pub fn set_writable(&mut self, index: u8) {
match index < 128 {
true => {
self.writable_indexes[0] |= 1 << (127 - index);
}
false => {
self.writable_indexes[1] |= 1 << (255 - index);
}
}
}

pub fn is_writable(&self, index: u8) -> bool {
match index < 128 {
true => self.writable_indexes[0] & 1 << (127 - index) != 0,
false => self.writable_indexes[1] & 1 << (255 - index) != 0,
}
}

pub fn reset_writable(&mut self) {
self.writable_indexes = [0, 0];
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you whether to leave this here for now or not, but in general I'd rather have functions defined in the versioned logic modules instead of here.

Copy link
Contributor

@toblich toblich left a comment

Choose a reason for hiding this comment

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

LGTM, all my previous comments are optional nitpicks, no need to delay the PR due to them if you'd rather just merge as-is

Copy link

github-actions bot commented Jan 9, 2025

Metric solana/specify-writable-pool-accounts main
Coverage 76.5% 76.4%

@aalu1418
Copy link
Collaborator Author

aalu1418 commented Jan 9, 2025

LGTM, all my previous comments are optional nitpicks, no need to delay the PR due to them if you'd rather just merge as-is

i will address these in a follow up PR! they seem pretty straight forward and I don't want any of my changes to block any refactors

@aalu1418 aalu1418 merged commit 6a38ffc into main Jan 9, 2025
17 checks passed
@aalu1418 aalu1418 deleted the solana/specify-writable-pool-accounts branch January 9, 2025 21:48
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