Solidity: Premint amounts below 1 with a leading fractional zero generate code that does not compile

Aperta
#893 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@RaphaelFakhri ci sta già lavorando.

Dal 25/10/2026.

  • #894 di @RaphaelFakhri — aperta
  • #898 di @ninglinLiu — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
solidity, typescript

Direzione di ricerca

Inspect calculatePremint in packages/core/solidity/src/erc20.ts where leading fractional zeros remain when integer part is empty. Run the issue's snippet with premint '0.05' to reproduce bad output. Open PR #894 already fixes this, so coordinate there. Done: generated constructor compiles with 5 * 10 ** (decimals() - 2).

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

  1. In the Solidity ERC20 tab, set Premint to 0.05.
  2. Compile the generated contract.

Or with the package:

const { erc20 } = require('@openzeppelin/wizard');
console.log(erc20.print({ name: 'MyToken', symbol: 'MTK', premint: '0.05' }));

Actual behavior

The constructor contains:

_mint(recipient, 05 * 10 ** (decimals() - 2));

solc fails with:

ParserError: Octal numbers not allowed.

The same happens for other amounts such as 0.001 or 0.001e1, and for Stablecoin, RWA, and Confidential ERC7984, which share calculatePremint.

Expected behavior

The generated line is _mint(recipient, 5 * 10 ** (decimals() - 2));, which compiles.

Cause

calculatePremint in packages/core/solidity/src/erc20.ts strips leading zeros from the integer part and trailing zeros from the fractional part, then concatenates them. Leading zeros of the fractional part remain at the start of units when the integer part is empty.

Lingua principale
TypeScript
Stelle
296
Fork
188
Merge medio
3h 24m
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenZeppelin/contracts-wizard

Tutte le issue di OpenZeppelin/contracts-wizard

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.