diff --git a/cross-chain/solana/programs/tbtc/src/error.rs b/cross-chain/solana/programs/tbtc/src/error.rs index 3cf0253fd..7db624a97 100644 --- a/cross-chain/solana/programs/tbtc/src/error.rs +++ b/cross-chain/solana/programs/tbtc/src/error.rs @@ -2,36 +2,36 @@ use anchor_lang::prelude::error_code; #[error_code] pub enum TbtcError { - #[msg("This address is already a minter.")] + #[msg("This address is already a minter")] MinterAlreadyExists = 0x10, - #[msg("This address is not a minter.")] + #[msg("This address is not a minter")] MinterNonexistent = 0x12, - #[msg("This address is already a guardian.")] + #[msg("This address is already a guardian")] GuardianAlreadyExists = 0x20, - #[msg("This address is not a guardian.")] + #[msg("This address is not a guardian")] GuardianNonexistent = 0x22, - #[msg("Caller is not a guardian.")] + #[msg("Caller is not a guardian")] SignerNotGuardian = 0x30, - #[msg("Caller is not a minter.")] + #[msg("Caller is not a minter")] SignerNotMinter = 0x32, - #[msg("Program is paused.")] + #[msg("Program is paused")] IsPaused = 0x40, - #[msg("Program is not paused.")] + #[msg("Program is not paused")] IsNotPaused = 0x42, - #[msg("Not valid authority to perform this action.")] + #[msg("Not valid authority to perform this action")] IsNotAuthority = 0x50, - #[msg("Not valid pending authority to take authority.")] + #[msg("Not valid pending authority to take authority")] IsNotPendingAuthority = 0x52, - #[msg("No pending authority.")] + #[msg("No pending authority")] NoPendingAuthorityChange = 0x54, } diff --git a/cross-chain/solana/programs/wormhole-gateway/src/error.rs b/cross-chain/solana/programs/wormhole-gateway/src/error.rs index a607e79b8..972c548f8 100644 --- a/cross-chain/solana/programs/wormhole-gateway/src/error.rs +++ b/cross-chain/solana/programs/wormhole-gateway/src/error.rs @@ -2,33 +2,36 @@ use anchor_lang::prelude::error_code; #[error_code] pub enum WormholeGatewayError { - #[msg("Cannot mint more than the minting limit.")] + #[msg("Cannot mint more than the minting limit")] MintingLimitExceeded = 0x10, - #[msg("Only custodian authority is permitted for this action.")] + #[msg("Only custodian authority is permitted for this action")] IsNotAuthority = 0x20, - #[msg("0x0 recipient not allowed.")] + #[msg("0x0 recipient not allowed")] ZeroRecipient = 0x30, - #[msg("Not enough wormhole tBTC in the gateway to bridge.")] + #[msg("Not enough wormhole tBTC in the gateway to bridge")] NotEnoughWrappedTbtc = 0x40, - #[msg("Amount must not be 0.")] + #[msg("Amount must not be 0")] ZeroAmount = 0x50, - #[msg("Token Bridge transfer already redeemed.")] + #[msg("Token Bridge transfer already redeemed")] TransferAlreadyRedeemed = 0x70, - #[msg("Token chain and address do not match Ethereum's tBTC.")] + #[msg("Token chain and address do not match Ethereum's tBTC")] InvalidEthereumTbtc = 0x80, - #[msg("No tBTC transferred.")] + #[msg("No tBTC transferred")] NoTbtcTransferred = 0x90, - #[msg("0x0 receiver not allowed.")] + #[msg("0x0 receiver not allowed")] RecipientZeroAddress = 0xa0, - #[msg("Not enough minted by the gateway to satisfy sending tBTC.")] + #[msg("Not enough minted by the gateway to satisfy sending tBTC")] MintedAmountUnderflow = 0xb0, + + #[msg("Minted amount after deposit exceeds u64")] + MintedAmountOverflow = 0xb2, } diff --git a/cross-chain/solana/programs/wormhole-gateway/src/processor/deposit_wormhole_tbtc.rs b/cross-chain/solana/programs/wormhole-gateway/src/processor/deposit_wormhole_tbtc.rs index 92a498595..f8888ef2a 100644 --- a/cross-chain/solana/programs/wormhole-gateway/src/processor/deposit_wormhole_tbtc.rs +++ b/cross-chain/solana/programs/wormhole-gateway/src/processor/deposit_wormhole_tbtc.rs @@ -59,9 +59,15 @@ pub struct DepositWormholeTbtc<'info> { impl<'info> DepositWormholeTbtc<'info> { fn constraints(ctx: &Context, amount: u64) -> Result<()> { + let updated_minted_amount = ctx + .accounts + .custodian + .minted_amount + .checked_add(amount) + .ok_or(WormholeGatewayError::MintedAmountOverflow)?; require_gte!( ctx.accounts.custodian.minting_limit, - ctx.accounts.custodian.minted_amount.saturating_add(amount), + updated_minted_amount, WormholeGatewayError::MintingLimitExceeded ); @@ -85,8 +91,7 @@ pub fn deposit_wormhole_tbtc(ctx: Context, amount: u64) -> )?; // Account for minted amount. - ctx.accounts.custodian.minted_amount = - ctx.accounts.custodian.minted_amount.saturating_add(amount); + ctx.accounts.custodian.minted_amount += amount; let custodian = &ctx.accounts.custodian;