From 30ba5fd14436866b63b019298589b1152283cdca Mon Sep 17 00:00:00 2001 From: so-kkroy22 Date: Sun, 5 May 2024 01:53:17 +0530 Subject: [PATCH] added --- aptos-move/aptos-vm/src/natives.rs | 6 +- aptos-move/e2e-move-tests/src/stake.rs | 8 +- aptos-move/e2e-move-tests/src/tests/gas.rs | 8 +- .../framework/aptos-framework/doc/stake.md | 108 +++++------------- aptos-move/vm-genesis/src/lib.rs | 2 +- consensus/safety-rules/src/fuzzing_utils.rs | 10 +- consensus/src/metrics_safety_rules.rs | 8 +- crates/aptos-genesis/src/keys.rs | 2 +- crates/aptos-keygen/src/lib.rs | 2 +- crates/aptos/src/op/key.rs | 2 +- 10 files changed, 46 insertions(+), 110 deletions(-) diff --git a/aptos-move/aptos-vm/src/natives.rs b/aptos-move/aptos-vm/src/natives.rs index 1ff10bb7da49b8..5073ffa4cebd23 100644 --- a/aptos-move/aptos-vm/src/natives.rs +++ b/aptos-move/aptos-vm/src/natives.rs @@ -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") diff --git a/aptos-move/e2e-move-tests/src/stake.rs b/aptos-move/e2e-move-tests/src/stake.rs index 566e94023ad49c..7fa75d119c3fcf 100644 --- a/aptos-move/e2e-move-tests/src/stake.rs +++ b/aptos-move/e2e-move-tests/src/stake.rs @@ -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, @@ -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, ), ) } diff --git a/aptos-move/e2e-move-tests/src/tests/gas.rs b/aptos-move/e2e-move-tests/src/tests/gas.rs index 3b542a2614c97a..2a90476e761e31 100644 --- a/aptos-move/e2e-move-tests/src/tests/gas.rs +++ b/aptos-move/e2e-move-tests/src/tests/gas.rs @@ -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}, @@ -145,11 +145,8 @@ 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", @@ -157,7 +154,6 @@ fn test_gas() { aptos_stdlib::stake_rotate_consensus_key( pool_address, consensus_pubkey, - proof_of_possession, ), ); run( diff --git a/aptos-move/framework/aptos-framework/doc/stake.md b/aptos-move/framework/aptos-framework/doc/stake.md index 46e6e104393e1d..3152a55531eb36 100644 --- a/aptos-move/framework/aptos-framework/doc/stake.md +++ b/aptos-move/framework/aptos-framework/doc/stake.md @@ -150,7 +150,6 @@ or if their stake drops below the min required, they would get removed at the en
use 0x1::account;
 use 0x1::aptos_coin;
 use 0x1::coin;
-use 0x1::ed25519;
 use 0x1::error;
 use 0x1::event;
 use 0x1::features;
@@ -1975,11 +1974,6 @@ Initialize the validator account and give ownership to the signing account.
     fullnode_addresses: vector<u8>,
 ) acquires AllowedValidators {
     // Checks the public key has a valid proof-of-possession to prevent rogue-key attacks.
-    let pubkey_from_pop = &mut ed25519::new_validated_public_key_from_bytes(
-        consensus_pubkey,
-    );
-    assert!(option::is_some(pubkey_from_pop), error::invalid_argument(EINVALID_PUBLIC_KEY));
-
     initialize_owner(account);
     move_to(account, ValidatorConfig {
         consensus_pubkey,
@@ -2438,12 +2432,6 @@ Move amount of coins from pending_inactive to active.
     let validator_info = borrow_global_mut<ValidatorConfig>(pool_address);
     let old_consensus_pubkey = validator_info.consensus_pubkey;
     // Checks the public key has a valid proof-of-possession to prevent rogue-key attacks.
-    if (!genesis) {
-
-    } else {
-        let pubkey = &mut ed25519::new_validated_public_key_from_bytes(new_consensus_pubkey);
-        assert!(option::is_some(pubkey), error::invalid_argument(EINVALID_PUBLIC_KEY));
-    };
     validator_info.consensus_pubkey = new_consensus_pubkey;
 
     event::emit_event(
@@ -4582,6 +4570,32 @@ Returns validator's next epoch voting power, including pending_active, active, a
 
 
 
+
+
+
+
+
schema DistributeRewardsAbortsIf {
+    stake: Coin<AptosCoin>;
+    num_successful_proposals: num;
+    num_total_proposals: num;
+    rewards_rate: num;
+    rewards_rate_denominator: num;
+    let stake_amount = coin::value(stake);
+    let rewards_amount = if (stake_amount > 0) {
+        spec_rewards_amount(stake_amount, num_successful_proposals, num_total_proposals, rewards_rate, rewards_rate_denominator)
+    } else {
+        0
+    };
+    let amount = rewards_amount;
+    let addr = type_info::type_of<AptosCoin>().account_address;
+    aborts_if (rewards_amount > 0) && !exists<coin::CoinInfo<AptosCoin>>(addr);
+    modifies global<coin::CoinInfo<AptosCoin>>(addr);
+    include (rewards_amount > 0) ==> coin::CoinAddAbortsIf<AptosCoin> { amount: amount };
+}
+
+ + + ### Function `append` @@ -4885,74 +4899,4 @@ Returns validator's next epoch voting power, including pending_active, active, a
- - - - - -
schema ResourceRequirement {
-    requires exists<AptosCoinCapabilities>(@aptos_framework);
-    requires exists<ValidatorPerformance>(@aptos_framework);
-    requires exists<ValidatorSet>(@aptos_framework);
-    requires exists<StakingConfig>(@aptos_framework);
-    requires exists<StakingRewardsConfig>(@aptos_framework) || !features::spec_periodical_reward_rate_decrease_enabled();
-    requires exists<timestamp::CurrentTimeMicroseconds>(@aptos_framework);
-    requires exists<ValidatorFees>(@aptos_framework);
-}
-
- - - - - - - -
fun spec_get_reward_rate_1(config: StakingConfig): num {
-   if (features::spec_periodical_reward_rate_decrease_enabled()) {
-       let epoch_rewards_rate = global<staking_config::StakingRewardsConfig>(@aptos_framework).rewards_rate;
-       if (epoch_rewards_rate.value == 0) {
-           0
-       } else {
-           let denominator_0 = aptos_std::fixed_point64::spec_divide_u128(staking_config::MAX_REWARDS_RATE, epoch_rewards_rate);
-           let denominator = if (denominator_0 > MAX_U64) {
-               MAX_U64
-           } else {
-               denominator_0
-           };
-           let nominator = aptos_std::fixed_point64::spec_multiply_u128(denominator, epoch_rewards_rate);
-           nominator
-       }
-   } else {
-           config.rewards_rate
-   }
-}
-
- - - - - - - -
fun spec_get_reward_rate_2(config: StakingConfig): num {
-   if (features::spec_periodical_reward_rate_decrease_enabled()) {
-       let epoch_rewards_rate = global<staking_config::StakingRewardsConfig>(@aptos_framework).rewards_rate;
-       if (epoch_rewards_rate.value == 0) {
-           1
-       } else {
-           let denominator_0 = aptos_std::fixed_point64::spec_divide_u128(staking_config::MAX_REWARDS_RATE, epoch_rewards_rate);
-           let denominator = if (denominator_0 > MAX_U64) {
-               MAX_U64
-           } else {
-               denominator_0
-           };
-           denominator
-       }
-   } else {
-           config.rewards_rate_denominator
-   }
-}
-
- - [move-book]: https://aptos.dev/move/book/SUMMARY diff --git a/aptos-move/vm-genesis/src/lib.rs b/aptos-move/vm-genesis/src/lib.rs index 019096aa6420ef..175fc6294763e4 100644 --- a/aptos-move/vm-genesis/src/lib.rs +++ b/aptos-move/vm-genesis/src/lib.rs @@ -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, /// `NetworkAddress` for the validator. pub network_addresses: Vec, diff --git a/consensus/safety-rules/src/fuzzing_utils.rs b/consensus/safety-rules/src/fuzzing_utils.rs index c6e2b505571b8d..b3eec904e98bb9 100644 --- a/consensus/safety-rules/src/fuzzing_utils.rs +++ b/consensus/safety-rules/src/fuzzing_utils.rs @@ -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}, @@ -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 { @@ -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> { @@ -272,14 +272,14 @@ pub mod fuzzing { } } - pub fn fuzz_sign_proposal(block_data: &BlockData) -> Result { + pub fn fuzz_sign_proposal(block_data: &BlockData) -> Result { 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 { + ) -> Result { let mut safety_rules = test_utils::test_safety_rules(); safety_rules.sign_timeout_with_qc(&timeout, None) } diff --git a/consensus/src/metrics_safety_rules.rs b/consensus/src/metrics_safety_rules.rs index c7475a671f4aaf..7a0f54b90e5408 100644 --- a/consensus/src/metrics_safety_rules.rs +++ b/consensus/src/metrics_safety_rules.rs @@ -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, @@ -207,7 +207,7 @@ mod tests { self.last_init_result.clone() } - fn sign_proposal(&mut self, _: &BlockData) -> Result { + fn sign_proposal(&mut self, _: &BlockData) -> Result { unimplemented!() } @@ -215,7 +215,7 @@ mod tests { &mut self, _: &TwoChainTimeout, _: Option<&TwoChainTimeoutCertificate>, - ) -> Result { + ) -> Result { unimplemented!() } @@ -231,7 +231,7 @@ mod tests { &mut self, _: LedgerInfoWithSignatures, _: LedgerInfo, - ) -> Result { + ) -> Result { unimplemented!() } } diff --git a/crates/aptos-genesis/src/keys.rs b/crates/aptos-genesis/src/keys.rs index f2c848bcced95a..194a429ddbb6b7 100644 --- a/crates/aptos-genesis/src/keys.rs +++ b/crates/aptos-genesis/src/keys.rs @@ -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()?); diff --git a/crates/aptos-keygen/src/lib.rs b/crates/aptos-keygen/src/lib.rs index 8ed7881f92962b..274cede3994448 100644 --- a/crates/aptos-keygen/src/lib.rs +++ b/crates/aptos-keygen/src/lib.rs @@ -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}, diff --git a/crates/aptos/src/op/key.rs b/crates/aptos/src/op/key.rs index ae4e17c6cdcf2e..dc6ca0e61992ce 100644 --- a/crates/aptos/src/op/key.rs +++ b/crates/aptos/src/op/key.rs @@ -255,7 +255,7 @@ impl CliCommand> 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") }, }