-
Notifications
You must be signed in to change notification settings - Fork 58
feat(verifier): make the authenticate function force the entry modifier #9368
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
base: vm-lang/aa-auth/8861-runtime-package-metadata
Are you sure you want to change the base?
feat(verifier): make the authenticate function force the entry modifier #9368
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 6 Skipped Deployments
|
|
Should this PR also include |
| _auth_ctx: &AuthContext, | ||
| _ctx: &TxContext, | ||
| ) {} | ||
| // FAIL Invalid 'entry' parameter type |
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.
Why does it fail? Because of Option arg?
| } else { | ||
| Err(format!( | ||
| "Invalid pure type. A datatype instantiation must be an option of pure types, offending argument: {param:?}" | ||
| "Invalid parameter type for authenticate function: {}. Valid types are immutable references to anything but receiving objects, or primitive types.", |
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.
Extremely minor notice - do we need comma before but.
Alternately I would rephrase it to Invalid parameter type for authenticate function: {}. Valid types are immutable references to anything, except receiving objects, or primitive types
The same notice for the error message above
| let handle = view.function_handle_at(func_def.function); | ||
| let params = view.signature_at(handle.parameters); | ||
|
|
||
| let all_non_ctx_params = match params.0.last() { |
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 would suggest simplified version of these checks.
- Removing inner match
- Less manual indexing
- A bit more structured
| let all_non_ctx_params = match params.0.last() { | |
| let all_non_ctx_params = match params.0.last() { | |
| Some(last_param) if TxContext::kind(view, last_param) != TxContextKind::None => { | |
| let mut non_ctx_params = ¶ms.0[..params.0.len() - 1]; | |
| if let Some((second_last, rest)) = non_ctx_params.split_last() { | |
| if AuthContext::kind(view, second_last) != AuthContextKind::None { | |
| non_ctx_params = rest; | |
| } | |
| } | |
| non_ctx_params | |
| } | |
| _ => ¶ms.0[..], | |
| }; |
| // Test account struct | ||
| public struct Account has key { | ||
| id: UID, | ||
| } |
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.
What is the reason to duplicate this type everywhere?
It is not really important for these tests; can be declared only once.
| // FAIL | ||
| #[allow(lint(share_owned))] | ||
| public fun by_value(_account: &Account, object: Object, _auth_ctx: &AuthContext, _ctx: &TxContext) { | ||
| transfer::public_share_object(object); | ||
| //#[authenticator] | ||
| public entry fun by_value( | ||
| _account: &Account, | ||
| object: Object, | ||
| _actx: &AuthContext, | ||
| _ctx: &TxContext, | ||
| ) { | ||
| let Object { id } = object; | ||
| object::delete(id); | ||
| } | ||
|
|
||
| // FAIL | ||
| public fun by_mutable_ref( | ||
| //#[authenticator] | ||
| public entry fun by_mutable_ref( | ||
| _account: &Account, | ||
| _object: &mut Object, | ||
| _auth_ctx: &AuthContext, | ||
| _actx: &AuthContext, | ||
| _ctx: &TxContext, | ||
| ) {} |
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 am not sure that I see the reason for having these tests anymore.
If we just comment some use cases, comment the #[authenticator] attribute. We check only positive ones that don't fail.
Are we going to create a test for each failed case later?
| let all_non_ctx_parameters = match parameters.last() { | ||
| Some((_, _, last_param_ty)) if tx_context_kind(last_param_ty) != TxContextKind::None => { | ||
| ¶meters[0..parameters.len() - 1] | ||
| let params_without_tx_ctx = ¶meters[0..parameters.len() - 1]; |
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.
Do we need to check AuthContext on the compiler level?
Can it be considered as a simple object parameter by the compiler?
Description of change
AuthContextas the second to last parameter. This might be a reason for an execution CUT.Links to any relevant issues
Fixes #9364
How the change has been tested