Skip to content

Commit

Permalink
Add BLS12-381 test-only natives for signature generation (aptos-labs#…
Browse files Browse the repository at this point in the history
…5487)

* generate keys

* all functions

* fix

* delete struct_t stuff

* update

* update direct test cases

* warning

* update

* new hope

* 2 more test cases

* 4 more test cases

* more cases

* a lot of cases

* all test cases!

* rename

* even more test cases

* delete dead code

* update

* update

* update asserts

* rename vars

* update comments

* update generate_key comments

* update comments

* update comments

* bring back test_pubkey_validation

* merge 2 test_pubkey_validation cases

* keep old test names

* reorg src

* update

* maul functions

* fix warnings

* reorg

* test pop with invalid pk bytes

* hardcoding is back

* keep all hardcoded tests for safety

* indentation

* indentation

* misc

* indentation

* one less diff hunk

* unused

* better var name
  • Loading branch information
zjma authored Nov 18, 2022
1 parent 6405e50 commit 80ab25c
Show file tree
Hide file tree
Showing 13 changed files with 591 additions and 103 deletions.
8 changes: 7 additions & 1 deletion aptos-move/aptos-vm/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use aptos_gas::{AbstractValueSizeGasParameters, NativeGasParameters, LATEST_GAS_
use aptos_types::account_config::CORE_CODE_ADDRESS;
use move_vm_runtime::native_functions::NativeFunctionTable;

#[cfg(feature = "testing")]
use aptos_types::chain_id::ChainId;
#[cfg(feature = "testing")]
use {
Expand Down Expand Up @@ -68,7 +69,12 @@ pub fn assert_no_test_natives(err_msg: &str) {
|| module_name.as_str() == "ed25519" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "multi_ed25519"
&& func_name.as_str() == "generate_keys_internal"
|| module_name.as_str() == "multi_ed25519" && func_name.as_str() == "sign_internal")
|| module_name.as_str() == "multi_ed25519" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "bls12381"
&& func_name.as_str() == "generate_keys_internal"
|| module_name.as_str() == "bls12381" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "bls12381"
&& func_name.as_str() == "generate_proof_of_possession_internal")
}),
"{}",
err_msg
Expand Down
6 changes: 3 additions & 3 deletions aptos-move/framework/aptos-framework/doc/aptos_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,18 @@ The Account does not exist under the auth_key before creating the account.
Limit the address of auth_key is not @vm_reserved / @aptos_framework / @aptos_toke.


<pre><code><b>include</b> <a href="aptos_account.md#0x1_aptos_account_Create_account">Create_account</a>;
<pre><code><b>include</b> <a href="aptos_account.md#0x1_aptos_account_CreateAccount">CreateAccount</a>;
<b>ensures</b> <b>exists</b>&lt;<a href="account.md#0x1_account_Account">account::Account</a>&gt;(auth_key);
<b>ensures</b> <b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinStore">coin::CoinStore</a>&lt;AptosCoin&gt;&gt;(auth_key);
</code></pre>




<a name="0x1_aptos_account_Create_account"></a>
<a name="0x1_aptos_account_CreateAccount"></a>


