0xPolygonMiden / miden-base

Core components of the Polygon Miden rollup
MIT License
70 stars 44 forks source link

Macro for `Digest` creation from long hex string #872

Open Fumuran opened 2 months ago

Fumuran commented 2 months ago

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.

bobbinth commented 2 months ago

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

digest!(0x886761b8acc91e06510bfd6a168213c4930c6cf09965427ea22518d3f2e2c01a)

But either way should be fine.

Mirko-von-Leipzig commented 1 month ago

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.