Skip to content

Revisit human-readable presentation of EVM opcodes #1602

@quasiyoke

Description

@quasiyoke

During the discussion of pull request #1544, we discussed that the representation of the opcode list in memory may be improved (#1600), and the code displaying opcodes may need refinement #1544 (review)

I prefer a solution like this. It has disadvantages:

  1. Requires new dependencies:
    • num-derive — we haven’t used this before.
    • num-traits — we already use this directly.
    • strum — is used in our subdependencies.
  2. Will increase build time.
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! num-derive = "0.4.2"
//! num-traits = "0.2.19"
//! strum = { version = "0.27.2", features = ["derive"] }
//! ```

use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use strum::IntoStaticStr;

#[derive(FromPrimitive, IntoStaticStr)]
#[repr(u8)]
enum Opcode {
    Stop = 0,
    Add = 1,
    Mul = 2,
}

fn main() {
    let s: &str = Opcode::from_u8(2).unwrap().into();
    assert_eq!(s, "Mul");
    println!("{}", s);
}

A part of #1560
As a follow up of #1544 (review)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions