0xMiden / 0xMiden/compiler

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

Open
#1,201 0 comments 0 reactions 1 assignee Claimed by @greenhat View on GitHub
rust sdk
Dominant language
Rust
Stars
115
Forks
84
Avg merge
1d 8h
Merged PRs (30d)
15

Description

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).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.