Skip to content

Change STRK and ETH ERC20 implementation; fix minting#799

Merged
FabijanC merged 7 commits intomainfrom
change-erc20-impl
Jun 16, 2025
Merged

Change STRK and ETH ERC20 implementation; fix minting#799
FabijanC merged 7 commits intomainfrom
change-erc20-impl

Conversation

@FabijanC
Copy link
Copy Markdown
Contributor

@FabijanC FabijanC commented Jun 11, 2025

Usage related changes

Development related changes

  • Rely on permissioned_mint instead of transfer for minting.
  • Remove unused minting error variant.
  • Prevent overflow in token contract total_supply in case of forking.

Checklist:

  • Checked out the contribution guidelines
  • Applied formatting - ./scripts/format.sh
  • No linter errors - ./scripts/clippy_check.sh
  • No unused dependencies - ./scripts/check_unused_deps.sh
  • No spelling errors - ./scripts/check_spelling.sh
  • Performed code self-review
  • Rebased to the latest commit of the target branch (or merged it into my branch)
    • Once you make the PR reviewable, please avoid force-pushing
  • Updated the docs if needed - ./website/README.md
  • Linked the issues resolvable by this PR - linking info
  • Updated the tests if needed; all passing - execution info

Summary by CodeRabbit

  • New Features

    • Added distinct ETH and STRK ERC20 token contracts, each with unique class hashes, addresses, names, and symbols.
    • Improved error reporting for minting failures, providing transaction hash and revert reason when minting is reverted.
  • Bug Fixes

    • Ensured correct function selector is used for minting operations and transaction traces.
    • Prevented redeployment of accounts if already deployed.
  • Documentation

    • Updated documentation to describe error responses for reverted minting transactions and clarified various comments.
  • Chores

    • Refined and updated constants and test configurations to use the new ETH and STRK ERC20 contract details.
    • Removed obsolete constants and error variants.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 11, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change replaces the previously used generic Cairo 1 ERC20 contract class and class hash constants with distinct constants and contract definitions for ETH and STRK ERC20 tokens. The update affects both implementation and test code, ensuring that the correct class hashes and contract addresses are used for predeployed ETH and STRK tokens. The minting logic is updated to use the "permissioned_mint" function instead of "transfer," and error handling for minting failures is enhanced. Documentation and comments are updated to reflect these changes, and outmoded constants and error variants are removed.

Assessment against linked issues

