Skip to content

Commit

Permalink
solana: add checked math; fix error msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-pickle committed Aug 3, 2023
1 parent 753c7ea commit c5d0770
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
22 changes: 11 additions & 11 deletions cross-chain/solana/programs/tbtc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
23 changes: 13 additions & 10 deletions cross-chain/solana/programs/wormhole-gateway/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ pub struct DepositWormholeTbtc<'info> {

impl<'info> DepositWormholeTbtc<'info> {
fn constraints(ctx: &Context<Self>, 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
);

Expand All @@ -85,8 +91,7 @@ pub fn deposit_wormhole_tbtc(ctx: Context<DepositWormholeTbtc>, 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;

Expand Down

0 comments on commit c5d0770

Please sign in to comment.