Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors found in the TBRv3 Solana Audit #105

Merged
merged 14 commits into from
Jan 22, 2025
Merged

Fix errors found in the TBRv3 Solana Audit #105

merged 14 commits into from
Jan 22, 2025

Conversation

feli-xlabs
Copy link
Contributor

  • Allow to create accounts by hand even if they're squatted.
  • Refactor the program ownership transfer so that we only need the new owner's signature when accepting the transfer.
  • Check both the chain ID and the peer address in case of an inbound transfer

@feli-xlabs feli-xlabs marked this pull request as ready for review January 9, 2025 18:53
Copy link
Contributor

@nonergodic nonergodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only comments/nits, nothing that's really important.

sdk/solana/tbrv3/token-bridge-relayer.ts Outdated Show resolved Hide resolved
Comment on lines +60 to +89
let total_fees_mwei = (|| {
let evm_transaction_fee_mwei = config
.evm_transaction_gas
.checked_mul(u64::from(oracle_evm_prices.gas_price))?;
let evm_tx_size_fee_mwei = config
.evm_transaction_size
.checked_mul(u64::from(oracle_evm_prices.price_per_byte))?;
let dropoff_mwei = u64::from(dropoff_amount_micro).checked_mul(MWEI_PER_MICRO_ETH)?;

evm_transaction_fee_mwei
.checked_add(evm_tx_size_fee_mwei)?
.checked_add(dropoff_mwei)
})()
.ok_or(TokenBridgeRelayerError::Overflow)?;

// μusd = Mwei * μusd/Token / Mwei/Token + μusd)
let total_fees_micro_usd = u64::try_from(
u128::from(total_fees_mwei) * u128::from(oracle_evm_prices.gas_token_price) / MWEI_PER_ETH,
)
.expect("Overflow")
+ u64::from(chain_config.relayer_fee_micro_usd);
.map_err(|_| TokenBridgeRelayerError::Overflow)?
.checked_add(u64::from(chain_config.relayer_fee_micro_usd))
.ok_or(TokenBridgeRelayerError::Overflow)?;

// lamports/SOL * μusd / μusd/SOL
Ok((LAMPORTS_PER_SOL * total_fees_micro_usd) / oracle_config.sol_price)
let fee = total_fees_micro_usd
.checked_mul(LAMPORTS_PER_SOL)
.map(|sol| sol / oracle_config.sol_price)
.ok_or(TokenBridgeRelayerError::Overflow)?;

Ok(fee)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where the motivation for the custom type with a single, simple overflow check at the end that you mentioned came from. Only a mother can love this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like it, maybe that's because I'm a father, not a mother.

solana/programs/token-bridge-relayer/src/lib.rs Outdated Show resolved Hide resolved
solana/tests/token-bridge-relayer-tests.ts Outdated Show resolved Hide resolved
solana/tests/utils/helpers.ts Show resolved Hide resolved
solana/tests/utils/helpers.ts Show resolved Hide resolved
solana/tests/utils/helpers.ts Show resolved Hide resolved
solana/tests/utils/helpers.ts Show resolved Hide resolved
@scnale scnale merged commit e42ad48 into main Jan 22, 2025
1 check passed
@scnale scnale deleted the audit-solana branch January 22, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants