Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
so-kkroy22 committed May 4, 2024
1 parent f457172 commit 30ba5fd
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 110 deletions.
6 changes: 3 additions & 3 deletions aptos-move/aptos-vm/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ pub fn assert_no_test_natives(err_msg: &str) {
|| 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() == "bls12381"
|| module_name.as_str() == "ed25519"
&& func_name.as_str() == "generate_keys_internal"
|| module_name.as_str() == "bls12381" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "bls12381"
|| module_name.as_str() == "ed25519" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "ed25519"
&& func_name.as_str() == "generate_proof_of_possession_internal"
|| module_name.as_str() == "event"
&& func_name.as_str() == "emitted_events_internal")
Expand Down
8 changes: 2 additions & 6 deletions aptos-move/e2e-move-tests/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::harness::MoveHarness;
use aptos_cached_packages::aptos_stdlib;
use aptos_crypto::{bls12381, PrivateKey, Uniform};
use aptos_crypto::{ed25519, PrivateKey, Uniform};
use aptos_language_e2e_tests::account::Account;
use aptos_types::{
account_address::AccountAddress, account_config::CORE_CODE_ADDRESS,
Expand Down Expand Up @@ -76,17 +76,13 @@ pub fn rotate_consensus_key(
account: &Account,
pool_address: AccountAddress,
) -> TransactionStatus {
let consensus_key = bls12381::PrivateKey::generate_for_testing();
let consensus_key = ed25519::PrivateKey::generate_for_testing();
let consensus_pubkey = consensus_key.public_key().to_bytes().to_vec();
let proof_of_possession = bls12381::ProofOfPossession::create(&consensus_key)
.to_bytes()
.to_vec();
harness.run_transaction_payload(
account,
aptos_stdlib::stake_rotate_consensus_key(
pool_address,
consensus_pubkey,
proof_of_possession,
),
)
}
Expand Down
8 changes: 2 additions & 6 deletions aptos-move/e2e-move-tests/src/tests/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
MoveHarness,
};
use aptos_cached_packages::{aptos_stdlib, aptos_token_sdk_builder};
use aptos_crypto::{bls12381, PrivateKey, Uniform};
use aptos_crypto::{ed25519, PrivateKey, Uniform};
use aptos_gas_profiling::TransactionGasLog;
use aptos_types::{
account_address::{default_stake_pool_address, AccountAddress},
Expand Down Expand Up @@ -145,19 +145,15 @@ fn test_gas() {
),
);
let pool_address = default_stake_pool_address(account_1_address, account_2_address);
let consensus_key = bls12381::PrivateKey::generate_for_testing();
let consensus_key = ed25519::PrivateKey::generate_for_testing();
let consensus_pubkey = consensus_key.public_key().to_bytes().to_vec();
let proof_of_possession = bls12381::ProofOfPossession::create(&consensus_key)
.to_bytes()
.to_vec();
run(
&mut harness,
"RotateConsensusKey",
account_2,
aptos_stdlib::stake_rotate_consensus_key(
pool_address,
consensus_pubkey,
proof_of_possession,
),
);
run(
Expand Down
108 changes: 26 additions & 82 deletions aptos-move/framework/aptos-framework/doc/stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ or if their stake drops below the min required, they would get removed at the en
<pre><code><b>use</b> <a href="account.md#0x1_account">0x1::account</a>;
<b>use</b> <a href="aptos_coin.md#0x1_aptos_coin">0x1::aptos_coin</a>;
<b>use</b> <a href="coin.md#0x1_coin">0x1::coin</a>;
<b>use</b> <a href="../../aptos-stdlib/doc/ed25519.md#0x1_ed25519">0x1::ed25519</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
<b>use</b> <a href="event.md#0x1_event">0x1::event</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features">0x1::features</a>;
Expand Down Expand Up @@ -1975,11 +1974,6 @@ Initialize the validator account and give ownership to the signing account.
fullnode_addresses: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;,
) <b>acquires</b> <a href="stake.md#0x1_stake_AllowedValidators">AllowedValidators</a> {
// Checks the <b>public</b> key <b>has</b> a valid proof-of-possession <b>to</b> prevent rogue-key attacks.
<b>let</b> pubkey_from_pop = &<b>mut</b> <a href="../../aptos-stdlib/doc/ed25519.md#0x1_ed25519_new_validated_public_key_from_bytes">ed25519::new_validated_public_key_from_bytes</a>(
consensus_pubkey,
);
<b>assert</b>!(<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(pubkey_from_pop), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="stake.md#0x1_stake_EINVALID_PUBLIC_KEY">EINVALID_PUBLIC_KEY</a>));

<a href="stake.md#0x1_stake_initialize_owner">initialize_owner</a>(<a href="account.md#0x1_account">account</a>);
<b>move_to</b>(<a href="account.md#0x1_account">account</a>, <a href="stake.md#0x1_stake_ValidatorConfig">ValidatorConfig</a> {
consensus_pubkey,
Expand Down Expand Up @@ -2438,12 +2432,6 @@ Move <code>amount</code> of coins from pending_inactive to active.
<b>let</b> validator_info = <b>borrow_global_mut</b>&lt;<a href="stake.md#0x1_stake_ValidatorConfig">ValidatorConfig</a>&gt;(pool_address);
<b>let</b> old_consensus_pubkey = validator_info.consensus_pubkey;
// Checks the <b>public</b> key <b>has</b> a valid proof-of-possession <b>to</b> prevent rogue-key attacks.
<b>if</b> (!<a href="genesis.md#0x1_genesis">genesis</a>) {

} <b>else</b> {
<b>let</b> pubkey = &<b>mut</b> <a href="../../aptos-stdlib/doc/ed25519.md#0x1_ed25519_new_validated_public_key_from_bytes">ed25519::new_validated_public_key_from_bytes</a>(new_consensus_pubkey);
<b>assert</b>!(<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(pubkey), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="stake.md#0x1_stake_EINVALID_PUBLIC_KEY">EINVALID_PUBLIC_KEY</a>));
};
validator_info.consensus_pubkey = new_consensus_pubkey;

<a href="event.md#0x1_event_emit_event">event::emit_event</a>(
Expand Down Expand Up @@ -4582,6 +4570,32 @@ Returns validator's next epoch voting power, including pending_active, active, a




<a id="0x1_stake_DistributeRewardsAbortsIf"></a>


<pre><code><b>schema</b> <a href="stake.md#0x1_stake_DistributeRewardsAbortsIf">DistributeRewardsAbortsIf</a> {
<a href="stake.md#0x1_stake">stake</a>: Coin&lt;AptosCoin&gt;;
num_successful_proposals: num;
num_total_proposals: num;
rewards_rate: num;
rewards_rate_denominator: num;
<b>let</b> stake_amount = <a href="coin.md#0x1_coin_value">coin::value</a>(<a href="stake.md#0x1_stake">stake</a>);
<b>let</b> rewards_amount = <b>if</b> (stake_amount &gt; 0) {
<a href="stake.md#0x1_stake_spec_rewards_amount">spec_rewards_amount</a>(stake_amount, num_successful_proposals, num_total_proposals, rewards_rate, rewards_rate_denominator)
} <b>else</b> {
0
};
<b>let</b> amount = rewards_amount;
<b>let</b> addr = <a href="../../aptos-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;AptosCoin&gt;().account_address;
<b>aborts_if</b> (rewards_amount &gt; 0) && !<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">coin::CoinInfo</a>&lt;AptosCoin&gt;&gt;(addr);
<b>modifies</b> <b>global</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">coin::CoinInfo</a>&lt;AptosCoin&gt;&gt;(addr);
<b>include</b> (rewards_amount &gt; 0) ==&gt; <a href="coin.md#0x1_coin_CoinAddAbortsIf">coin::CoinAddAbortsIf</a>&lt;AptosCoin&gt; { amount: amount };
}
</code></pre>



<a id="@Specification_1_append"></a>

### Function `append`
Expand Down Expand Up @@ -4885,74 +4899,4 @@ Returns validator's next epoch voting power, including pending_active, active, a
</code></pre>




<a id="0x1_stake_ResourceRequirement"></a>


<pre><code><b>schema</b> <a href="stake.md#0x1_stake_ResourceRequirement">ResourceRequirement</a> {
<b>requires</b> <b>exists</b>&lt;<a href="stake.md#0x1_stake_AptosCoinCapabilities">AptosCoinCapabilities</a>&gt;(@aptos_framework);
<b>requires</b> <b>exists</b>&lt;<a href="stake.md#0x1_stake_ValidatorPerformance">ValidatorPerformance</a>&gt;(@aptos_framework);
<b>requires</b> <b>exists</b>&lt;<a href="stake.md#0x1_stake_ValidatorSet">ValidatorSet</a>&gt;(@aptos_framework);
<b>requires</b> <b>exists</b>&lt;StakingConfig&gt;(@aptos_framework);
<b>requires</b> <b>exists</b>&lt;StakingRewardsConfig&gt;(@aptos_framework) || !<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_periodical_reward_rate_decrease_enabled">features::spec_periodical_reward_rate_decrease_enabled</a>();
<b>requires</b> <b>exists</b>&lt;<a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">timestamp::CurrentTimeMicroseconds</a>&gt;(@aptos_framework);
<b>requires</b> <b>exists</b>&lt;<a href="stake.md#0x1_stake_ValidatorFees">ValidatorFees</a>&gt;(@aptos_framework);
}
</code></pre>




<a id="0x1_stake_spec_get_reward_rate_1"></a>


<pre><code><b>fun</b> <a href="stake.md#0x1_stake_spec_get_reward_rate_1">spec_get_reward_rate_1</a>(config: StakingConfig): num {
<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_periodical_reward_rate_decrease_enabled">features::spec_periodical_reward_rate_decrease_enabled</a>()) {
<b>let</b> epoch_rewards_rate = <b>global</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">staking_config::StakingRewardsConfig</a>&gt;(@aptos_framework).rewards_rate;
<b>if</b> (epoch_rewards_rate.value == 0) {
0
} <b>else</b> {
<b>let</b> denominator_0 = aptos_std::fixed_point64::spec_divide_u128(<a href="staking_config.md#0x1_staking_config_MAX_REWARDS_RATE">staking_config::MAX_REWARDS_RATE</a>, epoch_rewards_rate);
<b>let</b> denominator = <b>if</b> (denominator_0 &gt; <a href="stake.md#0x1_stake_MAX_U64">MAX_U64</a>) {
<a href="stake.md#0x1_stake_MAX_U64">MAX_U64</a>
} <b>else</b> {
denominator_0
};
<b>let</b> nominator = aptos_std::fixed_point64::spec_multiply_u128(denominator, epoch_rewards_rate);
nominator
}
} <b>else</b> {
config.rewards_rate
}
}
</code></pre>




<a id="0x1_stake_spec_get_reward_rate_2"></a>


<pre><code><b>fun</b> <a href="stake.md#0x1_stake_spec_get_reward_rate_2">spec_get_reward_rate_2</a>(config: StakingConfig): num {
<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_periodical_reward_rate_decrease_enabled">features::spec_periodical_reward_rate_decrease_enabled</a>()) {
<b>let</b> epoch_rewards_rate = <b>global</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">staking_config::StakingRewardsConfig</a>&gt;(@aptos_framework).rewards_rate;
<b>if</b> (epoch_rewards_rate.value == 0) {
1
} <b>else</b> {
<b>let</b> denominator_0 = aptos_std::fixed_point64::spec_divide_u128(<a href="staking_config.md#0x1_staking_config_MAX_REWARDS_RATE">staking_config::MAX_REWARDS_RATE</a>, epoch_rewards_rate);
<b>let</b> denominator = <b>if</b> (denominator_0 &gt; <a href="stake.md#0x1_stake_MAX_U64">MAX_U64</a>) {
<a href="stake.md#0x1_stake_MAX_U64">MAX_U64</a>
} <b>else</b> {
denominator_0
};
denominator
}
} <b>else</b> {
config.rewards_rate_denominator
}
}
</code></pre>


[move-book]: https://aptos.dev/move/book/SUMMARY
2 changes: 1 addition & 1 deletion aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ pub struct Validator {
/// Amount to stake for consensus. Also the intial amount minted to the owner account.
pub stake_amount: u64,

/// bls12381 public key used to sign consensus messages.
/// ed25519 public key used to sign consensus messages.
pub consensus_pubkey: Vec<u8>,
/// `NetworkAddress` for the validator.
pub network_addresses: Vec<u8>,
Expand Down
10 changes: 5 additions & 5 deletions consensus/safety-rules/src/fuzzing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use aptos_consensus_types::{
vote_proposal::VoteProposal,
};
use aptos_crypto::{
bls12381,
ed25519,
hash::{HashValue, TransactionAccumulatorHasher},
test_utils::TEST_SEED,
traits::{SigningKey, Uniform},
Expand Down Expand Up @@ -68,7 +68,7 @@ prop_compose! {
) -> Block {
let signature = if include_signature {
let mut rng = StdRng::from_seed(TEST_SEED);
let private_key = bls12381::PrivateKey::generate(&mut rng);
let private_key = ed25519::PrivateKey::generate(&mut rng);
let signature = private_key.sign(&block_data).unwrap();
Some(signature)
} else {
Expand Down Expand Up @@ -243,7 +243,7 @@ pub mod fuzzing {
block_data::BlockData, timeout_2chain::TwoChainTimeout, vote::Vote,
vote_proposal::VoteProposal,
};
use aptos_crypto::bls12381;
use aptos_crypto::ed25519;
use aptos_types::epoch_change::EpochChangeProof;

pub fn fuzz_initialize(proof: EpochChangeProof) -> Result<(), Error> {
Expand Down Expand Up @@ -272,14 +272,14 @@ pub mod fuzzing {
}
}

pub fn fuzz_sign_proposal(block_data: &BlockData) -> Result<bls12381::Signature, Error> {
pub fn fuzz_sign_proposal(block_data: &BlockData) -> Result<ed25519::Signature, Error> {
let mut safety_rules = test_utils::test_safety_rules();
safety_rules.sign_proposal(block_data)
}

pub fn fuzz_sign_timeout_with_qc(
timeout: TwoChainTimeout,
) -> Result<bls12381::Signature, Error> {
) -> Result<ed25519::Signature, Error> {
let mut safety_rules = test_utils::test_safety_rules();
safety_rules.sign_timeout_with_qc(&timeout, None)
}
Expand Down
8 changes: 4 additions & 4 deletions consensus/src/metrics_safety_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
vote::Vote,
vote_proposal::VoteProposal,
};
use aptos_crypto::bls12381;
use aptos_crypto::ed25519;
use aptos_safety_rules::{ConsensusState, Error, TSafetyRules};
use aptos_types::{
epoch_change::EpochChangeProof,
Expand Down Expand Up @@ -207,15 +207,15 @@ mod tests {
self.last_init_result.clone()
}

fn sign_proposal(&mut self, _: &BlockData) -> Result<bls12381::Signature, Error> {
fn sign_proposal(&mut self, _: &BlockData) -> Result<ed25519::Signature, Error> {
unimplemented!()
}

fn sign_timeout_with_qc(
&mut self,
_: &TwoChainTimeout,
_: Option<&TwoChainTimeoutCertificate>,
) -> Result<bls12381::Signature, Error> {
) -> Result<ed25519::Signature, Error> {
unimplemented!()
}

Expand All @@ -231,7 +231,7 @@ mod tests {
&mut self,
_: LedgerInfoWithSignatures,
_: LedgerInfo,
) -> Result<bls12381::Signature, Error> {
) -> Result<ed25519::Signature, Error> {
unimplemented!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos-genesis/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn generate_key_objects(
keygen: &mut KeyGen,
) -> anyhow::Result<(IdentityBlob, IdentityBlob, PrivateIdentity, PublicIdentity)> {
let account_key = ConfigKey::new(keygen.generate_ed25519_private_key());
let consensus_key = ConfigKey::new(keygen.generate_bls12381_private_key());
let consensus_key = ConfigKey::new(keygen.generate_ed25519_private_key());
let validator_network_key = ConfigKey::new(keygen.generate_x25519_private_key()?);
let full_node_network_key = ConfigKey::new(keygen.generate_x25519_private_key()?);

Expand Down
2 changes: 1 addition & 1 deletion crates/aptos-keygen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use aptos_crypto::{ed25519::{self, Ed25519PrivateKey, Ed25519PublicKey}, x25519, CryptoMaterialError, PrivateKey, Uniform};
use aptos_crypto::{ed25519::{Ed25519PrivateKey, Ed25519PublicKey}, x25519, CryptoMaterialError, PrivateKey, Uniform};
use aptos_types::{account_address::AccountAddress, transaction::authenticator::AuthenticationKey};
use rand::{
rngs::{OsRng, StdRng},
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos/src/op/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl CliCommand<HashMap<&'static str, PathBuf>> for GenerateKey {
return Ok(result_map);
},
KeyType::Bls12381 => {
let private_key = keygen.generate_bls12381_private_key();
let private_key = keygen.generate_ed25519_private_key();
self.save_params.save_key(&private_key, "ed25519")
},
}
Expand Down

0 comments on commit 30ba5fd

Please sign in to comment.