Skip to content

Commit 867b182

Browse files
authored
Merge pull request #160 from movementlabsxyz/andygolay/is-core-resource-false
feat: make is_core_resource_address always return false
2 parents edafe2e + 0be2220 commit 867b182

File tree

10 files changed

+134
-35
lines changed

10 files changed

+134
-35
lines changed

aptos-move/aptos-release-builder/src/components/feature_flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub enum FeatureFlag {
122122
LimitVMTypeSize,
123123
AbortIfMultisigPayloadMismatch,
124124
GovernedGasPool,
125+
DecommissionCoreResources,
125126
}
126127

127128
fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
@@ -332,6 +333,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
332333
AptosFeatureFlag::ABORT_IF_MULTISIG_PAYLOAD_MISMATCH
333334
},
334335
FeatureFlag::GovernedGasPool => AptosFeatureFlag::GOVERNED_GAS_POOL,
336+
FeatureFlag::DecommissionCoreResources => AptosFeatureFlag::DECOMMISSION_CORE_RESOURCES,
335337
}
336338
}
337339
}
@@ -457,6 +459,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
457459
FeatureFlag::AbortIfMultisigPayloadMismatch
458460
},
459461
AptosFeatureFlag::GOVERNED_GAS_POOL => FeatureFlag::GovernedGasPool,
462+
AptosFeatureFlag::DECOMMISSION_CORE_RESOURCES => FeatureFlag::DecommissionCoreResources,
460463
}
461464
}
462465
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,15 @@ Scheme identifier for Ed25519 signatures used to derive authentication keys for
689689

690690

691691

692+
<a id="0x1_account_EFLAG_NOT_ENABLED"></a>
693+
694+
695+
696+
<pre><code><b>const</b> <a href="account.md#0x1_account_EFLAG_NOT_ENABLED">EFLAG_NOT_ENABLED</a>: u64 = 21;
697+
</code></pre>
698+
699+
700+
692701
<a id="0x1_account_EINVALID_ACCEPT_ROTATION_CAPABILITY"></a>
693702

694703
The caller does not have a valid rotation capability offer from the other account

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/doc/system_addresses.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232

3333
<pre><code><b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
34+
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features">0x1::features</a>;
3435
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">0x1::signer</a>;
3536
</code></pre>
3637

@@ -145,7 +146,12 @@ The operation can only be performed by the VM
145146

146147

147148
<pre><code><b>public</b> <b>fun</b> <a href="system_addresses.md#0x1_system_addresses_is_core_resource_address">is_core_resource_address</a>(addr: <b>address</b>): bool {
148-
addr == @core_resources
149+
// Check <b>if</b> the feature flag for decommissioning core resources is enabled.
150+
<b>if</b> (get_decommission_core_resources_enabled()) {
151+
<b>false</b>
152+
} <b>else</b> {
153+
addr == @core_resources
154+
}
149155
}
150156
</code></pre>
151157

@@ -497,6 +503,20 @@ Return true if <code>addr</code> is either the VM address or an Aptos Framework
497503
</code></pre>
498504

499505

506+
Specifies that a function aborts if the account does not have the root address.
507+
508+
509+
<a id="0x1_system_addresses_AbortsIfNotCoreResource"></a>
510+
511+
512+
<pre><code><b>schema</b> <a href="system_addresses.md#0x1_system_addresses_AbortsIfNotCoreResource">AbortsIfNotCoreResource</a> {
513+
addr: <b>address</b>;
514+
// This enforces <a id="high-level-req-1" href="#high-level-req">high-level requirement 1</a>:
515+
<b>aborts_if</b> addr != @core_resources <b>with</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_PERMISSION_DENIED">error::PERMISSION_DENIED</a>;
516+
}
517+
</code></pre>
518+
519+
500520

501521
<a id="@Specification_1_assert_aptos_framework"></a>
502522

@@ -546,20 +566,6 @@ Return true if <code>addr</code> is either the VM address or an Aptos Framework
546566
</code></pre>
547567

548568

549-
Specifies that a function aborts if the account does not have the aptos framework address.
550-
551-
552-
<a id="0x1_system_addresses_AbortsIfNotAptosFramework"></a>
553-
554-
555-
<pre><code><b>schema</b> <a href="system_addresses.md#0x1_system_addresses_AbortsIfNotAptosFramework">AbortsIfNotAptosFramework</a> {
556-
<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
557-
// This enforces <a id="high-level-req-2" href="#high-level-req">high-level requirement 2</a>:
558-
<b>aborts_if</b> <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="account.md#0x1_account">account</a>) != @aptos_framework <b>with</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_PERMISSION_DENIED">error::PERMISSION_DENIED</a>;
559-
}
560-
</code></pre>
561-
562-
563569

564570
<a id="@Specification_1_assert_vm"></a>
565571

@@ -577,18 +583,4 @@ Specifies that a function aborts if the account does not have the aptos framewor
577583
</code></pre>
578584

579585

580-
Specifies that a function aborts if the account does not have the VM reserved address.
581-
582-
583-
<a id="0x1_system_addresses_AbortsIfNotVM"></a>
584-
585-
586-
<pre><code><b>schema</b> <a href="system_addresses.md#0x1_system_addresses_AbortsIfNotVM">AbortsIfNotVM</a> {
587-
<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
588-
// This enforces <a id="high-level-req-3" href="#high-level-req">high-level requirement 3</a>:
589-
<b>aborts_if</b> <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="account.md#0x1_account">account</a>) != @vm_reserved <b>with</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_PERMISSION_DENIED">error::PERMISSION_DENIED</a>;
590-
}
591-
</code></pre>
592-
593-
594586
[move-book]: https://aptos.dev/move/book/SUMMARY

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ module aptos_framework::account {
129129
/// authentication keys. Without such separation, an adversary could create (and get a signer for) a resource account
130130
/// whose address matches an existing address of a MultiEd25519 wallet.
131131
const DERIVE_RESOURCE_ACCOUNT_SCHEME: u8 = 255;
132-
133132
/// Account already exists
134133
const EACCOUNT_ALREADY_EXISTS: u64 = 1;
135134
/// Account does not exist
@@ -170,6 +169,8 @@ module aptos_framework::account {
170169
const ENO_SIGNER_CAPABILITY_OFFERED: u64 = 19;
171170
// This account has exceeded the allocated GUIDs it can create. It should be impossible to reach this number for real applications.
172171
const EEXCEEDED_MAX_GUID_CREATION_NUM: u64 = 20;
172+
// A required feature flag is not enabled.
173+
const EFLAG_NOT_ENABLED: u64 = 21;
173174

174175
/// Explicitly separate the GUID space between Object and Account to prevent accidental overlap.
175176
const MAX_GUID_CREATION_NUM: u64 = 0x4000000000000;

aptos-move/framework/aptos-framework/sources/aptos_coin.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ module aptos_framework::aptos_coin {
214214
(burn_cap, mint_cap)
215215
}
216216

217-
/// Initializes the Delegations resource under `@aptos_framework`.
218217
#[test_only]
218+
/// Initializes the Delegations resource under `@aptos_framework`.
219219
public entry fun init_delegations(framework_signer: &signer) {
220220
// Ensure the delegations resource does not already exist
221221
if (!exists<Delegations>(@aptos_framework)) {

aptos-move/framework/aptos-framework/sources/system_addresses.move

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module aptos_framework::system_addresses {
22
use std::error;
33
use std::signer;
4+
use std::features::get_decommission_core_resources_enabled;
5+
#[test_only]
6+
use std::features::change_feature_flags_for_testing;
47

58
/// The address/account did not correspond to the core resource address
69
const ENOT_CORE_RESOURCE_ADDRESS: u64 = 1;
@@ -20,7 +23,12 @@ module aptos_framework::system_addresses {
2023
}
2124

2225
public fun is_core_resource_address(addr: address): bool {
23-
addr == @core_resources
26+
// Check if the feature flag for decommissioning core resources is enabled.
27+
if (get_decommission_core_resources_enabled()) {
28+
false
29+
} else {
30+
addr == @core_resources
31+
}
2432
}
2533

2634
public fun assert_aptos_framework(account: &signer) {
@@ -79,4 +87,22 @@ module aptos_framework::system_addresses {
7987
public fun is_reserved_address(addr: address): bool {
8088
is_aptos_framework_address(addr) || is_vm_address(addr)
8189
}
90+
91+
#[test(aptos_framework = @0x1, core_resources = @0xA550C18)]
92+
public entry fun test_core_resource_check_returns_false_with_flag_enabled(aptos_framework: signer, core_resources: address) {
93+
// Enable the feature flag for testing
94+
change_feature_flags_for_testing(&aptos_framework, vector[222], vector[]);
95+
96+
// Assert that is_core_resource_address returns false
97+
assert!(!is_core_resource_address(core_resources), 0);
98+
}
99+
100+
#[test(aptos_framework = @0x1, core_resources = @0xA550C18)]
101+
public entry fun test_core_resource_check_returns_true_without_flag(aptos_framework: signer, core_resources: address) {
102+
// Disable the feature flag for testing
103+
change_feature_flags_for_testing(&aptos_framework, vector[], vector[222]);
104+
105+
// Assert that is_core_resource_address returns true
106+
assert!(is_core_resource_address(core_resources), 0);
107+
}
82108
}

aptos-move/framework/move-stdlib/doc/features.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ return true.
135135
- [Function `abort_native_bridge_enabled`](#0x1_features_abort_native_bridge_enabled)
136136
- [Function `get_governed_gas_pool_feature`](#0x1_features_get_governed_gas_pool_feature)
137137
- [Function `governed_gas_pool_enabled`](#0x1_features_governed_gas_pool_enabled)
138+
- [Function `get_decommission_core_resources_feature`](#0x1_features_get_decommission_core_resources_feature)
139+
- [Function `get_decommission_core_resources_enabled`](#0x1_features_get_decommission_core_resources_enabled)
138140
- [Function `change_feature_flags`](#0x1_features_change_feature_flags)
139141
- [Function `change_feature_flags_internal`](#0x1_features_change_feature_flags_internal)
140142
- [Function `change_feature_flags_for_next_epoch`](#0x1_features_change_feature_flags_for_next_epoch)
@@ -427,6 +429,16 @@ Lifetime: transient
427429

428430

429431

432+
<a id="0x1_features_DECOMMISSION_CORE_RESOURCES"></a>
433+
434+
Lifetime: transient
435+
436+
437+
<pre><code><b>const</b> <a href="features.md#0x1_features_DECOMMISSION_CORE_RESOURCES">DECOMMISSION_CORE_RESOURCES</a>: u64 = 222;
438+
</code></pre>
439+
440+
441+
430442
<a id="0x1_features_DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE"></a>
431443

432444
Whether to default new Fungible Store to the concurrent variant.
@@ -3331,6 +3343,52 @@ Whether the Governed Gas Pool is enabled.
33313343

33323344

33333345

3346+
</details>
3347+
3348+
<a id="0x1_features_get_decommission_core_resources_feature"></a>
3349+
3350+
## Function `get_decommission_core_resources_feature`
3351+
3352+
3353+
3354+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_decommission_core_resources_feature">get_decommission_core_resources_feature</a>(): u64
3355+
</code></pre>
3356+
3357+
3358+
3359+
<details>
3360+
<summary>Implementation</summary>
3361+
3362+
3363+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_decommission_core_resources_feature">get_decommission_core_resources_feature</a>(): u64 { <a href="features.md#0x1_features_DECOMMISSION_CORE_RESOURCES">DECOMMISSION_CORE_RESOURCES</a> }
3364+
</code></pre>
3365+
3366+
3367+
3368+
</details>
3369+
3370+
<a id="0x1_features_get_decommission_core_resources_enabled"></a>
3371+
3372+
## Function `get_decommission_core_resources_enabled`
3373+
3374+
3375+
3376+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_decommission_core_resources_enabled">get_decommission_core_resources_enabled</a>(): bool
3377+
</code></pre>
3378+
3379+
3380+
3381+
<details>
3382+
<summary>Implementation</summary>
3383+
3384+
3385+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_decommission_core_resources_enabled">get_decommission_core_resources_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
3386+
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_DECOMMISSION_CORE_RESOURCES">DECOMMISSION_CORE_RESOURCES</a>)
3387+
}
3388+
</code></pre>
3389+
3390+
3391+
33343392
</details>
33353393

33363394
<a id="0x1_features_change_feature_flags"></a>

aptos-move/framework/move-stdlib/sources/configs/features.move

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,15 @@ module std::features {
615615
is_enabled(GOVERNED_GAS_POOL)
616616
}
617617

618+
/// Lifetime: transient
619+
const DECOMMISSION_CORE_RESOURCES: u64 = 222;
620+
621+
public fun get_decommission_core_resources_feature(): u64 { DECOMMISSION_CORE_RESOURCES }
622+
623+
public fun get_decommission_core_resources_enabled(): bool acquires Features {
624+
is_enabled(DECOMMISSION_CORE_RESOURCES)
625+
}
626+
618627
// ============================================================================================
619628
// Feature Flag Implementation
620629

types/src/on_chain_config/aptos_features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub enum FeatureFlag {
8787
LIMIT_VM_TYPE_SIZE = 69,
8888
ABORT_IF_MULTISIG_PAYLOAD_MISMATCH = 70,
8989
GOVERNED_GAS_POOL = 73,
90+
DECOMMISSION_CORE_RESOURCES = 222,
9091
}
9192

9293
impl FeatureFlag {

0 commit comments

Comments
 (0)