0

Is there a chance that a user can lose a fraction of ETH just performing normal transactions (addding money to a pool, sending it to someone)? I'm refereing to floating point numbers, I know there are no floating point numbers in Solidity, and from what I understand it's made like this to address the problem of losing money in werid circumstances, but what if we wanted to send 5 wei to 3 people (in form of an airdrop)? I'm refering to this article https://hackernoon.com/a-note-on-numbers-in-ethereum-and-javascript-3e6ac3b2fad9 where he says

Javascript’s [double] floating point numbers only go up to 16 decimals, but 1 ether = 10**18 wei. And all ether values in transactions must be denominated in wei.

Would this cause any problems developing the application? Could you think of a case where some wei would be lost or we are safe unless we divide the eth?

1
  • javascript frameworks are using bigint instead of floats which is helping to avoid rounding issues Commented May 16, 2022 at 19:01

1 Answer 1

0

It depends on the problem and the implemented solution.

For example if you want to split 1 eth = 10^18 wei between 3 addresses there will be 1 wei = 10^(-18) ether that you won't be able to split. One solution is to give 1 extra wei to one of addresses, or keep it in the contract balance as dust.

Some protocols that require extra precision have used fixed point with 36 decimals or even 54.

Obviously if the frontend does the error because it uses floating point then from solidity there's little you could do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.