m10io / tokeninc-smart-contracts

Ethereum Solidity Smart Contracts for Token, Inc.
3 stars 6 forks source link

RFC: Add check to ensure token decimals being set are the same as other interfaces. Check edge condition of intended 0 decimal value. #30

Open seanavery opened 6 years ago

seanavery commented 6 years ago

https://github.com/tokenio/tokeninc-smart-contracts/blob/45eff8892efb222ba9b21af099f09fea32e044b0/contracts/TokenIOLib.sol#L119

Problem: On a high level, we want to make sure that the set of interfaces for a given currency have uniform decimal values. If the decimal is 0, it is possible that 0 is the intended value or simply the decimal value has not been initialized.

  1. We want to be able initially set decimal values.
  2. We want to be able to set decimal value to 0.
  3. We want to ensure uniformity of decimal values across interfaces.

Example:

USDx, 2 uint _decimals = getUint(...('token.decimals', currency))

0 means it has never been set.

token decimals == 0, but we want to set to 2; we need check if that is indeed the expected result;

0 == 0 && _decimals == 0; 1 != 2 && 1 > 0

require((_decimals != decimals && _decimals > 0), "Expected decimals to be the same as they are in the storage contract.")