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

TON-ETH bridge: Arithmetic flaw in calculating fees #4

Open
vegancat opened this issue Sep 17, 2022 · 0 comments
Open

TON-ETH bridge: Arithmetic flaw in calculating fees #4

vegancat opened this issue Sep 17, 2022 · 0 comments

Comments

@vegancat
Copy link

Bug Type

Functional

Reproduction steps

1- open the bridge website
2- Input 999 in the input field "Amount of TON"

Actual result

Shown "Bridge Fees" is 7.484999999999999 TON

image

Expected result

According to Documentation "Bridge fees" is calculated as below:

input_amount = amount of TON which user inputs In the "Amount of TON" field (which is a minimum of 10TON)

Bridge Fees = (Fixed 5 TON) + ( 0.25% of (input_amount - 5))

Having 999 as input we have:

Bridge Fees = (5) + ( 0.25% * (999 - 5)) = 5 + 2.485 = 7.485 TON

Other cases

999 is not the only case. for example take a look at the cases below:

Trying 1000:

expected fee 7.4875, shown fee: 7.487500000000001 TON

image

Trying 100000000

expected fee 250004.9875, shown fee: 250004.98750000002 TON

image

Reason

It's happening due to the nature of storing float numbers. since numbers are stored in their binary representation. Some decimal values cannot be represented accurately in binary format and cause these kinda weird results.

suggestion

To illuminate this and other potential arithmetic flaws avoid calculating with bare Javascript methods and utilize a battle-tested Math Library.

Side-note

The demonstrated difference between displayed and expected value may seem insignificant but a malicious user with repetition may harm the bridge and its users significantly.

Suggested Severity

High

Device

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: chrome
  • Version: 21H2
    Chrome

Additional Context

No response

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

No branches or pull requests

1 participant