Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Oct 31, 2024
1 parent d0ecf1d commit 1d85fff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 14 additions & 2 deletions programs/protocol-contracts-solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pub mod gateway {
Ok(())
}

// whitelist new spl token
// in case signature is provided, check if tss is the signer, otherwise check if authority is pda.authority
// if succeeds, new whitelist entry account is created
pub fn whitelist_spl_mint(
ctx: Context<Whitelist>,
signature: [u8; 64],
Expand All @@ -98,9 +101,11 @@ pub mod gateway {
nonce: u64,
) -> Result<()> {
let pda = &mut ctx.accounts.pda;
let whitelist_candidate = &mut ctx.accounts.whitelist_candidate;

validate_signature_or_authority(
pda,
whitelist_candidate,
&ctx.accounts.authority,
signature,
recovery_id,
Expand All @@ -112,6 +117,9 @@ pub mod gateway {
Ok(())
}

// unwhitelist new spl token
// in case signature is provided, check if tss is the signer, otherwise check if authority is pda.authority
// if succeeds, whitelist entry account is deleted
pub fn unwhitelist_spl_mint(
ctx: Context<Unwhitelist>,
signature: [u8; 64],
Expand All @@ -120,9 +128,11 @@ pub mod gateway {
nonce: u64,
) -> Result<()> {
let pda = &mut ctx.accounts.pda;
let whitelist_candidate: &mut Account<'_, Mint> = &mut ctx.accounts.whitelist_candidate;

validate_signature_or_authority(
pda,
whitelist_candidate,
&ctx.accounts.authority,
signature,
recovery_id,
Expand Down Expand Up @@ -430,12 +440,13 @@ fn recover_eth_address(

fn validate_signature_or_authority(

Check warning on line 441 in programs/protocol-contracts-solana/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] programs/protocol-contracts-solana/src/lib.rs#L441

warning: this function has too many arguments (8/7) --> programs/protocol-contracts-solana/src/lib.rs:441:1 | 441 | / fn validate_signature_or_authority( 442 | | pda: &mut Account<Pda>, 443 | | whitelist_candidate: &mut Account<Mint>, 444 | | authority: &Signer, ... | 449 | | instruction_name: &str, 450 | | ) -> Result<()> { | |_______________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default
Raw output
programs/protocol-contracts-solana/src/lib.rs:441:1:w:warning: this function has too many arguments (8/7)
   --> programs/protocol-contracts-solana/src/lib.rs:441:1
    |
441 | / fn validate_signature_or_authority(
442 | |     pda: &mut Account<Pda>,
443 | |     whitelist_candidate: &mut Account<Mint>,
444 | |     authority: &Signer,
...   |
449 | |     instruction_name: &str,
450 | | ) -> Result<()> {
    | |_______________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
    = note: `#[warn(clippy::too_many_arguments)]` on by default


__END__
pda: &mut Account<Pda>,
whitelist_candidate: &mut Account<Mint>,
authority: &Signer,
signature: [u8; 64],
recovery_id: u8,
message_hash: [u8; 32],
nonce: u64,
purpose: &str,
instruction_name: &str,
) -> Result<()> {
// signature provided, recover and verify that tss is the signer
if signature != [0u8; 64] {
Expand All @@ -445,8 +456,9 @@ fn validate_signature_or_authority(
}

let mut concatenated_buffer = Vec::new();
concatenated_buffer.extend_from_slice(purpose.as_bytes());
concatenated_buffer.extend_from_slice(instruction_name.as_bytes());
concatenated_buffer.extend_from_slice(&pda.chain_id.to_be_bytes());
concatenated_buffer.extend_from_slice(&whitelist_candidate.key().to_bytes());
concatenated_buffer.extend_from_slice(&nonce.to_be_bytes());
require!(
message_hash == hash(&concatenated_buffer[..]).to_bytes(),
Expand Down
6 changes: 4 additions & 2 deletions tests/protocol-contracts-solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,14 @@ describe("some tests", () => {
await depositSplTokens(gatewayProgram, conn, wallet, mint, address);
});

it("unwhitelist SPL token using tss signature and deposit should fail", async () => {
it("unwhitelist SPL token using TSS signature and deposit should fail", async () => {
const pdaAccountData = await gatewayProgram.account.pda.fetch(pdaAccount);
const nonce = pdaAccountData.nonce;

const buffer = Buffer.concat([
Buffer.from("unwhitelist_spl_mint","utf-8"),
chain_id_bn.toArrayLike(Buffer, 'be', 8),
mint.publicKey.toBuffer(),
nonce.toArrayLike(Buffer, 'be', 8),
]);
const message_hash = keccak256(buffer);
Expand Down Expand Up @@ -465,13 +466,14 @@ describe("some tests", () => {
}
});

it("re-whitelist SPL token using tss signature and deposit should succeed", async () => {
it("re-whitelist SPL token using TSS signature and deposit should succeed", async () => {
const pdaAccountData = await gatewayProgram.account.pda.fetch(pdaAccount);
const nonce = pdaAccountData.nonce;

const buffer = Buffer.concat([
Buffer.from("whitelist_spl_mint","utf-8"),
chain_id_bn.toArrayLike(Buffer, 'be', 8),
mint.publicKey.toBuffer(),
nonce.toArrayLike(Buffer, 'be', 8),
]);
const message_hash = keccak256(buffer);
Expand Down

0 comments on commit 1d85fff

Please sign in to comment.