Skip to content

Commit

Permalink
Add validation preventing caller PDA to be garbage-collected (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
toblich authored Dec 19, 2024
1 parent bca6b9d commit e7d9aa1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ pub fn wrap_native_sol<'info>(
amount: u64,
signer_bump: u8,
) -> Result<()> {
require!(
// guarantee that if caller is a PDA it won't get garbage-collected
*from.owner == System::id() || from.get_lamports() > amount,
CcipRouterError::InsufficientLamports
);

invoke_signed(
&system_instruction::transfer(&from.key(), &to.key(), amount),
&[from.to_account_info(), to.to_account_info()],
Expand Down
2 changes: 2 additions & 0 deletions chains/solana/contracts/programs/ccip-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,8 @@ pub enum CcipRouterError {
InvalidTokenPrice,
#[msg("Stale gas price")]
StaleGasPrice,
#[msg("Insufficient lamports")]
InsufficientLamports,
}

// TODO: Refactor this to use the same structure as messages: execution_report.validate(..)
Expand Down
3 changes: 3 additions & 0 deletions chains/solana/contracts/target/idl/ccip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,9 @@
},
{
"name": "StaleGasPrice"
},
{
"name": "InsufficientLamports"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion chains/solana/contracts/tests/ccip/ccip_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2785,7 +2785,7 @@ func TestCCIPRouter(t *testing.T) {
}
})

t.Run("hen sending a Valid CCIP Message but the user does not have enough funds of the fee token, it fails", func(t *testing.T) {
t.Run("When sending a Valid CCIP Message but the user does not have enough funds of the fee token, it fails", func(t *testing.T) {
message := ccip_router.Solana2AnyMessage{
FeeToken: token2022.mint,
Receiver: validReceiverAddress[:],
Expand Down
3 changes: 3 additions & 0 deletions chains/solana/gobindings/ccip_router/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7d9aa1

Please sign in to comment.