Skip to content

Commit 2c9dece

Browse files
authored
Refine Voting Error Codes (aptos-labs#15590)
This commit refines voting error codes by introducing more specific classifications: ENO_VOTING_POWER, EINSUFFICIENT_STAKE_LOCKUP, and EPROPOSAL_EXPIRED.
1 parent 554f302 commit 2c9dece

File tree

7 files changed

+289
-317
lines changed

7 files changed

+289
-317
lines changed

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

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ on a proposal multiple times as long as the total voting power of these votes do
3939
- [Function `get_required_proposer_stake`](#0x1_aptos_governance_get_required_proposer_stake)
4040
- [Function `has_entirely_voted`](#0x1_aptos_governance_has_entirely_voted)
4141
- [Function `get_remaining_voting_power`](#0x1_aptos_governance_get_remaining_voting_power)
42+
- [Function `assert_proposal_expiration`](#0x1_aptos_governance_assert_proposal_expiration)
4243
- [Function `create_proposal`](#0x1_aptos_governance_create_proposal)
4344
- [Function `create_proposal_v2`](#0x1_aptos_governance_create_proposal_v2)
4445
- [Function `create_proposal_v2_impl`](#0x1_aptos_governance_create_proposal_v2_impl)
@@ -74,6 +75,7 @@ on a proposal multiple times as long as the total voting power of these votes do
7475
- [Function `get_required_proposer_stake`](#@Specification_1_get_required_proposer_stake)
7576
- [Function `has_entirely_voted`](#@Specification_1_has_entirely_voted)
7677
- [Function `get_remaining_voting_power`](#@Specification_1_get_remaining_voting_power)
78+
- [Function `assert_proposal_expiration`](#@Specification_1_assert_proposal_expiration)
7779
- [Function `create_proposal`](#@Specification_1_create_proposal)
7880
- [Function `create_proposal_v2`](#@Specification_1_create_proposal_v2)
7981
- [Function `create_proposal_v2_impl`](#@Specification_1_create_proposal_v2_impl)
@@ -758,6 +760,16 @@ Partial voting feature hasn't been properly initialized.
758760

759761

760762

763+
<a id="0x1_aptos_governance_EPROPOSAL_EXPIRED"></a>
764+
765+
The proposal has expired.
766+
767+
768+
<pre><code><b>const</b> <a href="aptos_governance.md#0x1_aptos_governance_EPROPOSAL_EXPIRED">EPROPOSAL_EXPIRED</a>: u64 = 15;
769+
</code></pre>
770+
771+
772+
761773
<a id="0x1_aptos_governance_EPROPOSAL_NOT_RESOLVABLE_YET"></a>
762774

763775
Proposal is not ready to be resolved. Waiting on time or votes
@@ -1160,6 +1172,43 @@ Note: a stake pool's voting power on a proposal could increase over time(e.g. re
11601172

11611173

11621174

1175+
</details>
1176+
1177+
<a id="0x1_aptos_governance_assert_proposal_expiration"></a>
1178+
1179+
## Function `assert_proposal_expiration`
1180+
1181+
1182+
1183+
<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool: <b>address</b>, proposal_id: u64)
1184+
</code></pre>
1185+
1186+
1187+
1188+
<details>
1189+
<summary>Implementation</summary>
1190+
1191+
1192+
<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool: <b>address</b>, proposal_id: u64) {
1193+
<a href="aptos_governance.md#0x1_aptos_governance_assert_voting_initialization">assert_voting_initialization</a>();
1194+
<b>let</b> proposal_expiration = <a href="voting.md#0x1_voting_get_proposal_expiration_secs">voting::get_proposal_expiration_secs</a>&lt;GovernanceProposal&gt;(
1195+
@aptos_framework,
1196+
proposal_id
1197+
);
1198+
// The voter's <a href="stake.md#0x1_stake">stake</a> needs <b>to</b> be locked up at least <b>as</b> long <b>as</b> the proposal's expiration.
1199+
<b>assert</b>!(
1200+
proposal_expiration &lt;= <a href="stake.md#0x1_stake_get_lockup_secs">stake::get_lockup_secs</a>(stake_pool),
1201+
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_EINSUFFICIENT_STAKE_LOCKUP">EINSUFFICIENT_STAKE_LOCKUP</a>),
1202+
);
1203+
<b>assert</b>!(
1204+
<a href="timestamp.md#0x1_timestamp_now_seconds">timestamp::now_seconds</a>() &lt;= proposal_expiration,
1205+
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_EPROPOSAL_EXPIRED">EPROPOSAL_EXPIRED</a>),
1206+
);
1207+
}
1208+
</code></pre>
1209+
1210+
1211+
11631212
</details>
11641213

11651214
<a id="0x1_aptos_governance_create_proposal"></a>
@@ -1498,15 +1547,7 @@ cannot vote on the proposal even after partial governance voting is enabled.
14981547
<b>let</b> voter_address = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(voter);
14991548
<b>assert</b>!(<a href="stake.md#0x1_stake_get_delegated_voter">stake::get_delegated_voter</a>(stake_pool) == voter_address, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_ENOT_DELEGATED_VOTER">ENOT_DELEGATED_VOTER</a>));
15001549

1501-
// The voter's <a href="stake.md#0x1_stake">stake</a> needs <b>to</b> be locked up at least <b>as</b> long <b>as</b> the proposal's expiration.
1502-
<b>let</b> proposal_expiration = <a href="voting.md#0x1_voting_get_proposal_expiration_secs">voting::get_proposal_expiration_secs</a>&lt;GovernanceProposal&gt;(
1503-
@aptos_framework,
1504-
proposal_id
1505-
);
1506-
<b>assert</b>!(
1507-
<a href="stake.md#0x1_stake_get_lockup_secs">stake::get_lockup_secs</a>(stake_pool) &gt;= proposal_expiration,
1508-
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_EINSUFFICIENT_STAKE_LOCKUP">EINSUFFICIENT_STAKE_LOCKUP</a>),
1509-
);
1550+
<a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool, proposal_id);
15101551

15111552
// If a <a href="stake.md#0x1_stake">stake</a> pool <b>has</b> already voted on a proposal before partial governance <a href="voting.md#0x1_voting">voting</a> is enabled,
15121553
// `get_remaining_voting_power` returns 0.
@@ -2435,6 +2476,28 @@ Abort if structs have already been created.
24352476

24362477

24372478

2479+
<a id="@Specification_1_assert_proposal_expiration"></a>
2480+
2481+
### Function `assert_proposal_expiration`
2482+
2483+
2484+
<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool: <b>address</b>, proposal_id: u64)
2485+
</code></pre>
2486+
2487+
2488+
2489+
2490+
<pre><code><b>include</b> <a href="aptos_governance.md#0x1_aptos_governance_VotingInitializationAbortIfs">VotingInitializationAbortIfs</a>;
2491+
<b>include</b> <a href="voting.md#0x1_voting_AbortsIfNotContainProposalID">voting::AbortsIfNotContainProposalID</a>&lt;GovernanceProposal&gt;{voting_forum_address: @aptos_framework};
2492+
<b>let</b> proposal_expiration = <a href="voting.md#0x1_voting_spec_get_proposal_expiration_secs">voting::spec_get_proposal_expiration_secs</a>&lt;GovernanceProposal&gt;(@aptos_framework, proposal_id);
2493+
<b>aborts_if</b> !<a href="stake.md#0x1_stake_stake_pool_exists">stake::stake_pool_exists</a>(stake_pool);
2494+
<b>aborts_if</b> proposal_expiration &gt; <a href="stake.md#0x1_stake_spec_get_lockup_secs">stake::spec_get_lockup_secs</a>(stake_pool);
2495+
<b>aborts_if</b> !<b>exists</b>&lt;<a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">timestamp::CurrentTimeMicroseconds</a>&gt;(@aptos_framework);
2496+
<b>aborts_if</b> <a href="timestamp.md#0x1_timestamp_now_seconds">timestamp::now_seconds</a>() &gt; proposal_expiration;
2497+
</code></pre>
2498+
2499+
2500+
24382501
<a id="@Specification_1_create_proposal"></a>
24392502

24402503
### Function `create_proposal`

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,7 @@ Vote on a proposal with a voter's voting power. To successfully vote, the follow
29552955
<b>if</b> (voting_power &gt; remaining_voting_power) {
29562956
voting_power = remaining_voting_power;
29572957
};
2958+
<a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">aptos_governance::assert_proposal_expiration</a>(pool_address, proposal_id);
29582959
<b>assert</b>!(voting_power &gt; 0, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="delegation_pool.md#0x1_delegation_pool_ENO_VOTING_POWER">ENO_VOTING_POWER</a>));
29592960

29602961
<b>let</b> governance_records = <b>borrow_global_mut</b>&lt;<a href="delegation_pool.md#0x1_delegation_pool_GovernanceRecords">GovernanceRecords</a>&gt;(pool_address);

0 commit comments

Comments
 (0)