Skip to content

Commit 2c812fe

Browse files
committed
solana: Mark existing dylint warnings as false positives
Adds linting directives to ignore functions that have been reviewed for safety. Adds some missing function documentation
1 parent 39db4fe commit 2c812fe

File tree

7 files changed

+66
-0
lines changed

7 files changed

+66
-0
lines changed

solana/programs/example-native-token-transfers/src/instructions/admin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub struct TransferOwnership<'info> {
5252
bpf_loader_upgradeable_program: Program<'info, BpfLoaderUpgradeable>,
5353
}
5454

55+
#[allow(unknown_lints)]
56+
#[allow(missing_owner_check)]
5557
pub fn transfer_ownership(ctx: Context<TransferOwnership>) -> Result<()> {
5658
// Missing ownership check is OK here: new_owner is not expected to interact with this
5759
// instruction. Instead, they call [`claim_ownership`]. The whole intention of new_owner
@@ -67,6 +69,7 @@ pub fn transfer_ownership(ctx: Context<TransferOwnership>) -> Result<()> {
6769
bpf_loader_upgradeable::SetUpgradeAuthorityChecked {
6870
program_data: ctx.accounts.program_data.to_account_info(),
6971
current_authority: ctx.accounts.owner.to_account_info(),
72+
// Missing ownership check is OK here: upgrade_lock is enforced to be a PDA.
7073
new_authority: ctx.accounts.upgrade_lock.to_account_info(),
7174
},
7275
&[&[b"upgrade_lock", &[ctx.bumps.upgrade_lock]]],
@@ -107,6 +110,8 @@ pub struct ClaimOwnership<'info> {
107110
bpf_loader_upgradeable_program: Program<'info, BpfLoaderUpgradeable>,
108111
}
109112

113+
#[allow(unknown_lints)]
114+
#[allow(missing_owner_check)]
110115
pub fn claim_ownership(ctx: Context<ClaimOwnership>) -> Result<()> {
111116
ctx.accounts.config.pending_owner = None;
112117
ctx.accounts.config.owner = ctx.accounts.new_owner.key();
@@ -118,6 +123,7 @@ pub fn claim_ownership(ctx: Context<ClaimOwnership>) -> Result<()> {
118123
.to_account_info(),
119124
bpf_loader_upgradeable::SetUpgradeAuthorityChecked {
120125
program_data: ctx.accounts.program_data.to_account_info(),
126+
// Missing ownership check is OK here: upgrade_lock is enforced to be a PDA.
121127
current_authority: ctx.accounts.upgrade_lock.to_account_info(),
122128
new_authority: ctx.accounts.new_owner.to_account_info(),
123129
},

solana/programs/example-native-token-transfers/src/instructions/release_inbound.rs

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ pub struct ReleaseInboundMint<'info> {
6060
/// Setting this flag to `false` is useful when bundling this instruction
6161
/// together with [`crate::instructions::redeem`] in a transaction, so that the minting
6262
/// is attempted optimistically.
63+
/// SECURITY: Owner checks are disabled here. Ownership checks are enforced by implicit anchor constraints.
64+
/// SECURITY: Signer checks are disabled here. The signer is checked implicitly by [`ReleaseInbound`]
65+
/// which is wrapped by [`ReleaseInboundMint`].
66+
#[allow(unknown_lints)]
67+
#[allow(missing_owner_check)]
68+
#[allow(missing_signer_check)]
6369
pub fn release_inbound_mint(
6470
ctx: Context<ReleaseInboundMint>,
6571
args: ReleaseInboundArgs,
@@ -115,6 +121,12 @@ pub struct ReleaseInboundUnlock<'info> {
115121
/// Setting this flag to `false` is useful when bundling this instruction
116122
/// together with [`crate::instructions::redeem`], so that the unlocking
117123
/// is attempted optimistically.
124+
/// SECURITY: Owner checks are disabled here. Ownership checks are enforced by implicit anchor constraints.
125+
/// SECURITY: Signer checks are disabled here because anyone is permitted to send a release
126+
/// transaction
127+
#[allow(unknown_lints)]
128+
#[allow(missing_owner_check)]
129+
#[allow(missing_signer_check)]
118130
pub fn release_inbound_unlock(
119131
ctx: Context<ReleaseInboundUnlock>,
120132
args: ReleaseInboundArgs,

solana/programs/example-native-token-transfers/src/instructions/transfer.rs

+24
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ pub struct TransferBurn<'info> {
102102
}
103103

104104
// TODO: fees for relaying?
105+
/// Burns tokens and issues a corresponding notification to the outbox of the connected
106+
/// [`NttManagerPeer`].
107+
/// SECURITY: Owner checks are disabled here. Ownership checks are enforced by implicit
108+
/// anchor constraints in the `Transfer` account struct.
109+
/// transaction
110+
/// SECURITY: Signer check is disabled here. The signer is checked via the `Transfer` struct
111+
/// wrapped by`TransferBurn`.
112+
#[allow(unknown_lints)]
113+
#[allow(missing_owner_check)]
114+
#[allow(missing_signer_check)]
105115
pub fn transfer_burn(ctx: Context<TransferBurn>, args: TransferArgs) -> Result<()> {
106116
require_eq!(
107117
ctx.accounts.common.config.mode,
@@ -124,6 +134,8 @@ pub fn transfer_burn(ctx: Context<TransferBurn>, args: TransferArgs) -> Result<(
124134
accs.peer.token_decimals,
125135
);
126136

137+
// Missing ownership checks are OK here. These accounts are verified via
138+
// implicit constraints in `InterfaceAccount`, `TokenAccount` and `Mint` defined above.
127139
token_interface::burn(
128140
CpiContext::new_with_signer(
129141
accs.common.token_program.to_account_info(),
@@ -186,6 +198,16 @@ pub struct TransferLock<'info> {
186198

187199
// TODO: fees for relaying?
188200
// TODO: factor out common bits
201+
/// Locks tokens and issues a corresponding notification to the outbox of the connected
202+
/// [`NttManagerPeer`].
203+
/// SECURITY: Owner checks are disabled here. Ownership checks are enforced by implicit
204+
/// anchor constraints in the `Transfer` account struct.
205+
/// transaction
206+
/// SECURITY: Signer check is disabled here. The signer is checked via the `Transfer` struct
207+
/// wrapped by`TransferLock`
208+
#[allow(unknown_lints)]
209+
#[allow(missing_owner_check)]
210+
#[allow(missing_signer_check)]
189211
pub fn transfer_lock(ctx: Context<TransferLock>, args: TransferArgs) -> Result<()> {
190212
require_eq!(
191213
ctx.accounts.common.config.mode,
@@ -208,6 +230,8 @@ pub fn transfer_lock(ctx: Context<TransferLock>, args: TransferArgs) -> Result<(
208230
accs.peer.token_decimals,
209231
);
210232

233+
// Missing ownership checks are OK here. These accounts are verified via
234+
// implicit constraints in `InterfaceAccount`, `TokenAccount` and `Mint` defined above.
211235
token_interface::transfer_checked(
212236
CpiContext::new_with_signer(
213237
accs.common.token_program.to_account_info(),

solana/programs/example-native-token-transfers/src/transceivers/wormhole/accounts.rs

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ pub struct WormholeAccounts<'info> {
2828
pub rent: Sysvar<'info, Rent>,
2929
}
3030

31+
/// SECURITY: Owner checks are disabled. Each of [`WormholeAccounts::bridge`], [`WormholeAccounts::fee_collector`],
32+
/// and [`WormholeAccounts::sequence`] must be checked by the Wormhole core bridge.
33+
/// wrapped by`TransferBurn`.
34+
/// SECURITY: Signer checks are disabled. The only valid sender is the
35+
/// [`wormhole::PostMessage::emitter`], enforced by the [`CpiContext`] below.
36+
#[allow(unknown_lints)]
37+
#[allow(missing_owner_check)]
38+
#[allow(missing_signer_check)]
3139
pub fn post_message<'info, A: TypePrefixedPayload>(
3240
wormhole: &WormholeAccounts<'info>,
3341
payer: AccountInfo<'info>,
@@ -68,6 +76,10 @@ pub fn post_message<'info, A: TypePrefixedPayload>(
6876
Ok(())
6977
}
7078

79+
/// SECURITY: Owner and signer checks are disabled as this private function is used only by
80+
/// [`post_message`].
81+
#[allow(missing_owner_check)]
82+
#[allow(missing_signer_check)]
7183
fn pay_wormhole_fee<'info>(
7284
wormhole: &WormholeAccounts<'info>,
7385
payer: &AccountInfo<'info>,

solana/programs/example-native-token-transfers/src/transceivers/wormhole/instructions/broadcast_id.rs

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ pub struct BroadcastId<'info> {
3030
pub wormhole: WormholeAccounts<'info>,
3131
}
3232

33+
/// SECURITY: Owner checks are disabled. [`token_interface::Mint`] performs implicit ownership
34+
/// checks for token accounts. [`BroadcastId::emitter`] is enforced to be a PDA.
35+
#[allow(unknown_lints)]
36+
#[allow(missing_owner_check)]
3337
pub fn broadcast_id(ctx: Context<BroadcastId>) -> Result<()> {
3438
let accs = ctx.accounts;
3539
let message = WormholeTransceiverInfo {

solana/programs/example-native-token-transfers/src/transceivers/wormhole/instructions/broadcast_peer.rs

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ pub struct BroadcastPeerArgs {
3939
pub chain_id: u16,
4040
}
4141

42+
/// SECURITY: Owner checks are disabled. [`BroadcastPeer::emitter`] is enforced to be a PDA.
43+
#[allow(unknown_lints)]
44+
#[allow(missing_owner_check)]
4245
pub fn broadcast_peer(ctx: Context<BroadcastPeer>, args: BroadcastPeerArgs) -> Result<()> {
4346
let accs = ctx.accounts;
4447

solana/programs/example-native-token-transfers/src/transceivers/wormhole/instructions/release_outbound.rs

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ pub struct ReleaseOutboundArgs {
5454
pub revert_on_delay: bool,
5555
}
5656

57+
/// SECURITY: Owner checks are disabled. [`ReleaseOutbound::emitter`] is enforced to be a PDA.
58+
/// [`ReleaseOutbound::wormhole_message`] is verified by the Wormhole core bridge instead of this
59+
/// program.
60+
#[allow(unknown_lints)]
61+
#[allow(missing_owner_check)]
5762
pub fn release_outbound(ctx: Context<ReleaseOutbound>, args: ReleaseOutboundArgs) -> Result<()> {
5863
let accs = ctx.accounts;
5964
let released = accs.outbox_item.try_release(accs.transceiver.id)?;

0 commit comments

Comments
 (0)