0xMiden / 0xMiden/compiler

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

Abierto
#1,201 0 comentarios 0 reacciones 1 asignado Reclamado por @greenhat Ver en GitHub
rust sdk
Lenguaje dominante
Rust
Estrellas
115
Forks
84
Merge medio
1 d 8 h
PR fusionados (30 d)
15

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.