Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] as_u8 enum generated from sol! is incorrect #412

Closed
huyhduong1401 opened this issue Nov 15, 2023 · 0 comments · Fixed by #413
Closed

[Bug] as_u8 enum generated from sol! is incorrect #412

huyhduong1401 opened this issue Nov 15, 2023 · 0 comments · Fixed by #413
Labels
bug Something isn't working

Comments

@huyhduong1401
Copy link
Contributor

Component

sol-types, sol! macro

What version of Alloy are you on?

0.4.2

Operating System

macOS (Apple Silicon)

Describe the bug

I am using sol! macro to generate enum to use it for eip712 signing but when see the hash struct it is wrong. After investigate, I found that the as_u8 is wrong as i tested on rust playground

#[derive(Clone, Copy)]
#[repr(u8)]
enum Color {
    Red = 0,
    Green = 1,
    Blue = 2,
}

impl Color {
    fn as_u8(&self) -> &u8 {
        unsafe { &*::core::ptr::addr_of!(self).cast::<u8>() }
    }
}

fn main() {
    let color = Color::Red;
    let u8_value = color.as_u8();
    println!("The u8 value of the color is: {}", u8_value);
}

For this code it will print something like "The u8 value of the color is: 159"

@huyhduong1401 huyhduong1401 added the bug Something isn't working label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant