Skip to content

Commit 6d6419a

Browse files
committed
fix: make destroy_account_from assert core resource account
1 parent 9d52827 commit 6d6419a

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

aptos-move/framework/aptos-framework/doc/account.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,15 @@ Scheme identifier for Ed25519 signatures used to derive authentication keys for
700700

701701

702702

703+
<a id="0x1_account_EFLAG_NOT_ENABLED"></a>
704+
705+
706+
707+
<pre><code><b>const</b> <a href="account.md#0x1_account_EFLAG_NOT_ENABLED">EFLAG_NOT_ENABLED</a>: u64 = 21;
708+
</code></pre>
709+
710+
711+
703712
<a id="0x1_account_EINVALID_ACCEPT_ROTATION_CAPABILITY"></a>
704713

705714
The caller does not have a valid rotation capability offer from the other account
@@ -1037,7 +1046,7 @@ Destroy the Account resource from a given account.
10371046
Used to destroy the core resources account on mainnet.
10381047

10391048

1040-
<pre><code><b>public</b> <b>fun</b> <a href="account.md#0x1_account_destroy_account_from">destroy_account_from</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>)
1049+
<pre><code><b>public</b> entry <b>fun</b> <a href="account.md#0x1_account_destroy_account_from">destroy_account_from</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>)
10411050
</code></pre>
10421051

10431052

@@ -1046,9 +1055,15 @@ Used to destroy the core resources account on mainnet.
10461055
<summary>Implementation</summary>
10471056

10481057

