solana-program-library icon indicating copy to clipboard operation
solana-program-library copied to clipboard

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

Open vkomenda opened this issue 4 years ago • 9 comments

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 avatar Jun 28 '21 15:06 vkomenda

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

vkomenda avatar Jun 28 '21 16:06 vkomenda

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.

ppoliani avatar Sep 10 '21 09:09 ppoliani

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!

ruymaster avatar Oct 13 '21 09:10 ruymaster

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

t-nelson avatar Oct 13 '21 16:10 t-nelson

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.

joncinque avatar Jan 11 '22 00:01 joncinque

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

SUMEETRM avatar Jul 05 '22 07:07 SUMEETRM

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?

stevenbooke avatar Jan 22 '24 02:01 stevenbooke

The command with decimals is working well on current version!

ruymaster avatar Jan 22 '24 02:01 ruymaster

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

joncinque avatar Jan 24 '24 12:01 joncinque