Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
so-kkroy22 committed May 7, 2024
1 parent 4e532cd commit 3fefc82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 58 deletions.
33 changes: 4 additions & 29 deletions aptos-move/framework/aptos-framework/sources/stake.move
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,11 @@ module aptos_framework::stake {
);
}

fun rotate_consensus_key_internal(
/// Rotate the consensus key of the validator, it'll take effect in next epoch.
public entry fun rotate_consensus_key(
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
genesis: bool,
) acquires StakePool, ValidatorConfig {
assert_stake_pool_exists(pool_address);
let stake_pool = borrow_global_mut<StakePool>(pool_address);
Expand All @@ -698,13 +698,8 @@ module aptos_framework::stake {
let validator_info = borrow_global_mut<ValidatorConfig>(pool_address);
let old_consensus_pubkey = validator_info.consensus_pubkey;
// Checks the public key is valid to prevent rogue-key attacks.
if (!genesis) {
let validated_public_key = ed25519::new_validated_public_key_from_bytes(new_consensus_pubkey);
assert!(option::is_some(&validated_public_key), error::invalid_argument(EINVALID_PUBLIC_KEY));
} else {
let validated_public_key = ed25519::new_validated_public_key_from_bytes(new_consensus_pubkey);
assert!(option::is_some(&validated_public_key), error::invalid_argument(EINVALID_PUBLIC_KEY));
};
let validated_public_key = ed25519::new_validated_public_key_from_bytes(new_consensus_pubkey);
assert!(option::is_some(&validated_public_key), error::invalid_argument(EINVALID_PUBLIC_KEY));
validator_info.consensus_pubkey = new_consensus_pubkey;

event::emit_event(
Expand All @@ -717,26 +712,6 @@ module aptos_framework::stake {
);
}

/// Rotate the consensus key of the validator
/// does not verify proof of possession
/// only for genesis
public(friend) fun rotate_consensus_key_genesis(
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
) acquires StakePool, ValidatorConfig {
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, true);
}

/// Rotate the consensus key of the validator, it'll take effect in next epoch.
public entry fun rotate_consensus_key(
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
) acquires StakePool, ValidatorConfig {
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, false);
}

/// Update the network and full node addresses of the validator. This only takes effect in the next epoch.
public entry fun update_network_and_fullnode_addresses(
operator: &signer,
Expand Down
33 changes: 4 additions & 29 deletions aptos-move/framework/supra-framework/sources/stake.move
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,11 @@ module supra_framework::stake {
);
}

fun rotate_consensus_key_internal(
/// Rotate the consensus key of the validator, it'll take effect in next epoch.
public entry fun rotate_consensus_key(
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
genesis: bool,
) acquires StakePool, ValidatorConfig {
assert_stake_pool_exists(pool_address);
let stake_pool = borrow_global_mut<StakePool>(pool_address);
Expand All @@ -699,13 +699,8 @@ module supra_framework::stake {
let validator_info = borrow_global_mut<ValidatorConfig>(pool_address);
let old_consensus_pubkey = validator_info.consensus_pubkey;
// Checks the public key is valid to prevent rogue-key attacks.
if (!genesis) {
let validated_public_key = ed25519::new_validated_public_key_from_bytes(new_consensus_pubkey);
assert!(option::is_some(&validated_public_key), error::invalid_argument(EINVALID_PUBLIC_KEY));
} else {
let validated_public_key = ed25519::new_validated_public_key_from_bytes(new_consensus_pubkey);
assert!(option::is_some(&validated_public_key), error::invalid_argument(EINVALID_PUBLIC_KEY));
};
let validated_public_key = ed25519::new_validated_public_key_from_bytes(new_consensus_pubkey);
assert!(option::is_some(&validated_public_key), error::invalid_argument(EINVALID_PUBLIC_KEY));
validator_info.consensus_pubkey = new_consensus_pubkey;

event::emit_event(
Expand All @@ -718,26 +713,6 @@ module supra_framework::stake {
);
}

/// Rotate the consensus key of the validator
/// does not verify proof of possession
/// only for genesis
public(friend) fun rotate_consensus_key_genesis(
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
) acquires StakePool, ValidatorConfig {
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, true);
}

/// Rotate the consensus key of the validator, it'll take effect in next epoch.
public entry fun rotate_consensus_key(
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
) acquires StakePool, ValidatorConfig {
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, false);
}

/// Update the network and full node addresses of the validator. This only takes effect in the next epoch.
public entry fun update_network_and_fullnode_addresses(
operator: &signer,
Expand Down

0 comments on commit 3fefc82

Please sign in to comment.