Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix acount.txn_epilogue_v2 incompatible #168

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: BA11C8B16393EE8048481F812F0038A5D20D703FD7F7B2B9BD5F49840B6703E1
source_digest: F1E05061776D5ED1B4717B879662E684E66FDC81A2B9B99AAF4A964F4C42E335
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file modified build/StarcoinFramework/bytecode_modules/Account.mv
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/TransactionManager.mv
Binary file not shown.
102 changes: 82 additions & 20 deletions build/StarcoinFramework/docs/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The module for the account resource that governs every account
- [Function `txn_epilogue`](#0x1_Account_txn_epilogue)
- [Function `transaction_fee_simulate`](#0x1_Account_transaction_fee_simulate)
- [Function `txn_epilogue_v2`](#0x1_Account_txn_epilogue_v2)
- [Function `txn_epilogue_v3`](#0x1_Account_txn_epilogue_v3)
- [Function `remove_zero_balance_entry`](#0x1_Account_remove_zero_balance_entry)
- [Function `remove_zero_balance`](#0x1_Account_remove_zero_balance)
- [Function `make_event_store_if_not_exist`](#0x1_Account_make_event_store_if_not_exist)
Expand Down Expand Up @@ -3327,7 +3328,7 @@ It collects gas and bumps the sequence number
txn_max_gas_units: u64,
gas_units_remaining: u64,
) <b>acquires</b> <a href="Account.md#0x1_Account">Account</a>, <a href="Account.md#0x1_Account_Balance">Balance</a> {
<a href="Account.md#0x1_Account_txn_epilogue_v2">txn_epilogue_v2</a>&lt;TokenType&gt;(account, txn_sender, txn_sequence_number, <a href="Vector.md#0x1_Vector_empty">Vector::empty</a>(), txn_gas_price, txn_max_gas_units, gas_units_remaining,1,1)
<a href="Account.md#0x1_Account_txn_epilogue_v3">txn_epilogue_v3</a>&lt;TokenType&gt;(account, txn_sender, txn_sequence_number, <a href="Vector.md#0x1_Vector_empty">Vector::empty</a>(), txn_gas_price, txn_max_gas_units, gas_units_remaining,1,1)
}
</code></pre>

Expand Down Expand Up @@ -3388,7 +3389,7 @@ The epilogue is invoked at the end of transactions.
It collects gas and bumps the sequence number


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_txn_epilogue_v2">txn_epilogue_v2</a>&lt;TokenType: store&gt;(account: &signer, txn_sender: <b>address</b>, txn_sequence_number: u64, txn_authentication_key_preimage: vector&lt;u8&gt;, txn_gas_price: u64, txn_max_gas_units: u64, gas_units_remaining: u64, stc_price: u128, stc_price_scaling: u128)
<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_txn_epilogue_v2">txn_epilogue_v2</a>&lt;TokenType: store&gt;(account: &signer, txn_sender: <b>address</b>, txn_sequence_number: u64, txn_authentication_key_preimage: vector&lt;u8&gt;, txn_gas_price: u64, txn_max_gas_units: u64, gas_units_remaining: u64)
</code></pre>


Expand All @@ -3405,6 +3406,85 @@ It collects gas and bumps the sequence number
txn_gas_price: u64,
txn_max_gas_units: u64,
gas_units_remaining: u64,
) <b>acquires</b> <a href="Account.md#0x1_Account">Account</a>, <a href="Account.md#0x1_Account_Balance">Balance</a> {
<a href="Account.md#0x1_Account_txn_epilogue_v3">txn_epilogue_v3</a>&lt;TokenType&gt;(
account,
txn_sender,
txn_sequence_number,
txn_authentication_key_preimage,
txn_gas_price,
txn_max_gas_units,
gas_units_remaining,1,1)
}
</code></pre>



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
<b>aborts_if</b> <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account) != <a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>();
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account">Account</a>&gt;(txn_sender);
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(txn_sender);
<b>aborts_if</b> txn_max_gas_units &lt; gas_units_remaining;
<b>let</b> transaction_fee_amount = txn_gas_price * (txn_max_gas_units - gas_units_remaining);
<b>aborts_if</b> transaction_fee_amount &gt; max_u128();
<b>aborts_if</b> <b>global</b>&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(txn_sender).token.value &lt; transaction_fee_amount;
<b>aborts_if</b> txn_sequence_number + 1 &gt; max_u64();
<b>aborts_if</b> txn_gas_price * (txn_max_gas_units - gas_units_remaining) &gt; 0 &&
<b>global</b>&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(txn_sender).token.value &lt; txn_gas_price * (txn_max_gas_units - gas_units_remaining);
<b>aborts_if</b> txn_gas_price * (txn_max_gas_units - gas_units_remaining) &gt; 0 &&
!<b>exists</b>&lt;<a href="TransactionFee.md#0x1_TransactionFee_TransactionFee">TransactionFee::TransactionFee</a>&lt;TokenType&gt;&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>());
<b>aborts_if</b> txn_gas_price * (txn_max_gas_units - gas_units_remaining) &gt; 0 &&
<b>global</b>&lt;<a href="TransactionFee.md#0x1_TransactionFee_TransactionFee">TransactionFee::TransactionFee</a>&lt;TokenType&gt;&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>()).fee.value + txn_gas_price * (txn_max_gas_units - gas_units_remaining) &gt; max_u128();
</code></pre>




<pre><code><b>pragma</b> verify = <b>false</b>;
<b>aborts_if</b> <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account) != <a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>();
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account">Account</a>&gt;(txn_sender);
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(txn_sender);
<b>aborts_if</b> txn_sequence_number + 1 &gt; max_u64();
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(txn_sender);
<b>aborts_if</b> txn_max_gas_units &lt; gas_units_remaining;
</code></pre>



</details>

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

## Function `txn_epilogue_v3`

The epilogue is invoked at the end of transactions.
It collects gas and bumps the sequence number


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_txn_epilogue_v3">txn_epilogue_v3</a>&lt;TokenType: store&gt;(account: &signer, txn_sender: <b>address</b>, txn_sequence_number: u64, txn_authentication_key_preimage: vector&lt;u8&gt;, txn_gas_price: u64, txn_max_gas_units: u64, gas_units_remaining: u64, stc_price: u128, stc_price_scaling: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_txn_epilogue_v3">txn_epilogue_v3</a>&lt;TokenType: store&gt;(
account: &signer,
txn_sender: <b>address</b>,
txn_sequence_number: u64,
txn_authentication_key_preimage: vector&lt;u8&gt;,
txn_gas_price: u64,
txn_max_gas_units: u64,
gas_units_remaining: u64,
stc_price: u128,
stc_price_scaling: u128,
) <b>acquires</b> <a href="Account.md#0x1_Account">Account</a>, <a href="Account.md#0x1_Account_Balance">Balance</a> {
Expand Down Expand Up @@ -3448,24 +3528,6 @@ It collects gas and bumps the sequence number



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
<b>aborts_if</b> <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account) != <a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>();
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account">Account</a>&gt;(txn_sender);
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(txn_sender);
<b>aborts_if</b> txn_sequence_number + 1 &gt; max_u64();
<b>aborts_if</b> !<b>exists</b>&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(txn_sender);
<b>aborts_if</b> txn_max_gas_units &lt; gas_units_remaining;
</code></pre>



</details>

<a name="0x1_Account_remove_zero_balance_entry"></a>
Expand Down
2 changes: 1 addition & 1 deletion build/StarcoinFramework/docs/TransactionManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ It collects gas and bumps the sequence number
}<b>else</b>{
(1,1)
};
<a href="Account.md#0x1_Account_txn_epilogue_v2">Account::txn_epilogue_v2</a>&lt;TokenType&gt;(
<a href="Account.md#0x1_Account_txn_epilogue_v3">Account::txn_epilogue_v3</a>&lt;TokenType&gt;(
&account,
txn_sender,
txn_sequence_number,
Expand Down
Binary file modified build/StarcoinFramework/source_maps/Account.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/TransactionManager.mvsm
Binary file not shown.
2 changes: 1 addition & 1 deletion integration-tests/account/txn_prologue_and_epilogue.move
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ script {
);
// execute the txn...
let gas_units_remaining = 10;
Account::txn_epilogue_v2<DummyToken>(
Account::txn_epilogue_v3<DummyToken>(
&account,
txn_sender,
txn_sequence_number,
Expand Down
42 changes: 40 additions & 2 deletions sources/Account.move
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ module Account {
txn_max_gas_units: u64,
gas_units_remaining: u64,
) acquires Account, Balance {
txn_epilogue_v2<TokenType>(account, txn_sender, txn_sequence_number, Vector::empty(), txn_gas_price, txn_max_gas_units, gas_units_remaining,1,1)
txn_epilogue_v3<TokenType>(account, txn_sender, txn_sequence_number, Vector::empty(), txn_gas_price, txn_max_gas_units, gas_units_remaining,1,1)
}

spec txn_epilogue {
Expand All @@ -1102,7 +1102,6 @@ module Account {
transaction_fee_token = if (transaction_fee_token == 0 && transaction_fee_stc > 0 ) { 1 } else { transaction_fee_token};
(transaction_fee_stc, transaction_fee_token)
}

/// The epilogue is invoked at the end of transactions.
/// It collects gas and bumps the sequence number
public fun txn_epilogue_v2<TokenType: store>(
Expand All @@ -1113,6 +1112,45 @@ module Account {
txn_gas_price: u64,
txn_max_gas_units: u64,
gas_units_remaining: u64,
) acquires Account, Balance {
txn_epilogue_v3<TokenType>(
account,
txn_sender,
txn_sequence_number,
txn_authentication_key_preimage,
txn_gas_price,
txn_max_gas_units,
gas_units_remaining,1,1)
}

spec txn_epilogue_v2 {
pragma verify = false; // Todo: fix me, cost too much time
aborts_if Signer::address_of(account) != CoreAddresses::GENESIS_ADDRESS();
aborts_if !exists<Account>(txn_sender);
aborts_if !exists<Balance<TokenType>>(txn_sender);
aborts_if txn_max_gas_units < gas_units_remaining;
let transaction_fee_amount = txn_gas_price * (txn_max_gas_units - gas_units_remaining);
aborts_if transaction_fee_amount > max_u128();
aborts_if global<Balance<TokenType>>(txn_sender).token.value < transaction_fee_amount;
aborts_if txn_sequence_number + 1 > max_u64();
aborts_if txn_gas_price * (txn_max_gas_units - gas_units_remaining) > 0 &&
global<Balance<TokenType>>(txn_sender).token.value < txn_gas_price * (txn_max_gas_units - gas_units_remaining);
aborts_if txn_gas_price * (txn_max_gas_units - gas_units_remaining) > 0 &&
!exists<TransactionFee::TransactionFee<TokenType>>(CoreAddresses::GENESIS_ADDRESS());
aborts_if txn_gas_price * (txn_max_gas_units - gas_units_remaining) > 0 &&
global<TransactionFee::TransactionFee<TokenType>>(CoreAddresses::GENESIS_ADDRESS()).fee.value + txn_gas_price * (txn_max_gas_units - gas_units_remaining) > max_u128();
}

/// The epilogue is invoked at the end of transactions.
/// It collects gas and bumps the sequence number
public fun txn_epilogue_v3<TokenType: store>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可以改成 friend,以后就不用维护兼容性了。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以从 TransactionManager 的入口进入测试,那个方法是给 rust 调用的,必须保证兼容性。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样就需要把GasOracleProposal流程都走一遍才能测了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,也是个问题。那要不先保留着,后面看怎么重构:

  1. 把这个方法的测试改成 unit test,不过需要有一些初始化资源的步骤。
  2. 或者给 test 和 dev 环境提供特殊的合约方法,方便测试 gas token。

account: &signer,
txn_sender: address,
txn_sequence_number: u64,
txn_authentication_key_preimage: vector<u8>,
txn_gas_price: u64,
txn_max_gas_units: u64,
gas_units_remaining: u64,
stc_price: u128,
stc_price_scaling: u128,
) acquires Account, Balance {
Expand Down
2 changes: 1 addition & 1 deletion sources/TransactionManager.move
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ module TransactionManager {
}else{
(1,1)
};
Account::txn_epilogue_v2<TokenType>(
Account::txn_epilogue_v3<TokenType>(
&account,
txn_sender,
txn_sequence_number,
Expand Down