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

refactor: enhance PDA validation #40

Merged
merged 6 commits into from
Oct 8, 2024
Merged

Conversation

brewmaster012
Copy link
Contributor

@brewmaster012 brewmaster012 commented Oct 7, 2024

Add seeds and bump to all references of PDA accounts.

This strengthens validation.

@codecov-commenter
Copy link

codecov-commenter commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 8.30%. Comparing base (b695c2c) to head (4f36439).

Additional details and impacted files
@@          Coverage Diff          @@
##            main     #40   +/-   ##
=====================================
  Coverage   8.30%   8.30%           
=====================================
  Files          1       1           
  Lines        253     253           
=====================================
  Hits          21      21           
  Misses       232     232           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brewmaster012 brewmaster012 marked this pull request as ready for review October 7, 2024 21:08
Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

looks good, couple of nits

programs/protocol-contracts-solana/src/lib.rs Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@@ -381,7 +382,6 @@ pub struct WithdrawSPLToken<'info> {
#[account(mut)]
pub pda_ata: Account<'info, TokenAccount>, // associated token address of PDA
Copy link
Contributor

Choose a reason for hiding this comment

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

just to double check if we can add some of these spl token constraints on these related accounts:
https://www.quicknode.com/guides/solana-development/anchor/how-to-use-constraints-in-anchor#spl-token-constraints

Copy link
Contributor Author

Choose a reason for hiding this comment

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

b0d3184

added a few constraints. This seems to be redundant to the checks inside the withdrawSPLToken function:
as a result, there is no way to trigger the error SPLAtaAndMintAddressMismatch in the test.
For now let's leave both validation there as they do not harm.

let pda_ata = get_associated_token_address(&pda.key(), &ctx.accounts.mint_account.key());
        require!(
            pda_ata == ctx.accounts.pda_ata.to_account_info().key(),
            Errors::SPLAtaAndMintAddressMismatch
        );

Copy link
Contributor

Choose a reason for hiding this comment

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

yes i suspected we can achieve the same validation with anchor after checking link above

i am ok with leaving both validations, but also would be ok to remove ours if it cant be triggered anymore to keep programs simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will keep both for now.

@@ -422,6 +420,38 @@ describe("some tests", () => {
}
});

it("create an account owned by the gateway program", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nits: maybe lets remove console logs and comment if we need this test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test case is removed in the subsequent PR #42

@lumtis lumtis changed the title Enhance PDA validation refactor: enhance PDA validation Oct 8, 2024
@brewmaster012 brewmaster012 merged commit 74c9d81 into main Oct 8, 2024
14 checks passed
@brewmaster012 brewmaster012 deleted the enhance-pda-validation branch October 8, 2024 16:06
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.

5 participants