Skip to content

Commit

Permalink
[AA] fix issues (#15876)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark authored Feb 4, 2025
1 parent 60f7ca8 commit 6760e82
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 104 deletions.
203 changes: 160 additions & 43 deletions aptos-move/framework/aptos-framework/doc/account_abstraction.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions aptos-move/framework/aptos-framework/doc/staking_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,22 @@ Staking reward configurations that will be stored with the @aptos_framework acco



<a id="0x1_staking_config_BPS_DENOMINATOR"></a>
<a id="0x1_staking_config_EDEPRECATED_FUNCTION"></a>

Denominator of number in basis points. 1 bps(basis points) = 0.01%.
The function has been deprecated.


<pre><code><b>const</b> <a href="staking_config.md#0x1_staking_config_BPS_DENOMINATOR">BPS_DENOMINATOR</a>: u64 = 10000;
<pre><code><b>const</b> <a href="staking_config.md#0x1_staking_config_EDEPRECATED_FUNCTION">EDEPRECATED_FUNCTION</a>: u64 = 10;
</code></pre>



<a id="0x1_staking_config_EDEPRECATED_FUNCTION"></a>
<a id="0x1_staking_config_BPS_DENOMINATOR"></a>

The function has been deprecated.
Denominator of number in basis points. 1 bps(basis points) = 0.01%.


<pre><code><b>const</b> <a href="staking_config.md#0x1_staking_config_EDEPRECATED_FUNCTION">EDEPRECATED_FUNCTION</a>: u64 = 10;
<pre><code><b>const</b> <a href="staking_config.md#0x1_staking_config_BPS_DENOMINATOR">BPS_DENOMINATOR</a>: u64 = 10000;
</code></pre>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module aptos_framework::account_abstraction {
const EFUNCTION_INFO_EXISTENCE: u64 = 2;
const EAUTH_FUNCTION_SIGNATURE_MISMATCH: u64 = 3;
const ENOT_MASTER_SIGNER: u64 = 4;
const EINCONSISTENT_SIGNER_ADDRESS: u64 = 5;
const EDEPRECATED_FUNCTION: u64 = 6;

const MAX_U64: u128 = 18446744073709551615;

Expand All @@ -43,9 +45,9 @@ module aptos_framework::account_abstraction {
V1 { auth_functions: OrderedMap<FunctionInfo, bool> }
}

/// Update dispatchable authenticator that enables account abstraction.
/// Add dispatchable authentication function that enables account abstraction via this function.
/// Note: it is a private entry function that can only be called directly from transaction.
public entry fun add_dispatchable_authentication_function(
entry fun add_authentication_function(
account: &signer,
module_address: address,
module_name: String,
Expand All @@ -59,7 +61,9 @@ module aptos_framework::account_abstraction {
);
}

public entry fun remove_dispatchable_authentication_function(
/// Remove dispatchable authentication function that enables account abstraction via this function.
/// Note: it is a private entry function that can only be called directly from transaction.
entry fun remove_authentication_function(
account: &signer,
module_address: address,
module_name: String,
Expand All @@ -73,9 +77,10 @@ module aptos_framework::account_abstraction {
);
}

/// Update dispatchable authenticator that disables account abstraction.
/// Remove dispatchable authenticator so that all dispatchable authentication functions will be removed as well.
/// After calling this function, the account is not abstracted at all.
/// Note: it is a private entry function that can only be called directly from transaction.
public entry fun remove_dispatchable_authenticator(
entry fun remove_authenticator(
account: &signer,
) acquires DispatchableAuthenticator {
assert!(!is_permissioned_signer(account), error::permission_denied(ENOT_MASTER_SIGNER));
Expand Down Expand Up @@ -115,32 +120,31 @@ module aptos_framework::account_abstraction {
DispatchableAuthenticator::V1 { auth_functions: ordered_map::new() }
);
};
if (exists<DispatchableAuthenticator>(resource_addr)) {
let current_map = &mut borrow_global_mut<DispatchableAuthenticator>(resource_addr).auth_functions;
if (is_add) {
assert!(
!ordered_map::contains(current_map, &auth_function),
error::already_exists(EFUNCTION_INFO_EXISTENCE)
);
ordered_map::add(current_map, auth_function, true);
} else {
assert!(
ordered_map::contains(current_map, &auth_function),
error::not_found(EFUNCTION_INFO_EXISTENCE)
);
ordered_map::remove(current_map, &auth_function);
};
event::emit(
UpdateDispatchableAuthenticator {
account: addr,
update: if (is_add) { b"add" } else { b"remove" },
auth_function,
}
assert!(exists<DispatchableAuthenticator>(resource_addr), error::not_found(EFUNCTION_INFO_EXISTENCE));
let current_map = &mut borrow_global_mut<DispatchableAuthenticator>(resource_addr).auth_functions;
if (is_add) {
assert!(
!ordered_map::contains(current_map, &auth_function),
error::already_exists(EFUNCTION_INFO_EXISTENCE)
);
if (ordered_map::length(current_map) == 0) {
remove_dispatchable_authenticator(account);
}
ordered_map::add(current_map, auth_function, true);
} else {
assert!(
ordered_map::contains(current_map, &auth_function),
error::not_found(EFUNCTION_INFO_EXISTENCE)
);
ordered_map::remove(current_map, &auth_function);
};
event::emit(
UpdateDispatchableAuthenticator {
account: addr,
update: if (is_add) { b"add" } else { b"remove" },
auth_function,
}
);
if (ordered_map::length(current_map) == 0) {
remove_authenticator(account);
}
}

#[view]
Expand Down Expand Up @@ -170,10 +174,17 @@ module aptos_framework::account_abstraction {
func_info: FunctionInfo,
signing_data: AbstractionAuthData,
): signer acquires DispatchableAuthenticator {
let func_infos = dispatchable_authenticator_internal(signer::address_of(&account));
let master_signer_addr = signer::address_of(&account);
let func_infos = dispatchable_authenticator_internal(master_signer_addr);
assert!(ordered_map::contains(func_infos, &func_info), error::not_found(EFUNCTION_INFO_EXISTENCE));
function_info::load_module_from_function(&func_info);
dispatchable_authenticate(account, signing_data, &func_info)
let returned_signer = dispatchable_authenticate(account, signing_data, &func_info);
// Returned signer MUST represent the same account address. Otherwise, it may break the invariant of Aptos blockchain!
assert!(
master_signer_addr == signer::address_of(&returned_signer),
error::invalid_state(EINCONSISTENT_SIGNER_ADDRESS)
);
returned_signer
}

/// The native function to dispatch customized move authentication function.
Expand All @@ -190,14 +201,41 @@ module aptos_framework::account_abstraction {
let bob_addr = signer::address_of(bob);
create_account_for_test(bob_addr);
assert!(!using_dispatchable_authenticator(bob_addr), 0);
add_dispatchable_authentication_function(
add_authentication_function(
bob,
@aptos_framework,
string::utf8(b"account_abstraction_tests"),
string::utf8(b"test_auth")
);
assert!(using_dispatchable_authenticator(bob_addr), 0);
remove_dispatchable_authenticator(bob);
remove_authenticator(bob);
assert!(!using_dispatchable_authenticator(bob_addr), 0);
}

#[deprecated]
public entry fun add_dispatchable_authentication_function(
_account: &signer,
_module_address: address,
_module_name: String,
_function_name: String,
) {
abort std::error::unavailable(EDEPRECATED_FUNCTION)
}

#[deprecated]
public entry fun remove_dispatchable_authentication_function(
_account: &signer,
_module_address: address,
_module_name: String,
_function_name: String,
) {
abort std::error::unavailable(EDEPRECATED_FUNCTION)
}

#[deprecated]
public entry fun remove_dispatchable_authenticator(
_account: &signer,
) {
abort std::error::unavailable(EDEPRECATED_FUNCTION)
}
}
Loading

0 comments on commit 6760e82

Please sign in to comment.