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

Solana: shortens types for EVM cost model parameters #117

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

scnale
Copy link
Collaborator

@scnale scnale commented Feb 11, 2025

No description provided.

@scnale scnale requested a review from a team February 11, 2025 16:07
Copy link

XLabs/arbitrary-token-transfers #117

Change Summary:

  • Modified type definitions from u64 to u32 for EVM transaction gas and size parameters across multiple files
  • Updated type conversions and comparisons from BigInt to Number in TypeScript/JavaScript files
  • Adjusted calculation methods to handle the new type constraints in Rust and TypeScript
  • Updated test cases and configurations to align with the new type specifications

Risk Score: 6/10

  • Explanation: Significant type conversion changes across multiple files with potential runtime implications and potential loss of precision

Potential Vulnerability:
File: solana/programs/token-bridge-relayer/src/utils.rs:58-67

let evm_transaction_fee_mwei = u64::from(config.evm_transaction_gas)
    * u64::from(oracle_evm_prices.gas_price);
  • Explanation: Potential integer overflow risk due to reduced bit width from u64 to u32, which could cause unexpected truncation or calculation errors

Code Smell:
File: sdk/solana/tbrv3/token-bridge-relayer.ts:832-836

const totalFeesMwei =
  BigInt(tbrConfig.evmTransactionGas) * BigInt(evmPrices.gasPrice) +
  BigInt(tbrConfig.evmTransactionSize) * BigInt(evmPrices.pricePerByte) +
  BigInt(dropoffAmount) * MWEI_PER_MICRO_ETH;
  • Explanation: Complex type conversion and mixing of Number and BigInt types, which can lead to unexpected behavior and reduced code readability

Unintended Consequences:
File: deployment/solana/configure.ts:35-42

const evmTxSize = Number(config.evmTransactionSize);
const evmTxGas = Number(config.evmTransactionGas);

if (
  evmTxSize !== contractConfig.evmTransactionSize ||
  evmTxGas !== contractConfig.evmTransactionGas
) {
  // Update configuration
}
  • Explanation: Potential precision loss when converting from larger integer types to smaller ones, which might cause configuration update triggers that were not intended

Debug Log:

  • No debug logs were identified in the provided diff that would need removal

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.

Looks good, the on thing that seems off is the bnToBigint conversion here which seems like a leftover?

@feli-xlabs
Copy link
Contributor

LGTM, same question as Andreas. Maybe the whole bnToBigint can be removed if unused.

@scnale scnale merged commit cd7e643 into main Feb 12, 2025
1 check passed
@scnale scnale deleted the fix/shorten-evm-cost-model-params branch February 12, 2025 13:05
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