Status DataClose notification

DexLyn Disclosed Report

Audit Report

Logical Error in `data_amount` Calculation

Target

https://github.com/DexlynLabs/bridge-repo/tree/6a772c126e0879928021156ca91b89ac4f1bfcae/move

Vulnerability details

The transfer_remote_with_gas() function is designed to facilitate cross-chain transfers by sending funds from the source chain to the destination chain while covering the gas fees on the destination chain. However, there is a critical logical error in the calculation of data_amount, which could lead to financial losses for users.

Validation steps

https://github.com/DexlynLabs/bridge-repo/blob/main/move/synthetic-tokens/sources/hyper_coin.move#L165-L167 In the function, the protocol calculates data_amount based on the difference between the source_decimals and destination_decimals. The logic is as follows:

if (source_decimals < destination_decimals) {
    data_amount = (amount as u256) * calculate_power(10, ((destination_decimals - source_decimals) as u16));
} else if (source_decimals < destination_decimals) { // Logical error: Same condition as above
    data_amount = (amount as u256);
} else {
    data_amount = (amount as u256) / calculate_power(10, ((source_decimals - destination_decimals) as u16));
    assert!(data_amount > 0, EAMOUNT_TOO_SMALL);
}

Problem:

  • The condition for the else if branch is identical to the if branch (source_decimals < destination_decimals). This means:
    • If source_decimals < destination_decimals, the data_amount is first calculated as amount * 10^N (where N = destination_decimals - source_decimals).
    • However, the else if branch immediately overrides data_amount with amount, discarding the previous calculation.
  • As a result, the data_amount is incorrectly set to amount instead of the expected scaled value (amount * 10^N).

Impact: Financial Loss for Users

  1. Incorrect Token Amount in Destination Chain:
    • The protocol burns the user's tokens on the source chain based on the original amount.
    • However, due to the logical error, the data_amount sent to the destination chain is not scaled up when source_decimals < destination_decimals.
    • This means fewer tokens are minted on the destination chain than intended.

Solution: Fix the Logical Error

To resolve this issue, the else if condition should be corrected to handle the case where source_decimals == destination_decimals. The corrected logic should look like this:

if (source_decimals < destination_decimals) {
    data_amount = (amount as u256) * calculate_power(10, ((destination_decimals - source_decimals) as u16));
} else if (source_decimals > destination_decimals) {
    data_amount = (amount as u256) / calculate_power(10, ((source_decimals - destination_decimals) as u16));
    assert!(data_amount > 0, EAMOUNT_TOO_SMALL);
} else {
    data_amount = (amount as u256); // Handle case where source_decimals == destination_decimals
}

Comments are hidden

This information is not publicly available.