Change STRK and ETH ERC20 implementation; fix minting#799
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis 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
Assessment against linked issues: Out-of-scope changes
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🔭 Outside diff range comments (1)
crates/starknet-devnet-core/src/account.rs (1)
171-201: 🛠️ Refactor suggestionBalance-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 inflatesERC20_total_supplyand rewritesERC20_balancestwice, 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-lintAdd
jsonafter 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 maintenanceThe 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-exercisedThe test pre-deploys
STRK_ERC20_CONTRACT_CLASS_HASHfor 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_minttakes 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 necessaryThe
tokio::Mutexguardingstarknetremains locked during the entireawaitchain, including the
call toget_balance. This blocks every concurrent JSON-RPC request that needsstarknet, 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 messageJSON-RPC clients often surface only the top-level
messagefield. Putting the primary revert reason
there (in addition todata) greatly improves UX:- #[error("Minting reverted")] + #[error("Minting reverted{revert_reason_msg}")] + MintingReverted { + tx_hash: Felt, + #[source] + revert_reason: Option<String>, + },where
revert_reason_msgis formatted conditionally. Optional but worth considering.crates/starknet-devnet-core/src/starknet/starknet_config.rs (2)
12-17: Import list updated – keep ordering consistentThe 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-20block) to mirror the layout inconstants.rs.
171-175: Large Sierra blobs are cloned on everyDefaultinstantiation
ETH_ERC20_CONTRACT_CLASS.to_string()(and the STRK variant) allocates and copies the entire Sierra source into aStringeach timeStarknetConfig::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(orCow<'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 constantsPrevious patterns expose both
_SIERRA_PATHand_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 existingCAIRO_1_ACCOUNT_CONTRACT_SIERRA[_PATH]naming.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 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 – approvedThe explanatory comment neatly directs contributors to the relocated tests without affecting compilation.
tests/integration/test_trace.rs (1)
41-47: Selector assertion updated correctlyAligns with the new
permissioned_mintentry-point. No issues spotted.tests/integration/general_integration_tests.rs (2)
10-12: Imports now reflect split ETH/STRK ERC20 classes – looks goodKeeps constants explicit and avoids mis-routing.
62-64: Config JSON updated with distinct class hashes – approved
to_hex_feltconversion 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 splitReplacing 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 additionThe 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 goodThe expanded comment makes the public contract of
predeploy_contractexplicit 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 metadataExposing
*_ERC20_NAME/*_ERC20_SYMBOLconstants will help downstream integrations.
Usage related changes
total_supplyproperty of token contracts.Development related changes
permissioned_mintinstead oftransferfor minting.total_supplyin case of forking.Checklist:
./scripts/format.sh./scripts/clippy_check.sh./scripts/check_unused_deps.sh./scripts/check_spelling.sh./website/README.mdSummary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores