-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
feli-xlabs
commented
Jan 2, 2025
- 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
0886d29
to
1fb1484
Compare
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
… so that when the new owner accepts the transfer, there is no need for the previous owner's signature.