1049-
<pre><code><b>public</b> <b>fun</b> <a href="account.md#0x1_account_destroy_account_from">destroy_account_from</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>) <b>acquires</b> <a href="account.md#0x1_account_Account">Account</a> {
1058+
<pre><code><b>public</b> entry <b>fun</b> <a href="account.md#0x1_account_destroy_account_from">destroy_account_from</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>) <b>acquires</b> <a href="account.md#0x1_account_Account">Account</a> {
10501059
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(<a href="account.md#0x1_account">account</a>);
10511060

1061+
// Assert that the feature flag for decommissioning core resources is enabled
1062+
<b>assert</b>!(
1063+
std::features::get_decommission_core_resources_enabled(),
1064+
<a href="account.md#0x1_account_EFLAG_NOT_ENABLED">EFLAG_NOT_ENABLED</a>
1065+
);
1066+
10521067
<b>let</b> <a href="account.md#0x1_account_Account">Account</a> {
10531068
authentication_key: _,
10541069
sequence_number: _,

aptos-move/framework/aptos-framework/doc/governed_gas_pool.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ Deposits gas fees into the governed gas pool.
407407
@param gas_fee The amount of gas fees to be deposited.
408408

409409

410-
<pre><code><b>public</b> <b>fun</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_deposit_gas_fee">deposit_gas_fee</a>(gas_payer: <b>address</b>, gas_fee: u64)
410+
<pre><code><b>public</b> <b>fun</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_deposit_gas_fee">deposit_gas_fee</a>(_gas_payer: <b>address</b>, _gas_fee: u64)
411411
</code></pre>
412412

413413

@@ -416,7 +416,7 @@ Deposits gas fees into the governed gas pool.
416416
<summary>Implementation</summary>
417417

418418

419-
<pre><code><b>public</b> <b>fun</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_deposit_gas_fee">deposit_gas_fee</a>(gas_payer: <b>address</b>, gas_fee: u64) <b>acquires</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_GovernedGasPool">GovernedGasPool</a> {
419+
<pre><code><b>public</b> <b>fun</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_deposit_gas_fee">deposit_gas_fee</a>(_gas_payer: <b>address</b>, _gas_fee: u64) <b>acquires</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_GovernedGasPool">GovernedGasPool</a> {
420420
// get the sender <b>to</b> preserve the signature but do nothing
421421
<a href="governed_gas_pool.md#0x1_governed_gas_pool_governed_gas_pool_address">governed_gas_pool_address</a>();
422422
}
@@ -561,7 +561,7 @@ Abort if the governed gas pool has insufficient funds
561561
### Function `deposit_gas_fee`
562562

563563

564-
<pre><code><b>public</b> <b>fun</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_deposit_gas_fee">deposit_gas_fee</a>(gas_payer: <b>address</b>, gas_fee: u64)
564+
<pre><code><b>public</b> <b>fun</b> <a href="governed_gas_pool.md#0x1_governed_gas_pool_deposit_gas_fee">deposit_gas_fee</a>(_gas_payer: <b>address</b>, _gas_fee: u64)
565565
</code></pre>
566566

567567

aptos-move/framework/aptos-framework/sources/account.move

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ module aptos_framework::account {
260260
/// Destroy the Account resource from a given account.
261261
/// Used to destroy the core resources account on mainnet.
262262
public entry fun destroy_account_from(account: &signer, from: address) acquires Account {
263-
system_addresses::assert_aptos_framework(account);
263+
system_addresses::assert_core_resource(account);
264264

265265
// Assert that the feature flag for decommissioning core resources is enabled
266266
assert!(
@@ -998,9 +998,10 @@ module aptos_framework::account {
998998
);
999999
}
10001000

1001-
#[test(aptos_framework = @aptos_framework, from = @0xdead)]
1001+
#[test(aptos_framework = @aptos_framework, core_resources = @0xa550c18, from = @0xdead)]
10021002
public entry fun test_destroy_account_from_with_flag_enabled(
10031003
aptos_framework: &signer,
1004+
core_resources: &signer,
10041005
from: &signer,
10051006
) acquires Account {
10061007
// Enable the feature flag for testing
@@ -1015,16 +1016,17 @@ module aptos_framework::account {
10151016
assert!(exists<Account>(signer::address_of(from)), 1);
10161017

10171018
// Destroy the Account resource
1018-
destroy_account_from(aptos_framework, signer::address_of(from));
1019+
destroy_account_from(core_resources, signer::address_of(from));
10191020

10201021
// Confirm the resource has been removed
10211022
assert!(!exists<Account>(signer::address_of(from)), 2);
10221023
}
10231024

1024-
#[test(aptos_framework = @aptos_framework, from = @0xdead)]
1025+
#[test(aptos_framework = @aptos_framework, core_resources = @0xa550c18, from = @0xdead)]
10251026
#[expected_failure(abort_code = 21, location = Self)]
10261027
public entry fun test_destroy_account_from_with_flag_disabled(
10271028
aptos_framework: &signer,
1029+
core_resources: &signer,
10281030
from: &signer,
10291031
) acquires Account {
10301032
// Disable the feature flag for testing
@@ -1039,7 +1041,7 @@ module aptos_framework::account {
10391041
assert!(exists<Account>(signer::address_of(from)), 1);
10401042

10411043
// Attempt to destroy the Account resource (should fail)
1042-
destroy_account_from(aptos_framework, signer::address_of(from));
1044+
destroy_account_from(core_resources, signer::address_of(from));
10431045
}
10441046

10451047
#[test_only]

aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ type Bytes = Vec<u8>;
3737
#[cfg_attr(feature = "fuzzing", derive(proptest_derive::Arbitrary))]
3838
#[cfg_attr(feature = "fuzzing", proptest(no_params))]
3939
pub enum EntryFunctionCall {
40+
/// Destroy the Account resource from a given account.
41+
/// Used to destroy the core resources account on mainnet.
42+
AccountDestroyAccountFrom {
43+
from: AccountAddress,
44+
},
45+
4046
/// Offers rotation capability on behalf of `account` to the account at address `recipient_address`.
4147
/// An account can delegate its rotation capability to only one other address at one time. If the account
4248
/// has an existing rotation capability offer, calling this function will update the rotation capability offer with
@@ -1130,6 +1136,7 @@ impl EntryFunctionCall {
11301136
pub fn encode(self) -> TransactionPayload {
11311137
use EntryFunctionCall::*;
11321138
match self {
1139+
AccountDestroyAccountFrom { from } => account_destroy_account_from(from),
11331140
AccountOfferRotationCapability {
11341141
rotation_capability_sig_bytes,
11351142
account_scheme,
@@ -1804,6 +1811,23 @@ impl EntryFunctionCall {
18041811
}
18051812
}
18061813

1814+
/// Destroy the Account resource from a given account.
1815+
/// Used to destroy the core resources account on mainnet.
1816+
pub fn account_destroy_account_from(from: AccountAddress) -> TransactionPayload {
1817+
TransactionPayload::EntryFunction(EntryFunction::new(
1818+
ModuleId::new(
1819+
AccountAddress::new([
1820+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1821+
0, 0, 0, 1,
1822+
]),
1823+
ident_str!("account").to_owned(),
1824+
),
1825+
ident_str!("destroy_account_from").to_owned(),
1826+
vec![],
1827+
vec![bcs::to_bytes(&from).unwrap()],
1828+
))
1829+
}
1830+
18071831
/// Offers rotation capability on behalf of `account` to the account at address `recipient_address`.
18081832
/// An account can delegate its rotation capability to only one other address at one time. If the account
18091833
/// has an existing rotation capability offer, calling this function will update the rotation capability offer with
@@ -5034,6 +5058,16 @@ pub fn vesting_vest_many(contract_addresses: Vec<AccountAddress>) -> Transaction
50345058
}
50355059
mod decoder {
50365060
use super::*;
5061+
pub fn account_destroy_account_from(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
5062+
if let TransactionPayload::EntryFunction(script) = payload {
5063+
Some(EntryFunctionCall::AccountDestroyAccountFrom {
5064+
from: bcs::from_bytes(script.args().get(0)?).ok()?,
5065+
})
5066+
} else {
5067+
None
5068+
}
5069+
}
5070+
50375071
pub fn account_offer_rotation_capability(
50385072
payload: &TransactionPayload,
50395073
) -> Option<EntryFunctionCall> {
@@ -6916,6 +6950,10 @@ type EntryFunctionDecoderMap = std::collections::HashMap<
69166950
static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMap> =
69176951
once_cell::sync::Lazy::new(|| {
69186952
let mut map: EntryFunctionDecoderMap = std::collections::HashMap::new();
6953+
map.insert(
6954+
"account_destroy_account_from".to_string(),
6955+
Box::new(decoder::account_destroy_account_from),
6956+
);
69196957
map.insert(
69206958
"account_offer_rotation_capability".to_string(),
69216959
Box::new(decoder::account_offer_rotation_capability),

0 commit comments

Comments
 (0)