Skip to content

Commit

Permalink
[Spec] Added specs for module gas_schedule & aptos_coin & chain_id & …
Browse files Browse the repository at this point in the history
…chain_status. (#5771)

* Updated the spec of gas_schedule

* add aptos_coin & chain_id & chain_status spec

* Generate spec doc

* Updated chain_status.spec.move

* Updated chain_status.spec.move

* Generate spec doc

Co-authored-by: yoyoping <[email protected]>
Co-authored-by: tiutiutiu <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2022
1 parent a2e4dc6 commit 8072655
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 10 deletions.
135 changes: 135 additions & 0 deletions aptos-move/framework/aptos-framework/doc/aptos_coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ modified from https://github.com/move-language/move/tree/main/language/documenta
- [Function `delegate_mint_capability`](#0x1_aptos_coin_delegate_mint_capability)
- [Function `claim_mint_capability`](#0x1_aptos_coin_claim_mint_capability)
- [Function `find_delegation`](#0x1_aptos_coin_find_delegation)
- [Specification](#@Specification_1)
- [Function `initialize`](#@Specification_1_initialize)
- [Function `destroy_mint_cap`](#@Specification_1_destroy_mint_cap)
- [Function `configure_accounts_for_test`](#@Specification_1_configure_accounts_for_test)
- [Function `mint`](#@Specification_1_mint)
- [Function `delegate_mint_capability`](#@Specification_1_delegate_mint_capability)
- [Function `claim_mint_capability`](#@Specification_1_claim_mint_capability)
- [Function `find_delegation`](#@Specification_1_find_delegation)


<pre><code><b>use</b> <a href="coin.md#0x1_coin">0x1::coin</a>;
Expand Down Expand Up @@ -454,5 +462,132 @@ Claim the delegated mint capability and destroy the delegated token.

</details>

<a name="@Specification_1"></a>

## Specification



<pre><code><b>pragma</b> verify = <b>true</b>;
<b>pragma</b> aborts_if_is_strict;
</code></pre>



<a name="@Specification_1_initialize"></a>

### Function `initialize`


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="aptos_coin.md#0x1_aptos_coin_initialize">initialize</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>): (<a href="coin.md#0x1_coin_BurnCapability">coin::BurnCapability</a>&lt;<a href="aptos_coin.md#0x1_aptos_coin_AptosCoin">aptos_coin::AptosCoin</a>&gt;, <a href="coin.md#0x1_coin_MintCapability">coin::MintCapability</a>&lt;<a href="aptos_coin.md#0x1_aptos_coin_AptosCoin">aptos_coin::AptosCoin</a>&gt;)
</code></pre>




<pre><code><b>pragma</b> aborts_if_is_partial;
<b>let</b> addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework);
<b>ensures</b> <b>exists</b>&lt;<a href="aptos_coin.md#0x1_aptos_coin_MintCapStore">MintCapStore</a>&gt;(addr);
<b>ensures</b> <b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">coin::CoinInfo</a>&lt;<a href="aptos_coin.md#0x1_aptos_coin_AptosCoin">AptosCoin</a>&gt;&gt;(addr);
</code></pre>



<a name="@Specification_1_destroy_mint_cap"></a>

### Function `destroy_mint_cap`


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="aptos_coin.md#0x1_aptos_coin_destroy_mint_cap">destroy_mint_cap</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
</code></pre>




<pre><code><b>let</b> addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework);
<b>aborts_if</b> addr != @aptos_framework;
<b>aborts_if</b> !<b>exists</b>&lt;<a href="aptos_coin.md#0x1_aptos_coin_MintCapStore">MintCapStore</a>&gt;(@aptos_framework);
</code></pre>



<a name="@Specification_1_configure_accounts_for_test"></a>

### Function `configure_accounts_for_test`


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="aptos_coin.md#0x1_aptos_coin_configure_accounts_for_test">configure_accounts_for_test</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, core_resources: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, mint_cap: <a href="coin.md#0x1_coin_MintCapability">coin::MintCapability</a>&lt;<a href="aptos_coin.md#0x1_aptos_coin_AptosCoin">aptos_coin::AptosCoin</a>&gt;)
</code></pre>




<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



<a name="@Specification_1_mint"></a>

### Function `mint`


<pre><code><b>public</b> entry <b>fun</b> <a href="aptos_coin.md#0x1_aptos_coin_mint">mint</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, dst_addr: <b>address</b>, amount: u64)
</code></pre>




<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



<a name="@Specification_1_delegate_mint_capability"></a>

### Function `delegate_mint_capability`


<pre><code><b>public</b> entry <b>fun</b> <a href="aptos_coin.md#0x1_aptos_coin_delegate_mint_capability">delegate_mint_capability</a>(<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, <b>to</b>: <b>address</b>)
</code></pre>




<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



<a name="@Specification_1_claim_mint_capability"></a>

### Function `claim_mint_capability`


<pre><code><b>public</b> entry <b>fun</b> <a href="aptos_coin.md#0x1_aptos_coin_claim_mint_capability">claim_mint_capability</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
</code></pre>




<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



<a name="@Specification_1_find_delegation"></a>

### Function `find_delegation`


<pre><code><b>fun</b> <a href="aptos_coin.md#0x1_aptos_coin_find_delegation">find_delegation</a>(addr: <b>address</b>): <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a>&lt;u64&gt;
</code></pre>




<pre><code><b>aborts_if</b> !<b>exists</b>&lt;<a href="aptos_coin.md#0x1_aptos_coin_Delegations">Delegations</a>&gt;(@core_resources);
</code></pre>


[move-book]: https://move-language.github.io/move/introduction.html
47 changes: 47 additions & 0 deletions aptos-move/framework/aptos-framework/doc/chain_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ This code provides a container for storing a chain id and functions to initializ
- [Resource `ChainId`](#0x1_chain_id_ChainId)
- [Function `initialize`](#0x1_chain_id_initialize)
- [Function `get`](#0x1_chain_id_get)
- [Specification](#@Specification_0)
- [Function `initialize`](#@Specification_0_initialize)
- [Function `get`](#@Specification_0_get)


<pre><code><b>use</b> <a href="system_addresses.md#0x1_system_addresses">0x1::system_addresses</a>;
Expand Down Expand Up @@ -97,5 +100,49 @@ Return the chain ID of this instance.

</details>

<a name="@Specification_0"></a>

## Specification



<pre><code><b>pragma</b> verify = <b>true</b>;
<b>pragma</b> aborts_if_is_strict;
</code></pre>



<a name="@Specification_0_initialize"></a>

### Function `initialize`


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="chain_id.md#0x1_chain_id_initialize">initialize</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, id: u8)
</code></pre>




<pre><code><b>let</b> addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework);
<b>aborts_if</b> addr != @aptos_framework;
<b>aborts_if</b> <b>exists</b>&lt;<a href="chain_id.md#0x1_chain_id_ChainId">ChainId</a>&gt;(@aptos_framework);
</code></pre>



<a name="@Specification_0_get"></a>

### Function `get`


<pre><code><b>public</b> <b>fun</b> <a href="chain_id.md#0x1_chain_id_get">get</a>(): u8
</code></pre>




<pre><code><b>aborts_if</b> !<b>exists</b>&lt;<a href="chain_id.md#0x1_chain_id_ChainId">ChainId</a>&gt;(@aptos_framework);
</code></pre>


[move-book]: https://move-language.github.io/move/introduction.html
41 changes: 41 additions & 0 deletions aptos-move/framework/aptos-framework/doc/chain_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ which reflect that the system has been successfully initialized.
- [Function `assert_genesis`](#0x1_chain_status_assert_genesis)
- [Specification](#@Specification_1)
- [Function `set_genesis_end`](#@Specification_1_set_genesis_end)
- [Function `assert_operating`](#@Specification_1_assert_operating)
- [Function `assert_genesis`](#@Specification_1_assert_genesis)


<pre><code><b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
Expand Down Expand Up @@ -212,6 +214,13 @@ Helper function to assert genesis state.
## Specification



<pre><code><b>pragma</b> verify = <b>true</b>;
<b>pragma</b> aborts_if_is_strict;
</code></pre>



<a name="@Specification_1_set_genesis_end"></a>

### Function `set_genesis_end`
Expand All @@ -238,4 +247,36 @@ Helper function to assert genesis state.
</code></pre>



<a name="@Specification_1_assert_operating"></a>

### Function `assert_operating`


<pre><code><b>public</b> <b>fun</b> <a href="chain_status.md#0x1_chain_status_assert_operating">assert_operating</a>()
</code></pre>




<pre><code><b>aborts_if</b> !<a href="chain_status.md#0x1_chain_status_is_operating">is_operating</a>();
</code></pre>



<a name="@Specification_1_assert_genesis"></a>

### Function `assert_genesis`


<pre><code><b>public</b> <b>fun</b> <a href="chain_status.md#0x1_chain_status_assert_genesis">assert_genesis</a>()
</code></pre>




<pre><code><b>aborts_if</b> !<a href="chain_status.md#0x1_chain_status_is_genesis">is_genesis</a>();
</code></pre>


[move-book]: https://move-language.github.io/move/introduction.html
37 changes: 35 additions & 2 deletions aptos-move/framework/aptos-framework/doc/gas_schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ it costs to execute Move on the network.
- [Function `set_gas_schedule`](#0x1_gas_schedule_set_gas_schedule)
- [Function `set_storage_gas_config`](#0x1_gas_schedule_set_storage_gas_config)
- [Specification](#@Specification_1)
- [Function `initialize`](#@Specification_1_initialize)
- [Function `set_gas_schedule`](#@Specification_1_set_gas_schedule)
- [Function `set_storage_gas_config`](#@Specification_1_set_storage_gas_config)

Expand Down Expand Up @@ -255,6 +256,32 @@ This can be called by on-chain governance to update the gas schedule.
## Specification



<pre><code><b>pragma</b> verify = <b>true</b>;
<b>pragma</b> aborts_if_is_strict;
</code></pre>



<a name="@Specification_1_initialize"></a>

### Function `initialize`


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="gas_schedule.md#0x1_gas_schedule_initialize">initialize</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, gas_schedule_blob: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;)
</code></pre>




<pre><code><b>include</b> <a href="system_addresses.md#0x1_system_addresses_AbortsIfNotAptosFramework">system_addresses::AbortsIfNotAptosFramework</a>{ <a href="account.md#0x1_account">account</a>: aptos_framework };
<b>aborts_if</b> len(gas_schedule_blob) == 0;
<b>aborts_if</b> <b>exists</b>&lt;<a href="gas_schedule.md#0x1_gas_schedule_GasScheduleV2">GasScheduleV2</a>&gt;(<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework));
<b>ensures</b> <b>exists</b>&lt;<a href="gas_schedule.md#0x1_gas_schedule_GasScheduleV2">GasScheduleV2</a>&gt;(<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework));
</code></pre>



<a name="@Specification_1_set_gas_schedule"></a>

### Function `set_gas_schedule`
Expand All @@ -266,7 +293,12 @@ This can be called by on-chain governance to update the gas schedule.



<pre><code><b>requires</b> <a href="chain_status.md#0x1_chain_status_is_operating">chain_status::is_operating</a>();
<pre><code><b>include</b> <a href="system_addresses.md#0x1_system_addresses_AbortsIfNotAptosFramework">system_addresses::AbortsIfNotAptosFramework</a>{ <a href="account.md#0x1_account">account</a>: aptos_framework };
<b>aborts_if</b> len(gas_schedule_blob) == 0;
<b>let</b> new_gas_schedule = <a href="util.md#0x1_util_spec_from_bytes">util::spec_from_bytes</a>&lt;<a href="gas_schedule.md#0x1_gas_schedule_GasScheduleV2">GasScheduleV2</a>&gt;(gas_schedule_blob);
<b>let</b> <a href="gas_schedule.md#0x1_gas_schedule">gas_schedule</a> = <b>global</b>&lt;<a href="gas_schedule.md#0x1_gas_schedule_GasScheduleV2">GasScheduleV2</a>&gt;(@aptos_framework);
<b>aborts_if</b> <b>exists</b>&lt;<a href="gas_schedule.md#0x1_gas_schedule_GasScheduleV2">GasScheduleV2</a>&gt;(@aptos_framework) && new_gas_schedule.feature_version &lt; <a href="gas_schedule.md#0x1_gas_schedule">gas_schedule</a>.feature_version;
<b>ensures</b> <b>exists</b>&lt;<a href="gas_schedule.md#0x1_gas_schedule_GasScheduleV2">GasScheduleV2</a>&gt;(<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework));
</code></pre>


Expand All @@ -282,7 +314,8 @@ This can be called by on-chain governance to update the gas schedule.



<pre><code><b>requires</b> <a href="chain_status.md#0x1_chain_status_is_operating">chain_status::is_operating</a>();
<pre><code><b>include</b> <a href="system_addresses.md#0x1_system_addresses_AbortsIfNotAptosFramework">system_addresses::AbortsIfNotAptosFramework</a>{ <a href="account.md#0x1_account">account</a>: aptos_framework };
<b>aborts_if</b> !<b>exists</b>&lt;StorageGasConfig&gt;(@aptos_framework);
</code></pre>


Expand Down
11 changes: 11 additions & 0 deletions aptos-move/framework/aptos-framework/doc/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ owned.


<pre><code><b>pragma</b> opaque;
<b>aborts_if</b> [abstract] <b>false</b>;
<b>ensures</b> [abstract] result == <a href="util.md#0x1_util_spec_from_bytes">spec_from_bytes</a>&lt;T&gt;(bytes);
</code></pre>




<a name="0x1_util_spec_from_bytes"></a>


<pre><code><b>fun</b> <a href="util.md#0x1_util_spec_from_bytes">spec_from_bytes</a>&lt;T&gt;(bytes: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;): T;
</code></pre>


Expand Down
43 changes: 43 additions & 0 deletions aptos-move/framework/aptos-framework/sources/aptos_coin.spec.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
spec aptos_framework::aptos_coin {
spec module {
pragma verify = true;
pragma aborts_if_is_strict;
}

spec initialize {
pragma aborts_if_is_partial;
let addr = signer::address_of(aptos_framework);
ensures exists<MintCapStore>(addr);
ensures exists<coin::CoinInfo<AptosCoin>>(addr);
}

spec destroy_mint_cap {
let addr = signer::address_of(aptos_framework);
aborts_if addr != @aptos_framework;
aborts_if !exists<MintCapStore>(@aptos_framework);
}

// Test function,not needed verify.
spec configure_accounts_for_test {
pragma verify = false;
}

// Only callable in tests and testnets.not needed verify.
spec mint {
pragma verify = false;
}

// Only callable in tests and testnets.not needed verify.
spec delegate_mint_capability {
pragma verify = false;
}

// Only callable in tests and testnets.not needed verify.
spec claim_mint_capability(account: &signer) {
pragma verify = false;
}

spec find_delegation(addr: address): Option<u64> {
aborts_if !exists<Delegations>(@core_resources);
}
}
Loading

0 comments on commit 8072655

Please sign in to comment.