Skip to content

Commit 62ce7d9

Browse files
authored
feat(svm): disallow deposits with output token set to 0x0 (#1043)
Signed-off-by: Reinis Martinsons <[email protected]>
1 parent 919bfd3 commit 62ce7d9

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

programs/svm-spoke/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub enum CommonError {
3333
InsufficientSpokePoolBalanceToExecuteLeaf,
3434
#[msg("Invalid exclusive relayer!")]
3535
InvalidExclusiveRelayer,
36+
#[msg("Invalid output token!")]
37+
InvalidOutputToken,
3638
}
3739

3840
// SVM specific errors.

programs/svm-spoke/src/instructions/deposit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ pub fn _deposit(
9595
let state = &mut ctx.accounts.state;
9696
let current_time = get_current_time(state)?;
9797

98+
if output_token == Pubkey::default() {
99+
return err!(CommonError::InvalidOutputToken);
100+
}
101+
98102
if current_time.checked_sub(quote_timestamp).unwrap_or(u32::MAX) > state.deposit_quote_time_buffer {
99103
return err!(CommonError::InvalidQuoteTimestamp);
100104
}

test/svm/SvmSpoke.Deposit.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,17 @@ describe("svm_spoke.deposit", () => {
774774
assertSE(vaultAccount.amount, depositData.inputAmount, "Vault balance should equal the deposited amount");
775775
});
776776

777+
it("Output token cannot be zero address", async () => {
778+
const invalidDepositData = { ...depositData, outputToken: new PublicKey("11111111111111111111111111111111") };
779+
780+
try {
781+
await approvedDeposit(invalidDepositData);
782+
assert.fail("Should not be able to process deposit with zero output token address");
783+
} catch (err: any) {
784+
assert.include(err.toString(), "Error Code: InvalidOutputToken", "Expected InvalidOutputToken error");
785+
}
786+
});
787+
777788
describe("codama client and solana kit", () => {
778789
it("Deposit with with solana kit and codama client", async () => {
779790
// typescript is not happy with the depositData object

0 commit comments

Comments
 (0)