Skip to content

refactor(transforms): replace magic numbers with named constants #13

@EmperorOrokuSaki

Description

@EmperorOrokuSaki

Issue

Multiple magic numbers are hardcoded throughout the transforms crate, making the code less readable and maintainable.

Current State

Several magic numbers without clear meaning:

  • 1024 in stack_noise.rs:49 (EVM stack limit)
  • 64 in detection.rs:260 (auxdata scan window)
  • 0x5b in detection.rs:333 (JUMPDEST opcode)
  • 32_000 and 200 in obfuscate.rs:203 (gas calculation)

Proposed Solution

Replace with named constants:

const EVM_STACK_LIMIT: usize = 1024;
const AUXDATA_SCAN_WINDOW: usize = 64;
const JUMPDEST_OPCODE: u8 = 0x5b;
const BASE_GAS_COST: u64 = 32_000;
const GAS_PER_BYTE: u64 = 200;

Benefits

  • Improved code readability
  • Self-documenting code
  • Easier to modify values in the future
  • Reduced chance of typos

Files to Modify

  • crates/transforms/src/stack_noise.rs
  • crates/core/src/detection.rs
  • crates/cli/src/commands/obfuscate.rs

Priority

Low - Code quality improvement

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions