Repository navigation
Solidity: Fix premint amounts below 1 generating literals with leading zeros - #894
RaphaelFakhri wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Normalize and test premint units packages/core/solidity/src/erc20.ts, packages/core/solidity/src/erc20.test.ts, .changeset/premint-leading-zeros.md |
calculatePremint removes leading zeros from the combined digits before appending exponent-derived zeros. Tests cover 0.05 and 0.001e1. A patch changeset describes the fix. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- Solidity: Premint amounts below 1 with a leading fractional zero generate code that does not compile #893 — Describes the invalid Solidity number literal generated for premint amounts such as
0.05, which this change addresses.
Suggested reviewers: frangio, ericglau, ernestognw
Merge Risk: 
Minimal · up to f067a
-
The premint fix preserves supported numeric forms and addresses the invalid leading-zero literals without an identified merge-blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#893requires compilable literals for premint values below 1, including0.05and exponent notation.calculatePremintnow appliesstripLeadingZerosto the concatenated integer and fractional digits before adding exponent-derived zeros. The new tests verify0.05producesunits: '5'and0.001e1producesunits: '1', with the expected decimal exponent.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
|
I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement |
Fixes #893
calculatePremintstrips leading zeros from the integer part and trailing zeros from the fractional part, but it does not strip leading zeros from the fractional part. When the premint is below 1 and the fractional part starts with a zero, the generated literal starts with a zero. Solidity rejects it.For example, ERC20 with premint
0.05generates the following line:solc0.8.x fails withParserError: Octal numbers not allowed.The same happens for0.001,0.01e1, and in Stablecoin, RWA, and Confidential ERC7984, which use the same calculation.Changes
calculatePremint.0.05now generates_mint(recipient, 5 * 10 ** (decimals() - 2));, which compiles.calculatePremintwith amounts below 1.@openzeppelin/wizard.Testing
npx ava src/erc20.test.ts --match "calculatePremint*"inpackages/core/solidity: fails onmain(units: '05'), passes with the fix.0.05compiles withsolcjsafter the fix.yarn testinpackages/core/confidential,yarn lint, andyarn format:checkpass.