0xMiden / 0xMiden/protocol

MASM pattern for polymorphic procedure calls

Đang mở
#2,187 13 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
132
Fork
167
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
110

Mô tả

## Description

Opening this issue to spark a discussion around polymorphism/interface pattern requirement in MASM.

### Use Case

The Zoro team (and potentially other developers) want to implement a pattern where an account shares a common `receive_asset` procedure root without having to depend on the underlying MAST root of the `validate_and_update_state`.

### Current Behavior

**Original Implementation (Doesn't Work):**
```masm
export.receive_asset
procref.validate_and_update_state mem_storew_be.ADDR dropw push.ADDR
dynexec

exec.native_account::add_asset
dropw
end
```

Note: Since `procref` is resolved at compile time, each account implementation with a different `validate_and_update_state` logic will produce a different `receive_asset` procedure hash. This breaks the architecture because the team needs a consistent procedure hash to identify and call the function across different account types.

### Current Workaround

```masm
export.receive_asset
push.VALIDATE_AND_UPDATE_STATE_HASH_ADDR exec.active_account::get_item
push.ADDR mem_storew_be dropw push.ADDR
dynexec

exec.native_account::add_asset
dropw
end
```

**Problems with this approach:**
1. Requires storing the validation procedure hash in account storage. We do not have support for immutables, so the only approach would be to store it as constants or in normal storage.
2. Since account storage is mutable, this opens up potential security vulnerabilities.

### Questions

1. Is there a recommended pattern for this use case that we have and should document? What is the current solution to this problem?
2. Should we consider language-level support for interface/trait-like patterns?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.