blocknet icon indicating copy to clipboard operation
blocknet copied to clipboard

Fix any precision issues caused by the usage of double (arithmetic)

Open shrnkld opened this issue 4 years ago • 2 comments

Scenario: The XBridge protocol currently uses a mix of (float), double, int64_t and uint64_t and as such we are seeing precision issues eg when partial orders are created (ref: https://github.com/blocknetdx/blocknet/issues/570)

Proposed solution: Replace all uses of (float), double, int64_t and uint64_t with a 'signed integer' type with 256 bits for all amounts (int256_t), enabling XBridge support for tokens with 18 decimal places (being similar to what ETH uses (uint256)). Further, using a signed type, as opposed to unsigned, would also prevent underflows in the event of a negative amount that results from a calculation.

To do:

  • [ ] remove/fix any precision issues caused by the usage of double (arithmetic) and replace with int256_t throughout the XBridge code

QA and Acceptance info to follow...

shrnkld avatar Nov 24 '21 09:11 shrnkld

@shrnkld LGTM

atcsecure avatar Nov 29 '21 15:11 atcsecure

WIP and ideas: step 1: replace all uint64_t with int64_t and test. ~~step 2: replace all float with double and test calculations and performance (increasing precision points for erc20 support)~~ cannot find any instances of float related to xbridge in the src. step 3:replace all int64_t with int256_t and retest

shrnkld avatar Jan 31 '23 15:01 shrnkld