Skip to content

Refactor: Return Result instead of panic in native_token_scale_factor() #40

@Zena-park

Description

@Zena-park

Context

Flagged in PR #35 code review (comment).

Problem

crates/common/types/genesis.rsnative_token_scale_factor() can panic on user-supplied config when native_token_l1_decimals > 18, which can crash nodes at runtime (e.g., when reading genesis JSON).

Current Code

10u64.pow(18 - self.native_token_l1_decimals.unwrap())

This will panic with underflow if decimals > 18.

Proposed Fix

Return Result<Option<U256>, _> (or validate config during deserialization/initialization) so invalid configs surface as structured errors instead of panics.

Note: The bridge contract already rejects >18 decimals, but defense-in-depth at the Rust layer is still valuable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    skip-ciSkip CI checks on this PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions