https://github.com/DexlynLabs/bridge-repo/tree/6a772c126e0879928021156ca91b89ac4f1bfcae/move
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.
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);
}
else if branch is identical to the if branch (source_decimals < destination_decimals). This means:
source_decimals < destination_decimals, the data_amount is first calculated as amount * 10^N (where N = destination_decimals - source_decimals).else if branch immediately overrides data_amount with amount, discarding the previous calculation.data_amount is incorrectly set to amount instead of the expected scaled value (amount * 10^N).amount.data_amount sent to the destination chain is not scaled up when source_decimals < destination_decimals.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.