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

Arbitrary precision arithmetic by default #3660

Closed
appetrosyan opened this issue Jun 29, 2023 · 4 comments
Closed

Arbitrary precision arithmetic by default #3660

appetrosyan opened this issue Jun 29, 2023 · 4 comments
Assignees
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST QA-confirmed This bug is reproduced and needs a fix

Comments

@appetrosyan
Copy link
Contributor

appetrosyan commented Jun 29, 2023

Feature request

In lieu of providing multiple fixed-width integer types for all assets, we instead should provide a variable width, fixed precision storage system (with re-allocation) that acts like an arbitrary precision number.

So, all numbers are represented as a Fixed, where the precision is either unspecified and arbitrary (in metadata) or specified at the asset definition creation time and fixed for the duration of the asset's existence.

We differentiate between BinaryFixedPoint as it is used today and DecimalFixedPoint. This allows us to bridge the gap between different blockchains.

Rules

  • Any operation that involves BinaryFixedPoint and DecimalFixedPoint must use arbitrary precision to find the precise answer and use lossy conversions.
  • Any operation that involves numbers of the same kind, may optionally use specialised faster instructions, but fall back to arbitrary precision in cases of overflow, changing the backing storage but not panicking.
  • Operation totals get accumulated into a temporary floating point buffer with no precision loss until being added to the metrics total.
@appetrosyan appetrosyan added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label Jun 29, 2023
@appetrosyan appetrosyan changed the title Always store u128 as quantity Arbitrary length Integer Jun 29, 2023
@appetrosyan appetrosyan changed the title Arbitrary length Integer Arbitrary precision arithmetic by default Jun 29, 2023
@Erigara Erigara self-assigned this Aug 9, 2023
@mversic mversic self-assigned this Dec 7, 2023
@mversic mversic removed their assignment Jan 23, 2024
@mversic
Copy link
Contributor

mversic commented Jan 23, 2024

I think the inspiration here is something like NUMBER in Oracle

@s8sato
Copy link
Contributor

s8sato commented Feb 14, 2024

Just like 10^18 wei for ETH, what if the resolution of the base unit for the named unit is determined on the asset definition creation and only the number of base units is calculated internally?
There may be a reason why the current design did not adopt it though

@mversic
Copy link
Contributor

mversic commented Feb 14, 2024

@Erigara I think you should write what we've decided to do about this since the description of the ticket no longer matches what is being implemented

@Erigara
Copy link
Contributor

Erigara commented Feb 14, 2024

@mversic sure.

After some dissuasion we decided to provide numeric type for Assets similar to commonly encountered NUMERIC type in relational databases (Postgre, MySql, Oracle).

This type is decimal point number which provides 2 parameters:

  • precision: amount of significant decimal digits in number
  • scale: amount of decimal places after point

From the user point of view it would look like this:

  1. When registering AssetDefinition user will provide NumericSpec with desired precision and scale for the given asset
  2. When sending instruction to Iroha: mint, transfer, burn. Values of asset will be checked to satisfy given spec.

Encoding:

  • for json string representation will be used: "10", "10.3"
  • for scale Numeric will be encoded by two numbers: mantissa and scale, so 10 will be encoded as 10;0, 10.42 as 1042;2

Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
…` for `Asset`s

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
…ic!`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
…ic!`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
…` for `Asset`s

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
…ic!`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
…ic!`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 22, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
…` for `Asset`s

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
…ic!`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
…ic!`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Feb 29, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 1, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 1, 2024
…` for `Asset`s

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 1, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 1, 2024
…ic!`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 1, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 1, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 1, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit to Erigara/iroha that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Erigara added a commit that referenced this issue Mar 6, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
@timofeevmd timofeevmd self-assigned this Apr 1, 2024
@timofeevmd timofeevmd added the QA-confirmed This bug is reproduced and needs a fix label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST QA-confirmed This bug is reproduced and needs a fix
Projects
None yet
Development

No branches or pull requests

5 participants