solana-labs / solana-program-library

A collection of Solana programs maintained by Solana Labs
https://solanalabs.com
Apache License 2.0
3.56k stars 2.08k forks source link

token-cli: Minting more than `u64::MAX` tokens leads to confusing behavior #1983

Open vkomenda opened 3 years ago

vkomenda commented 3 years ago

Here are devnet transactions:

$ spl-token create-token --decimals 18
Creating token BZk67G7gcKquWXAgoTDoKqe78xwkSQiF4thsqYkHshJd
Signature: XioHUWB36xfCT97iPsQhugHnN39obq4UxPp9m7d5oc7fYfmcoa4DGs7wvbFsw1zijkXcr6LkHZ7yQLHr1befSVi

$ spl-token mint BZk67G7gcKquWXAgoTDoKqe78xwkSQiF4thsqYkHshJd 1000
Minting 1000 tokens

$ spl-token supply BZk67G7gcKquWXAgoTDoKqe78xwkSQiF4thsqYkHshJd
18.446744073709551615

Similar commands work fine with other tokens that have less decimal digits.

vkomenda commented 3 years ago

Can we make the token amount a u128 in the program? Why is it currently a u64?

ppoliani commented 3 years ago

Is there a reason the token program allows creating Mint accounts with 18 decimals? The supply being an u64 does not leave too much room for practical application of such a token.

ruymaster commented 3 years ago

I am trying to ming token with decimal 18 and total supply 100,000,000,000. command is not working correctly. There is a same issue!

t-nelson commented 3 years ago

I am trying to ming token with decimal 18 and total supply 100,000,000,000. command is not working correctly. There is a same issue!

As mentioned above, the token supply is implemented as a u64. It can represent at most 18,446,744,073,709,551,615 base units, so if you want 100B total supply, the largest decimals you can use is 8

joncinque commented 2 years ago

Seems like as a start, the CLI could error by default if you're trying to mint more than the max supply, with some sort of yolo flag to get rid of the check if someone wants to overmint. And at least print a correct message.

SUMEETRM commented 2 years ago

Made a pull request to fix this issue: https://github.com/solana-labs/solana-program-library/pull/3275

stevenbooke commented 9 months ago

Does this issue still need to be worked on?

My understanding is that specifying --decimals x means that the base unit of the token is $\mathbf{10^{-x}}$, which means 1 token is made up of $\mathbf{10^{x}}$ base units. Let $\mathbf{T}$ denote the max tokens that can be minted. We get $\mathbf{2^{64} - 1 = T \times 10^{x}}$, which gives us $\mathbf{T = \frac{2^{64} - 1}{10^{x} } }$. Is my understanding correct?

ruymaster commented 9 months ago

The command with decimals is working well on current version!

joncinque commented 9 months ago

The confusing behavior is still there unfortunately. You can "over-mint" tokens with the "mint" command, try running the commands in the first post and you'll see that you only get 18.44... tokens even though you ask to mint 1000