0xMiden / 0xMiden/miden-vm

Consider making `hash_string_to_word` a `const fn`

未关闭
#2,454 9 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
tools
主要语言
Rust
星标
772
派生
352
平均合并
1 天 7 小时
30 天内合并 PR
84

描述

`hash_string_to_word` essentially, blake3-hashes its input and converts the result into a `Word`.

The `blake3` crate doesn't offer a `const` implementation, afaict, but there is https://github.com/triblespace/const-BLAKE3 as an alternative. We may want to look into that to enable deriving hashes in `const` contexts.
I think the main question is how trustworthy the implementation is.

This would be useful in miden-base to bring back `StorageSlotName::from_static_str`, which is no longer possible now that we have included the derived `StorageSlotId` into the slot name itself.

Instead of defining slot names like this:

```rust
static FALCON_PUBKEY_SLOT_NAME: LazyLock = LazyLock::new(|| {
StorageSlotName::new("miden::standards::auth::rpo_falcon512::public_key")
.expect("storage slot name should be valid")
});

impl AuthRpoFalcon512 {
pub fn public_key_slot() -> &'static StorageSlotName {
&FALCON_PUBKEY_SLOT_NAME
}
}
```

It would allow us to guarantee compile-time slot name validation and expose a nicer API for users:

```rust
impl AuthRpoFalcon512 {
pub const FALCON_PUBKEY_SLOT: StorageSlotName = StorageSlotName::from_static_str(
"miden::standards::auth::rpo_falcon512::public_key"
);
}
```

贡献指南

打开贡献指南

调研方向

Look at the `hash_string_to_word` function in the codebase, likely in a hashing or utils module. Investigate the `const-BLAKE3` crate as an alternative to the current `blake3` crate for const compatibility. The goal is to enable `StorageSlotName::from_static_str` to be a const function again, allowing compile-time validation. Check the existing tests for `hash_string_to_word` and `StorageSlotName` to understand the expected behavior.

由索引模型根据 Issue 内容生成。

评估

技术栈
rust
领域
backend, cryptography
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。