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

Macro for Digest creation from long hex string #872

Open
Fumuran opened this issue Sep 12, 2024 · 2 comments
Open

Macro for Digest creation from long hex string #872

Fumuran opened this issue Sep 12, 2024 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@Fumuran
Copy link
Contributor

Fumuran commented Sep 12, 2024

Feature description

Create a macro which will be able to create a new Digest value from a long hex string in a constant environment (inside a constant function/creation of a constant value).
Something like:

const KERNEL0_PROCEDURES: [Digest; 28] = [
    digest!("0x886761b8acc91e06510bfd6a168213c4930c6cf09965427ea22518d3f2e2c01a"),
    ...
    digest!("0x6d95ebdc8e3c480d72f0fc4320d6f8f9d11ae0b668fc17b9921633e736d7f83e"),
];

Why is this feature needed?

This macro will be used during the creation of the constant array of the kernel procedure hashes, making the code more concise.

@Fumuran Fumuran added the enhancement New feature or request label Sep 12, 2024
@bobbinth
Copy link
Contributor

bobbinth commented Sep 12, 2024

I wonder if we can provide the digest without quotation marks - e.g.:

digest!(0x886761b8acc91e06510bfd6a168213c4930c6cf09965427ea22518d3f2e2c01a)

But either way should be fine.

@Mirko-von-Leipzig
Copy link
Contributor

I had created this previously for pathfinder with two macros for const evaluation of hex string and from bytes.

The macros are here, and the const hex parsing here.

We did try existing crates for the hex parsing but they all expect exact lengths which kind of sucks for creating quick test values i.e. they reject 0x123.

Its also not possible to do this without the quotes unfortunately, as numeric input must fit into a numeric type so you'd be restricted to u128 length. Which might be fine for tests I guess.

@bobbinth bobbinth added this to the v0.7 milestone Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants