-
Notifications
You must be signed in to change notification settings - Fork 187
fix: Add validation for ERC20 premint amount to prevent "Literal too large" error #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
664c252
f25c4c9
5249990
84c2549
0bb5698
3b2f545
35a36db
e98385f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,11 +179,21 @@ | |
| const decimalPlace = decimals.length - exponent; | ||
| const zeroes = new Array(Math.max(0, -decimalPlace)).fill('0').join(''); | ||
| const units = integer + decimals + zeroes; | ||
| const exp = decimalPlace <= 0 ? 'decimals()' : `(decimals() - ${decimalPlace})`; | ||
|
|
||
| // Add 18 decimals to the number (standard ERC20 decimals) | ||
| const fullAmount = units + '000000000000000000'; | ||
|
|
||
| // Check if the final number would be too large | ||
| if (fullAmount.length > 77) { // Solidity has a limit on number literals | ||
|
||
| throw new OptionsError({ | ||
| premint: 'Amount too large. Please use a smaller number to avoid Solidity literal limits', | ||
| }); | ||
| } | ||
|
|
||
| c.addConstructorArgument({ type: 'address', name: 'recipient' }); | ||
|
|
||
| const mintLine = `_mint(recipient, ${units} * 10 ** ${exp});`; | ||
| // Generate the mint line with the full amount directly | ||
| const mintLine = `_mint(recipient, ${fullAmount});`; | ||
|
||
|
|
||
| if (crossChainBridging) { | ||
| if (premintChainId === '') { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This number should not be hardcoded as 18 decimals. While 18 is the default, users who take the generated contract as a starting point could override the
decimals()function of ERC20.sol to change the intended display decimals. The premint amount should take this value into consideration.For example, if the user enters a Premint of 1000 in the UI, and they override
decimals()to 2, then the actual premint calculation should result in100000.