Objective Addressed Explanation
Use the same ERC20 contract classes and class hashes for STRK and ETH as on Testnet/Mainnet (#795)
Remove forced/incorrect class hash usage for ERC20 tokens (#795)
Update configuration, deployment, and tests to use the correct ETH and STRK class hashes (#795)
Remove or update outdated constants and error handling related to ERC20 tokens (#795)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation

No out-of-scope changes found.

Possibly related PRs


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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@FabijanC FabijanC changed the title Change STRK and ETH ERC20 implementation Change STRK and ETH ERC20 implementation; fix minting Jun 13, 2025
@FabijanC FabijanC marked this pull request as ready for review June 13, 2025 13:15
@FabijanC
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
crates/starknet-devnet-core/src/account.rs (1)

171-201: 🛠️ Refactor suggestion

Balance-initialisation loop silently double-counts when both fee-token addresses coincide

for fee_token_address in [self.eth_fee_token_address, self.strk_fee_token_address] { … } will iterate twice over the same address whenever the caller passes identical ETH & STRK addresses (as done in the tests).
That inflates ERC20_total_supply and rewrites ERC20_balances twice, masking potential bugs in real-world scenarios and making the helper dangerous if a future caller accidentally reuses an address.

Minimal fix—deduplicate before the loop:

-        for fee_token_address in [self.eth_fee_token_address, self.strk_fee_token_address] {
+        use std::collections::HashSet;
+        let unique_addresses: HashSet<_> =
+            [self.eth_fee_token_address, self.strk_fee_token_address].into_iter().collect();
+
+        for fee_token_address in unique_addresses {

This avoids unintended double mutation while keeping complexity trivial.

🧹 Nitpick comments (9)
website/docs/balance.md (1)

49-56: Specify language in fenced block to satisfy markdown-lint

Add json after the opening fence to silence MD040 and enable syntax highlighting.

-```
+```json
 {
     "tx_hash": "0x123..."
     "revert_reason": "Something happened"
 }
-```
+```
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

51-51: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

tests/integration/test_subscription_to_tx_status.rs (1)

23-26: Hard-coded tx hash may require frequent maintenance

The deterministic hash assertion is valuable, but every tweak to minting logic or class hash will force a test update.
Consider deriving the expected hash via the same hashing routine used by Devnet instead of embedding a literal.

crates/starknet-devnet-core/src/account.rs (1)

315-316: Test only deploys STRK ERC20 class – ETH path left un-exercised

The test pre-deploys STRK_ERC20_CONTRACT_CLASS_HASH for both fee tokens, leaving the ETH implementation untested. Consider pre-deploying the ETH class hash to improve coverage of the split-token logic.

crates/starknet-devnet-core/src/starknet/mod.rs (1)

833-837: Selector literal updated, but calldata length comment unchanged

permissioned_mint takes 3 arguments (recipient, low, high).
The preceding comment "// target address" is still accurate, but consider adding a short note that
the selector was switched from "transfer" to "permissioned_mint" to avoid confusion when
walking through git history.

crates/starknet-devnet-server/src/api/http/endpoints/mint_token.rs (1)

66-86: Hold lock only as long as necessary

The tokio::Mutex guarding starknet remains locked during the entire await chain, including the
call to get_balance. This blocks every concurrent JSON-RPC request that needs starknet, even
though balance retrieval is read-only.

-    let mut starknet = api.starknet.lock().await;
-    ...
-    let tx_hash = starknet.mint(...).await?;
-    let tx = starknet.get_transaction_execution_and_finality_status(tx_hash)?;
-    match tx.execution_status {
+    let tx_hash = {
+        let mut starknet = api.starknet.lock().await;
+        starknet.mint(request.address, request.amount, erc20_address).await?
+    };
+
+    let execution_status = {
+        let starknet = api.starknet.lock().await;
+        starknet.get_transaction_execution_and_finality_status(tx_hash)?
+    };
+
+    match execution_status.execution_status {

Releasing the lock earlier improves concurrency without altering semantics.

crates/starknet-devnet-server/src/api/json_rpc/error.rs (1)

80-82: Consider exposing the revert reason directly in the error message

JSON-RPC clients often surface only the top-level message field. Putting the primary revert reason
there (in addition to data) greatly improves UX:

-    #[error("Minting reverted")]
+    #[error("Minting reverted{revert_reason_msg}")]
+    MintingReverted {
+        tx_hash: Felt,
+        #[source]
+        revert_reason: Option<String>,
+    },

where revert_reason_msg is formatted conditionally. Optional but worth considering.

crates/starknet-devnet-core/src/starknet/starknet_config.rs (2)

12-17: Import list updated – keep ordering consistent

The added ETH/STRK constants are correct, but the list is now mixed between “general defaults” and “token-specific” constants.
For readability, group the ETH/STRK lines together (or in a dedicated // ERC-20 block) to mirror the layout in constants.rs.


171-175: Large Sierra blobs are cloned on every Default instantiation

ETH_ERC20_CONTRACT_CLASS.to_string() (and the STRK variant) allocates and copies the entire Sierra source into a String each time StarknetConfig::default() is called. These files are > 100 KB and the default is created frequently in tests.

If the field does not need mutability, store &'static str (or Cow<'static, str>) instead to share the memory:

-    pub eth_erc20_contract_class: String,
+    pub eth_erc20_contract_class: &'static str,
 ...
-            eth_erc20_contract_class: ETH_ERC20_CONTRACT_CLASS.to_string(),
+            eth_erc20_contract_class: ETH_ERC20_CONTRACT_CLASS,

Same for strk_erc20_contract_class.

crates/starknet-devnet-core/src/constants.rs (1)

28-36: Consistent naming & path constants

Previous patterns expose both _SIERRA_PATH and _SIERRA (in-file string). For the new ETH/STRK contracts only the latter is provided. Aligning the naming keeps the public API predictable:

+pub const ETH_ERC20_CONTRACT_SIERRA_PATH: &str = concat!(
+    env!("CARGO_MANIFEST_DIR"),
+    "/contracts/system_artifacts/erc20_eth.sierra"
+);
+pub const ETH_ERC20_CONTRACT_CLASS: &str = include_str!(ETH_ERC20_CONTRACT_SIERRA_PATH);
-
-pub const ETH_ERC20_CONTRACT_CLASS: &str = include_str!(concat!(
-    env!("CARGO_MANIFEST_DIR"),
-    "/contracts/system_artifacts/erc20_eth.sierra"
-));

Apply the same pattern to STRK.
This reduces duplication and matches the existing CAIRO_1_ACCOUNT_CONTRACT_SIERRA[_PATH] naming.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff5a3ac and dee7d57.

📒 Files selected for processing (17)
  • crates/starknet-devnet-core/src/account.rs (4 hunks)
  • crates/starknet-devnet-core/src/constants.rs (1 hunks)
  • crates/starknet-devnet-core/src/error.rs (0 hunks)
  • crates/starknet-devnet-core/src/starknet/mod.rs (3 hunks)
  • crates/starknet-devnet-core/src/starknet/predeployed.rs (2 hunks)
  • crates/starknet-devnet-core/src/starknet/starknet_config.rs (2 hunks)
  • crates/starknet-devnet-core/src/state/mod.rs (2 hunks)
  • crates/starknet-devnet-core/src/system_contract.rs (1 hunks)
  • crates/starknet-devnet-server/src/api/http/endpoints/mint_token.rs (2 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/error.rs (4 hunks)
  • tests/integration/common/constants.rs (1 hunks)
  • tests/integration/general_integration_tests.rs (2 hunks)
  • tests/integration/test_deploy.rs (1 hunks)
  • tests/integration/test_fork.rs (2 hunks)
  • tests/integration/test_subscription_to_tx_status.rs (1 hunks)
  • tests/integration/test_trace.rs (1 hunks)
  • website/docs/balance.md (1 hunks)
💤 Files with no reviewable changes (1)
  • crates/starknet-devnet-core/src/error.rs
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/integration/general_integration_tests.rs (1)
tests/integration/common/utils.rs (1)
  • to_hex_felt (157-159)
crates/starknet-devnet-server/src/api/http/endpoints/mint_token.rs (4)
crates/starknet-devnet-core/src/account.rs (1)
  • get_balance (205-215)
crates/starknet-devnet-core/src/system_contract.rs (1)
  • get_balance (64-70)
tests/integration/test_messaging.rs (1)
  • get_balance (90-98)
crates/starknet-devnet-core/src/traits.rs (1)
  • get_balance (60-60)
crates/starknet-devnet-core/src/system_contract.rs (3)
crates/starknet-devnet-types/src/rpc/contract_class.rs (1)
  • cairo_1_from_sierra_json_str (53-58)
crates/starknet-devnet-core/src/state/mod.rs (1)
  • default (159-165)
crates/starknet-devnet-core/src/starknet/starknet_config.rs (1)
  • default (144-177)
tests/integration/test_fork.rs (1)
tests/integration/common/background_devnet.rs (1)
  • get_config (415-417)
🪛 markdownlint-cli2 (0.17.2)
website/docs/balance.md

51-51: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (10)
tests/integration/test_deploy.rs (1)

19-20: Helpful inline pointer – approved

The explanatory comment neatly directs contributors to the relocated tests without affecting compilation.

tests/integration/test_trace.rs (1)

41-47: Selector assertion updated correctly

Aligns with the new permissioned_mint entry-point. No issues spotted.

tests/integration/general_integration_tests.rs (2)

10-12: Imports now reflect split ETH/STRK ERC20 classes – looks good

Keeps constants explicit and avoids mis-routing.


62-64: Config JSON updated with distinct class hashes – approved

to_hex_felt conversion is consistent with the rest of the config schema.

crates/starknet-devnet-core/src/system_contract.rs (1)

79-80: Updated test imports look consistent with new token split

Replacing the generic Cairo-1 constants with ETH_ERC20_* keeps the test in sync with the production code and compiles cleanly. No further action required.

tests/integration/common/constants.rs (1)

46-49: Constant names & values align with main-net addresses – good addition

The dedicated class-hash constants for ETH and STRK make the intent explicit and remove ambiguity inherent in the previous single hash. 👍

crates/starknet-devnet-core/src/starknet/predeployed.rs (1)

46-47: Confirm storage key matches the new contract implementation

"permitted_minter" replaces "Ownable_owner". Ensure the STRK/ETH ERC20 contracts indeed expose this storage variable (same name, no namespace). A mismatch will leave the chargeable account unable to mint and surface only at runtime.

tests/integration/test_fork.rs (1)

633-645: Assertions correctly updated for split token class hashes

assert_ne! now checks both ETH & STRK class hashes, ensuring forked dev-nets do not reuse local classes. Looks solid.

crates/starknet-devnet-core/src/state/mod.rs (1)

53-54: Doc clarification looks good

The expanded comment makes the public contract of predeploy_contract explicit and removes any ambiguity about balance or constructor side-effects.

crates/starknet-devnet-core/src/constants.rs (1)

46-51: Good to see explicit token metadata

Exposing *_ERC20_NAME / *_ERC20_SYMBOL constants will help downstream integrations.

@FabijanC FabijanC merged commit 430b337 into main Jun 16, 2025
2 checks passed
@FabijanC FabijanC deleted the change-erc20-impl branch June 16, 2025 07:51
@coderabbitai coderabbitai bot mentioned this pull request Sep 24, 2025
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with default erc20 class

1 participant