-
Notifications
You must be signed in to change notification settings - Fork 45
[1/2] Authentication component rollup target #666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fbb19fd
to
aa01ece
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for authentication components to the Miden rollup system by introducing a new project template and compilation target for authentication components.
- Adds
--auth-component
template for creating authentication components that validate account state changes - Implements a "no-auth" authentication component example that increments nonce when account state changes
- Adds local network test demonstrating authentication component usage in counter contract scenario
Reviewed Changes
Copilot reviewed 189 out of 190 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tools/cargo-miden/src/commands/new_project.rs | Adds auth-component template option and updates template tag version |
tools/cargo-miden/src/target.rs | Adds AuthComponent rollup target detection and library type mapping |
tools/cargo-miden/src/lib.rs | Adds authentication component midenc compilation flags and RUSTFLAGS management |
tools/cargo-miden/tests/build.rs | Adds test for auth-component template validation |
midenc-session/src/lib.rs | Adds AuthComponent rollup target enum variant |
sdk/base/wit/miden.wit | Adds authentication-component interface definition |
examples/auth-component-no-auth/ | New example authentication component with no-auth implementation |
tests/integration-node/src/node_tests/counter_contract_no_auth.rs | Test demonstrating auth component usage |
Comments suppressed due to low confidence (1)
tools/cargo-miden/src/target.rs:54
- The error message is outdated and doesn't include the new 'authentication-component' option. It should be updated to include all valid project kinds.
_ => bail!(
"Invalid value '{}' for 'project-kind' in [package.metadata.miden]. Must be one of: \
'account', 'note-script', or 'transaction-script'",
kind_str
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
The miden-base expects the authentication component expects an authentication procedure with the name `auth_*` (underscore). Since WIT names are in kebab case convert this one to snake case. In the future miden-base will use annotation to mark the procedure as authentication procedure and we will remove this. Until then we use the following workaround.
add `-C link-args=--fatal-warnings` to cargo-miden `RUSTFLAGS` to error out in such cases during the linking.
…base recognize the authentication procedure.
…dure`, add comments.
9f7ec43
to
4efe063
Compare
@bitwalker Rebased and ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! There is one change that should be reverted here though (see my comment for details)
let init_body = core::mem::take(&mut self.init_body); | ||
let init = masm::Procedure::new( | ||
Default::default(), | ||
masm::Visibility::Public, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The init procedure needs to be public, so that it can be called from any call
able procedure in the component that needs to initialize a fresh context in its prologue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I understand why init
needs to be public. We only invoke the init
in our lifted exports functions (see an example at
compiler/tests/integration/expected/examples/basic_wallet.masm
Lines 13 to 21 in 4efe063
export.move-asset-to-note | |
exec.::miden:basic-wallet/[email protected]::init | |
trace.240 | |
nop | |
exec.::miden:basic-wallet/[email protected]::basic_wallet::miden:basic-wallet/[email protected]#move-asset-to-note | |
trace.252 | |
nop | |
exec.::std::sys::truncate_stack | |
end |
call
ed without any prologue and epilogue at the call site. So the lifted export functions are the only public procedures in the component.
See also the discussion that led to making init
private at 0xMiden/miden-base#1877
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be noted that the fact we're emitting a single module for a given Wasm binary is incidental here, it isn't an inherent structural thing, just an artifact of how Rust compiles to Wasm.
In any case, if we can guarantee that all exports from a component (including a program entrypoint, if present), are emitted to the same underlying MASM module, sure, the init
procedure can be private in that case. I didn't think that was something we guaranteed, so much as it was a happy accident of how things get compiled from Rust.
I'm fine with making this private until there is an actual issue in practice, but wanted to raise the chance of it being an issue during review to make sure the change is actually well-motivated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking this approved, per my latest comment
Close #660
Close #667
Corresponding template repo PR - 0xMiden/rust-templates#21
I suggest reviewing this PR on a per-commit basis.
This PR:
cargo miden new --auth-component [NAME]
);example/auth-component-no-auth
example project for no-auth version;example/auth-component-no-auth
as an authentication component usingmiden-client
in the counter contract scenario;