sherlock-audit / 2024-11-telcoin-judging

0 stars 0 forks source link

Young Lime Mouse - Non-Standard `decimals` Storage May Cause Compatibility Issues #238

Closed sherlock-admin4 closed 1 week ago

sherlock-admin4 commented 1 week ago

Young Lime Mouse

Low/Info

Non-Standard decimals Storage May Cause Compatibility Issues

Title: Non-Standard decimals Storage May Cause Compatibility Issues


Summary

The unconventional storage of the decimals variable in Stablecoin.sol may cause compatibility issues with wallets, exchanges, or other contracts that interact with the token. This design choice will cause potential display or calculation errors for external parties as they expect decimals to be stored in the standard ERC20 manner.


Root Cause

In Stablecoin.sol, at lines 61-64, the decimals are stored in a custom storage slot using StorageSlot:

// Lines 61-64
bytes32 internal constant DECIMALS_SLOT =
    0x86386409a65c1a7f963bc51852fa7ecbdb9cad2cec464de22ee4591e1622b46b;

function decimals() public view override returns (uint8) {
    return uint8(StorageSlot.getUint256Slot(DECIMALS_SLOT).value);
}

This deviates from the standard ERC20 implementation, where decimals is typically a public state variable.


Internal Pre-conditions

  1. Use of custom storage slot for decimals: The contract uses a non-standard method to store decimals.
  2. External systems expect standard storage: Wallets and exchanges assume decimals are stored per the ERC20 standard.

Impact

External systems interacting with the token may misinterpret the decimals value, leading to incorrect display of token balances or transaction amounts. This can cause confusion among users and potentially lead to transaction errors.


Mitigation

Adopt the standard ERC20 practice for storing and accessing the decimals variable. Modify the contract to use a simple uint8 public decimals declaration:

// Replace custom storage with standard declaration
uint8 public decimals;

Initialize decimals in the constructor or initializer function:

constructor() {
    decimals = 18; // or the desired decimal value
}

If customization is necessary, ensure thorough documentation and consider implementing interfaces or methods that allow external systems to retrieve the correct decimals value reliably.