nautilus-project/nautilus

Add authority checks for `Record<T>` PDAs

buffalojoec opened this issue · 0 comments

When you annotate a struct using #[derive(nautilus::Table)] you can provide an attribute for any field to mark it as an authority using #[authority].

This means that the public key provided in this field must be a signer on any instruction that attempts to modify this record's data.

The code is uncompleted to actually add these checks, and you can find the skeleton code here:
https://github.com/nautilus-project/nautilus/blob/main/solana/syn/src/object/data.rs#L144

To close this issue, we need to:

  • Enforce any field annotated with #[authority] to be of type Pubkey
  • Complete the count_authorities(..) function to return the total count of authorities protecting that record
  • Complete the check_authorities(..) function to validate that each specified authority for this record is marked as a signer

For context, the check_authorities(&self, accounts: Vec<AccountInfo>) function takes a vector of AccountInfo.
This function's parameters can be modified.
You'll find the code linked below where the actual AccountInfo objects are read in from the provided accounts, and can choose to pipe them into this function in the most efficient way possible.
https://github.com/nautilus-project/nautilus/blob/main/solana/syn/src/entry/entry_variant.rs#L74

Make use of cargo expand to see where the accounts are loaded and how they are used to initialize the objects declared in the user's function signature.