<pre><code><b>schema</b> <a href="aptos_account.md#0x1_aptos_account_Create_account">Create_account</a> {
<pre><code><b>schema</b> <a href="aptos_account.md#0x1_aptos_account_CreateAccount">CreateAccount</a> {
auth_key: <b>address</b>;
<b>aborts_if</b> <b>exists</b>&lt;<a href="account.md#0x1_account_Account">account::Account</a>&gt;(auth_key);
<b>aborts_if</b> <a href="aptos_account.md#0x1_aptos_account_length_judgment">length_judgment</a>(auth_key);
Expand Down
21 changes: 11 additions & 10 deletions aptos-move/framework/aptos-framework/doc/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ The number of new events created does not exceed MAX_U64.


<pre><code><b>include</b> <a href="block.md#0x1_block_Initialize">Initialize</a>;
<b>include</b> <a href="block.md#0x1_block_New_event_handle">New_event_handle</a>;
<b>include</b> <a href="block.md#0x1_block_NewEventHandle">NewEventHandle</a>;
</code></pre>


Expand All @@ -597,10 +597,10 @@ The number of new events created does not exceed MAX_U64.



<a name="0x1_block_New_event_handle"></a>
<a name="0x1_block_NewEventHandle"></a>


<pre><code><b>schema</b> <a href="block.md#0x1_block_New_event_handle">New_event_handle</a> {
<pre><code><b>schema</b> <a href="block.md#0x1_block_NewEventHandle">NewEventHandle</a> {
aptos_framework: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
<b>let</b> addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework);
<b>let</b> <a href="account.md#0x1_account">account</a> = <b>global</b>&lt;<a href="account.md#0x1_account_Account">account::Account</a>&gt;(addr);
Expand All @@ -625,23 +625,24 @@ The new_epoch_interval must be greater than 0.
The BlockResource existed under the @aptos_framework.


<pre><code><b>include</b> <a href="block.md#0x1_block_Update_epoch_interval_microsecs">Update_epoch_interval_microsecs</a>;
<pre><code><b>include</b> <a href="block.md#0x1_block_UpdateEpochIntervalMicrosecs">UpdateEpochIntervalMicrosecs</a>;
</code></pre>




<a name="0x1_block_Update_epoch_interval_microsecs"></a>
<a name="0x1_block_UpdateEpochIntervalMicrosecs"></a>


<pre><code><b>schema</b> <a href="block.md#0x1_block_Update_epoch_interval_microsecs">Update_epoch_interval_microsecs</a> {
<pre><code><b>schema</b> <a href="block.md#0x1_block_UpdateEpochIntervalMicrosecs">UpdateEpochIntervalMicrosecs</a> {
aptos_framework: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
new_epoch_interval: u64;
<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> new_epoch_interval &lt;= 0;
<b>aborts_if</b> !<b>exists</b>&lt;<a href="block.md#0x1_block_BlockResource">BlockResource</a>&gt;(addr);
<b>ensures</b> <b>exists</b>&lt;<a href="block.md#0x1_block_BlockResource">BlockResource</a>&gt;(addr);
<b>let</b> <b>post</b> block_resource = <b>global</b>&lt;<a href="block.md#0x1_block_BlockResource">BlockResource</a>&gt;(addr);
<b>ensures</b> block_resource.epoch_interval == new_epoch_interval;
}
</code></pre>

Expand Down Expand Up @@ -759,16 +760,16 @@ The Configuration existed under the @aptos_framework.
The CurrentTimeMicroseconds existed under the @aptos_framework.


<pre><code><b>include</b> <a href="block.md#0x1_block_Emit_writeset_block_event">Emit_writeset_block_event</a>;
<pre><code><b>include</b> <a href="block.md#0x1_block_EmitWritesetBlockEvent">EmitWritesetBlockEvent</a>;
</code></pre>




<a name="0x1_block_Emit_writeset_block_event"></a>
<a name="0x1_block_EmitWritesetBlockEvent"></a>


<pre><code><b>schema</b> <a href="block.md#0x1_block_Emit_writeset_block_event">Emit_writeset_block_event</a> {
<pre><code><b>schema</b> <a href="block.md#0x1_block_EmitWritesetBlockEvent">EmitWritesetBlockEvent</a> {
vm_signer: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
<b>let</b> addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(vm_signer);
<b>aborts_if</b> addr != @vm_reserved;
Expand Down
1 change: 0 additions & 1 deletion aptos-move/framework/aptos-framework/doc/state_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ aborts if StateStorageUsage already exists.


<pre><code><b>pragma</b> opaque;
<b>aborts_if</b> <b>false</b>;
</code></pre>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,11 @@ module aptos_framework::aptos_governance {
vector::push_back(&mut active_validators, signer::address_of(proposer));
vector::push_back(&mut active_validators, signer::address_of(yes_voter));
vector::push_back(&mut active_validators, signer::address_of(no_voter));
stake::create_validator_set(aptos_framework, active_validators);
let (_sk_1, pk_1, _pop_1) = stake::generate_identity();
let (_sk_2, pk_2, _pop_2) = stake::generate_identity();
let (_sk_3, pk_3, _pop_3) = stake::generate_identity();
let pks = vector[pk_1, pk_2, pk_3];
stake::create_validator_set(aptos_framework, active_validators, pks);

let (burn_cap, mint_cap) = aptos_coin::initialize_for_test(aptos_framework);
// Spread stake among active and pending_inactive because both need to be accounted for when computing voting
Expand Down
Loading

0 comments on commit 80ab25c

Please sign in to comment.