-
Notifications
You must be signed in to change notification settings - Fork 52
feat(move-compiler): Add authenticator attribute #8951
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/8116-feature-branch
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -563,6 +563,11 @@ pub struct FunctionDefinition { | |
| pub visibility: Visibility, | ||
| /// Marker if the function is intended as an entry function. That is | ||
| pub is_entry: bool, | ||
| /// In case the function has been marked by "authenticator(version = x)" | ||
| /// attribute, this field will contain the specified version. | ||
| /// A value of None indicates that the function was not marked as an | ||
| /// authenticator. | ||
| pub authenticator_version: Option<u8>, | ||
|
||
| /// List of locally defined types (declared in this module) with the `Key` | ||
| /// ability that the procedure might access, either through: | ||
| /// BorrowGlobal, MoveFrom, or transitively through another procedure | ||
|
|
@@ -2937,6 +2942,7 @@ pub fn basic_test_module() -> CompiledModule { | |
| function: FunctionHandleIndex(0), | ||
| visibility: Visibility::Private, | ||
| is_entry: false, | ||
| authenticator_version: None, | ||
| acquires_global_resources: vec![], | ||
| code: Some(CodeUnit { | ||
| locals: SignatureIndex(0), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| use move_core_types::u256::U256; | ||
| use move_ir_types::location::Spanned; | ||
| use move_symbol_pool::Symbol; | ||
|
|
||
| use crate::{ | ||
| diag, | ||
| diagnostics::DiagnosticReporter, | ||
| expansion::ast::{Attribute_, AttributeName_, AttributeValue}, | ||
| shared::{ | ||
| known_attributes::{AuthenticatorAttribute, KnownAttribute}, | ||
| unique_map::UniqueMap, | ||
| }, | ||
| }; | ||
|
|
||
| pub fn parse_authenticator_version( | ||
| reporter: &DiagnosticReporter, | ||
| attributes: &UniqueMap<Spanned<KnownAttribute>, Spanned<Attribute_>>, | ||
| ) -> Option<u8> { | ||
| let Some(attribute) = attributes.get_(&AuthenticatorAttribute.into()) else { | ||
| return None; | ||
| }; | ||
|
|
||
| let sp!(authenticator_loc, value) = attribute; | ||
| match value { | ||
| Attribute_::Name(_) => Some(1), | ||
| Attribute_::Assigned(_, attribute_value) => { | ||
| authenticator_version_to_u8(reporter, &attribute_value) | ||
| } | ||
| Attribute_::Parameterized(_, inner_attributes) => { | ||
| let Some(sp!(_, version_value)) = inner_attributes.get_(&AttributeName_::Unknown( | ||
| Symbol::from(AuthenticatorAttribute::VERSION), | ||
| )) else { | ||
| reporter.add_diag(diag!( | ||
| Attributes::InvalidValue, | ||
| ( | ||
| *authenticator_loc, | ||
| "Missing `version` for authenticator attribute. Expected format: #[authenticator(version = ...)]".to_string() | ||
| ) | ||
| )); | ||
| return None; | ||
| }; | ||
|
|
||
| match version_value { | ||
| Attribute_::Name(_) | Attribute_::Parameterized(_, _) => None, | ||
| Attribute_::Assigned(_, attribute_value) => { | ||
| authenticator_version_to_u8(reporter, &attribute_value) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn authenticator_version_to_u8( | ||
| reporter: &DiagnosticReporter, | ||
| attribute_value: &AttributeValue, | ||
| ) -> Option<u8> { | ||
| use crate::expansion::ast::{AttributeValue_ as EAV, Value_ as EV}; | ||
|
|
||
| match attribute_value { | ||
| sp!(_, EAV::Value(sp!(_, EV::U8(value)))) => Some(*value), | ||
| sp!(_, EAV::Value(sp!(_, EV::InferredNum(value)))) if *value <= U256::from(u8::MAX) => { | ||
| Some(value.down_cast_lossy()) | ||
| } | ||
| // As a catch all, we reject all other supported attribute value types. | ||
| sp!(_, _) => { | ||
| reporter.add_diag(diag!( | ||
| Attributes::InvalidValue, | ||
| ( | ||
| attribute_value.loc, | ||
| "Only unannotated or u8 literal `version` values are supported.".to_string() | ||
| ), | ||
| )); | ||
| None | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ mod canonicalize_handles; | |
| #[macro_use] | ||
| mod context; | ||
| mod optimize; | ||
| mod authenticator_attribute; | ||
| pub mod translate; | ||
Uh oh!
There was an error while loading. Please reload this page.