peatio icon indicating copy to clipboard operation
peatio copied to clipboard

Peatio rounds ETH amounts to 16 decimal points

Open antonDigitalMagic opened this issue 3 years ago • 3 comments

The bug was found using the opendax 2-4-stable branch with eth mainnet.

We've sent deposit to the User's deposit address, the amount received is 20447946344588791 Wei. According to etherscan.

This is 0,020447946344588791 Ether (18 decimal places)

Collection fee daemon logs: {"level":"WARN","time":"2021-03-05 09:53:03","message":"The deposit was spreaded in the next way: [{:to_address=>"0xb1bf8eaab5d4c7d8608df400938bcba30c91ea0e", :amount=>"0.0204479463445888", :currency_id=>"eth", :status=>"pending"}]"}

Collection daemon logs: #<Peatio::Wallet::ClientError: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 20447946344588800 and got: 20447946344588791. (-32010)>"}

As you can see the Deposit amount has been rounded from 18 decimal places (0,020447946344588791) to 16 decimal places (0.0204479463445888) which is incorrect as in ethereum network the decimal limits is 18 NOT 16.

This problem has been caused by the MySQL Database fields configuration which is decimal(32,16) e.g. 16 decimal places.

So in case the number is more than 16 decimal places and it gets round UP, then deposit is uncollectable

The issue should be fixed for both deposits and withdraws

My view of a fix is to bump up all fields with decimal(32,16) to decimal(32,18), and add tests which check that numbers with 18 decimal places in ETH get parsed correctly by the system.

antonDigitalMagic avatar Mar 05 '21 13:03 antonDigitalMagic

Are you sure that this is fixing the issue? As i believe we have to round the amount down, if you can add a test case that would be great!

martianatwork avatar Mar 06 '21 12:03 martianatwork

Are you sure that this is fixing the issue? As i believe we have to round the amount down, if you can add a test case that would be great!

The issue is that ETH can have up to 18 decimal points and DB currently allows only 16.

I want to add some tests cases, but its hard for me to stratup peatio tests locally on a MAC. If you’re willing to contribute some test cases, feel free to do so.

antonDigitalMagic avatar Mar 06 '21 13:03 antonDigitalMagic

@antonDigitalMagic I think you are missing a point, yes your patch partially fixes the issue but not a proper solution. I believe almost all exchanges use ETH with 8 decimals, the problem is not about the storing the value but about the rounding.

Peatio will round the deposit while collecting and this is where 0.0204479463445888 will become 0.02044795 when it should have been 0.02044794

I hope this explains, i will submit a PR to fix this probably in the next week

martianatwork avatar Mar 07 '21 13:03 martianatwork