0xMiden / 0xMiden/compiler

Consider `#[auth_component]` macro with a fixed trait shape for authentication components

オープン
#1,201 コメント 0 件 リアクション 0 件 担当者 1 名 @greenhat が担当を希望しています GitHub で見る
rust sdk
主要言語
Rust
スター
115
フォーク
84
平均マージ
1日 8時間
マージ済み PR(30日)
15

説明

Suggested in https://github.com/0xMiden/compiler/pull/1171#pullrequestreview-4519113305

> One thing that sticks out to me already - `#[auth_script]` serves to define an auth component, which are different from normal account components (i.e. they have unique constraints, are defined by having a single entrypoint - the auth procedure, the signature of which is also fixed AIUI). I would suggest that we use a separate `#[auth_component]` attribute for defining auth components. It would work somewhat similarly to `#[component]`, in that it decorates a trait - but it can be a lot stricter about shape/assumptions (i.e. it can require that the trait define only a single method, and that method must adhere to the signature requirements of auth procedures). It isn't clear to me why we'd use `#[auth_script]` to decorate component trait methods, since that implies that you could decorate more than one trait method with `#[auth_script]`, or that multiple traits could specify `#[auth_script]` methods and be used together, when in fact neither of those are the case. By modeling auth components as distinct entities, we regain some control over how they are used (or can at the very least prevent/catch more incorrect usages).

This might work IF we don't expect the authentication component to export ANY OTHER METHOD besides the authentication script itself.

It could look like the following code:

```rust
#[component_storage]
struct AuthComponentStorage {
/// The account owner's public key (RPO-Falcon512 public key hash).
#[storage(
description = "owner public key",
type = "miden::standards::auth::pub_key"
)]
owner_public_key: StorageValue,
}

/// API of the RPO-Falcon512 authentication component.
#[auth_component]
trait AuthComponent {
// #[auth_component] macro will require the only one method with fixed signature defined below
fn some_method(&mut self, _arg: Word);
}

#[auth_component]
impl AuthComponent for AuthComponentStorage {
fn some_method(&mut self, _arg: Word) {
// implementation
}
}
```

I feel that requiring the user to write the trait by hand is a bit awkward since its shape is predefined (one method with a fixed signature).

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。