Archway Precision: Why 18-decimal precision? #26
zanicar
announced in
Archway Blog
Replies: 1 comment
-
Archway's decimal precision poses a small challenge for dapp frontends. Example 1 (doesn't work) const ATTO_UNIT = 1000000000000000000;
console.log('1000 ARCH as aarch =', 1000 * ATTO_UNIT);
// Outputs: 1000 ARCH as aarch = 1e+21 Example 2 (works) const ATTO_UNIT = 1000000000000000000;
console.log('1000 ARCH as aarch =', BigInt(1000) * BigInt(ATTO_UNIT));
// Outputs: 1000 ARCH as aarch = 1000000000000000000000n |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Archway Precision
Photo by Lukas Tennie on Unsplash
Why use 18 decimals of precision?
Abstract
Archway uses 18-decimal precision in order to more accurately track and reward individual contract usage. The CosmosSDK default 6-decimal precision is not sufficient, as accurate accounting for the Archway protocol requires at least 9-decimal precision. Instead of introducing yet another precision scale we opted to utilize an already familiar “standard”.
If you are interested in some lightweight learning more about blockchain precision scales, floating-points, quantum theory and astrophysics, please read on…
Background
In the worlds of finance, blockchain and mathematics, numeric precision plays an important and very interesting role. The purpose of subdivision is to allow for fine granular control / accounting in environments where both actual value and perceived value change over time. These changes occur as a result of changes in both the physical and economic environments that affect availability, supply, demand and associated risks. A sustainable economic model must be capable of adapting to and expressing such changes effectively.
Used Decimal Precision
Legend has it that when Bitcoin was originally discussed between Satoshi, Hal Finney and Ray Dillinger, they decided on Bitcoin's 8-decimal precision based on the hard limit of 21 million Bitcoin subdivided by the entire circulating supply of the combined world monetary systems at that time, to yield a unit worth approximately one US penny. However, this approach is not without some unintended side effects... such as Bitcoin transforming from its original design of being transactional to being more of a store of value today.
Legend has it that Ethereum in contrast decided to follow an approach that took the distant future into account to decide on its smallest subdivision, the WEI at 18-decimal precision. Such a degree of precision will allow the network to increase significantly in usage and total market capitalization, yet still offer a small unit of value that would remain convenient to use for transactional purposes.
In the Cosmos most projects utilize a default of 6-decimal precision as it has been found to be sufficient for the vast majority of use cases. This is because Cosmos chains are application specific and need not cater for the entire world economy. However, Archway requires greater granular accuracy for tracking individual contract usage and rewards distribution. Archway needs at least 9-decimal precision to realize its ideal economic model, but for compatibility and familiarity reasons elected to utilize 18-decimal precision as most ERC-20 tokens already utilize the same format used by Ethereum.
Why not dynamic precision?
One may be tempted to ask why not simply increase precision as and when it is required... However, the problem is twofold.
First, you may encounter rounding issues, for example
3 / 2 = 1.5
; Rounding to whole numbers will yield2 + 2 = 4
(a miracle), or1 + 1 = 2
(a black hole), where one unit is unaccounted for. The latter can easily be utilized to execute the infamous (or even legendary) "Salami Slicing Attack".Second, and more commonly, you will run into determinism issues due to the way fractions and decimal numbers are typically dealt with in the computing space. Computing systems utilize floating-point arithmetic that prominently uses rounding to represent the closest approximated number. However, different architectures and operating system environments may yield slightly different results due to their own internal representations... which in the world of distributed consensus systems, such as blockchain, will lead to consensus failures!
Enter Quantum Theory
Well, sort of... In Quantum Theory a Quanta represents the minimum amount of any physical entity that can be involved in any interaction. In blockchain we have something very similar to a quanta, we represent the smallest decimal unit as a whole number, as this unit is the smallest entity that can be part of a transaction.
In Bitcoin it is the Satoshi, and one Bitcoin is equal to 100,000,000 Satoshis (10^8). For Ethereum it is the WEI, and one ETH is equal to 1,000,000,000,000,000,000 WEI (10^18), that is one quintillion on the short scale. For Archway it is the
aarch
orattoARCH
, "Atto-" is the ISO prefix for a quintillionth and the prefix is derived from the Danish word for eighteen (“atten”).Astrophysics, Floating-points and Delegation Shares
One place where you can prominently see the effect of ultra high precision and the effects of floating-point rounding is when you stake / delegate exactly one ARCH to a validator. The amount staked is converted to shares (a floating-point value), which is required to deal with slashing events. With an 18-decimal precision, the amount which is calculated from the shares may be off by 1 aarch due to rounding, as the floating-point number will be rounded to its closest approximation.
But fear not, as one quintillionth is a mere 40mm / 1.57 inches over the entire distance between Sol (our sun) and Proxima Centauri, which is 4.2465 light years away (approximately 4.0x10^19mm); Alternatively it is also the equivalent of 1,000 grains of sand across planet Earth.
Beta Was this translation helpful? Give feedback.
All reactions