Conversation
WalkthroughThe PR reorders ERC20 address constants in starknet-devnet-core. In starknet-devnet-types, it removes PREFIX_INVOKE and adds unchecked constructors: PatriciaKey::new_unchecked and ContractAddress::new_unchecked. In starknet-devnet-server, it replaces get_erc20_address (Result-returning) with get_erc20_fee_unit_address (direct value), updates callers in read/write endpoints, and adjusts error handling. ApiError removes GeneralError, renames InvalidValueError to InvalidAddress, and updates mappings accordingly. Balance and mint paths now use direct ERC20 address construction without fallible conversion. Unit tests validate ContractAddress::new vs new_unchecked for ETH/STRK addresses. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
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 review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
crates/starknet-devnet-types/src/patricia_key.rs (1)
22-23: Guard the unchecked constructor with a debug assertion and add a safety note.Helps catch accidental out-of-range uses in dev builds and documents the invariant.
impl PatriciaKey { @@ - Ok(Self(felt)) + Ok(Self(felt)) } - pub(crate) fn new_unchecked(felt: Felt) -> Self { - Self(felt) + /// Constructs without range checks. + /// Safety: `felt` must be in [0x0, PATRICIA_KEY_UPPER_BOUND). + pub(crate) fn new_unchecked(felt: Felt) -> Self { + debug_assert!( + Felt::from_hex_unchecked(PATRICIA_KEY_UPPER_BOUND) >= felt, + "PatriciaKey out of range" + ); + Self(felt) }Also applies to: 25-26
crates/starknet-devnet-types/src/rpc/contract_address.rs (1)
20-22: Document the unchecked constructor.Clarify caller responsibility to maintain invariants.
- pub fn new_unchecked(felt: Felt) -> Self { + /// Constructs a ContractAddress without range checks. + /// Safety: `felt` must satisfy PatriciaKey bounds. + pub fn new_unchecked(felt: Felt) -> Self { Self(PatriciaKey::new_unchecked(felt)) }crates/starknet-devnet-server/src/api/error.rs (1)
87-89: Confirm UX choice for InvalidAddress message.Mapping returns only the inner
msg(without the "Invalid address:" prefix). If intentional for cleaner client messages, keep as is; otherwise switch toerror_messagefor consistency with other variants.Would you like a small unit test asserting the RPC mapping for InvalidAddress? I can add one similar to existing tests.
Also applies to: 287-291
crates/starknet-devnet-server/src/api/account_helpers.rs (1)
60-65: Good switch to non-fallible ERC20 helper and validating tests.
- Helper now clearly reflects deterministic mapping of FeeUnit -> ERC20 address.
- Tests ensure constants remain in range for both checked/unchecked paths.
Optional: add doc comment on
get_erc20_fee_unit_addressnoting it relies on canonical, compile-time constants.Also applies to: 72-76, 80-105
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
crates/starknet-devnet-core/src/constants.rs(1 hunks)crates/starknet-devnet-server/src/api/account_helpers.rs(1 hunks)crates/starknet-devnet-server/src/api/endpoints.rs(3 hunks)crates/starknet-devnet-server/src/api/error.rs(4 hunks)crates/starknet-devnet-server/src/api/write_endpoints.rs(2 hunks)crates/starknet-devnet-types/src/constants.rs(0 hunks)crates/starknet-devnet-types/src/patricia_key.rs(1 hunks)crates/starknet-devnet-types/src/rpc/contract_address.rs(1 hunks)
💤 Files with no reviewable changes (1)
- crates/starknet-devnet-types/src/constants.rs
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: FabijanC
PR: 0xSpaceShard/starknet-devnet#799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, `get_class_hash_at` has different behaviors at different layers: at the internal state level (blockifier), it returns `Ok(ClassHash(Felt::ZERO))` for undeployed addresses, while at the RPC layer, this gets converted to `Err(Error::ContractNotFound)`. When checking if a contract is deployed at the internal state level, use `is_ok_and(|h| h.0 == Felt::ZERO)` to detect undeployed addresses.
📚 Learning: 2025-06-16T07:35:24.725Z
Learnt from: FabijanC
PR: 0xSpaceShard/starknet-devnet#799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, `get_class_hash_at` has different behaviors at different layers: at the internal state level (blockifier), it returns `Ok(ClassHash(Felt::ZERO))` for undeployed addresses, while at the RPC layer, this gets converted to `Err(Error::ContractNotFound)`. When checking if a contract is deployed at the internal state level, use `is_ok_and(|h| h.0 == Felt::ZERO)` to detect undeployed addresses.
Applied to files:
crates/starknet-devnet-types/src/rpc/contract_address.rscrates/starknet-devnet-core/src/constants.rs
🔇 Additional comments (4)
crates/starknet-devnet-core/src/constants.rs (1)
34-35: LGTM on constant reordering.No functional change; consistent with intent to group ERC20 symbols.
Also applies to: 43-44
crates/starknet-devnet-server/src/api/write_endpoints.rs (1)
20-21: Mint path simplification looks good.Using a non-fallible ERC20 address for known fee units removes unnecessary error plumbing.
Also applies to: 313-314
crates/starknet-devnet-server/src/api/error.rs (1)
302-302: Forwardability classification is appropriate.Keeping InvalidAddress non-forwardable aligns with local validation semantics.
Also applies to: 330-331
crates/starknet-devnet-server/src/api/endpoints.rs (1)
22-24: Address parsing and ERC20 helper updates look correct.
- Properly maps parse errors to InvalidAddress.
- Uses the non-fallible ERC20 address helper.
- Error propagation for get_balance stays intact.
Also applies to: 680-684, 692-693
Usage related changes
Better UX when Errors are printed out
Development related changes
Small change in ApiError enum, resolves #850.
Checklist:
./scripts/format.sh./scripts/clippy_check.sh./scripts/check_unused_deps.sh./scripts/check_spelling.sh./website/README.mdSummary by CodeRabbit