Skip to content

Commit 518dceb

Browse files
committed
solana: Add check for no registered transceivers
Add guard on transfer instructions to prevent a transfer from being processed when no transceivers are registered. This is done by checking the `next_transceiver_id` field in the Config. This field auto-increments when a transceiver is added. If this value is 0, then the program is in a state where no transceivers have been registered.
1 parent 82c8308 commit 518dceb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

solana/programs/example-native-token-transfers/src/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ pub enum NTTError {
3737
DisabledTransceiver,
3838
#[msg("InvalidDeployer")]
3939
InvalidDeployer,
40+
#[msg("NoRegisteredTransceivers")]
41+
NoRegisteredTransceivers,
4042
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ pub fn transfer_burn(ctx: Context<TransferBurn>, args: TransferArgs) -> Result<(
120120
);
121121

122122
let accs = ctx.accounts;
123+
124+
// TODO If functionality is added to disable transceivers, this check should be modified to
125+
// ensure that, if all transceivers have been disabled, that an error is returned. Otherwise it
126+
// may be possible to permanently lose funds.
127+
// No transceivers have been registered yet
128+
if accs.common.config.next_transceiver_id == 0 {
129+
return Err(NTTError::NoRegisteredTransceivers.into());
130+
}
131+
123132
let TransferArgs {
124133
mut amount,
125134
recipient_chain,
@@ -213,6 +222,15 @@ pub fn transfer_lock(ctx: Context<TransferLock>, args: TransferArgs) -> Result<(
213222
);
214223

215224
let accs = ctx.accounts;
225+
226+
// TODO If functionality is added to disable transceivers, this check should be modified to
227+
// ensure that, if all transceivers have been disabled, that an error is returned. Otherwise it
228+
// may be possible to permanently lose funds.
229+
// No transceivers have been registered yet
230+
if accs.common.config.next_transceiver_id == 0 {
231+
return Err(NTTError::NoRegisteredTransceivers.into());
232+
}
233+
216234
let TransferArgs {
217235
mut amount,
218236
recipient_chain,

0 commit comments

Comments
 (0)