Skip to content

Commit

Permalink
added new field on ValidatoConfig in stake.move to have bls key
Browse files Browse the repository at this point in the history
  • Loading branch information
naitik-supraoracles committed Jan 7, 2025
1 parent 1fb062c commit 3bf72f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions aptos-move/framework/supra-framework/sources/stake.move
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ module supra_framework::stake {
/// Validator info stored in validator address.
struct ValidatorConfig has key, copy, store, drop {
consensus_pubkey: vector<u8>,
consensus_bls_pubkey: vector<u8>,
network_addresses: vector<u8>,
// to make it compatible with previous definition, remove later
fullnode_addresses: vector<u8>,
Expand Down Expand Up @@ -561,6 +562,7 @@ module supra_framework::stake {
initialize_owner(owner);
move_to(owner, ValidatorConfig {
consensus_pubkey: vector::empty(),
consensus_bls_pubkey: vector::empty(),
network_addresses: vector::empty(),
fullnode_addresses: vector::empty(),
validator_index: 0,
Expand All @@ -583,16 +585,18 @@ module supra_framework::stake {
public entry fun initialize_validator(
account: &signer,
consensus_pubkey: vector<u8>,
consensus_bls_pubkey: vector<u8>,
network_addresses: vector<u8>,
fullnode_addresses: vector<u8>,
) acquires AllowedValidators {
// Checks the public key is valid to prevent rogue-key attacks.
let valid_public_key = ed25519::new_validated_public_key_from_bytes(consensus_pubkey);
assert!(option::is_some(&valid_public_key), error::invalid_argument(EINVALID_PUBLIC_KEY));

//DO WE HAVE TO ADD CHECK FOR BLS KEY TOO? I AM NOT SURE.
initialize_owner(account);
move_to(account, ValidatorConfig {
consensus_pubkey,
consensus_bls_pubkey,
network_addresses,
fullnode_addresses,
validator_index: 0,
Expand Down Expand Up @@ -1900,8 +1904,10 @@ module supra_framework::stake {
account::create_account_for_test(validator_address);
};

let bls_pk_bytes = vector[];

let pk_bytes = ed25519::unvalidated_public_key_to_bytes(public_key);
initialize_validator(validator, pk_bytes, vector::empty(), vector::empty());
initialize_validator(validator, pk_bytes, bls_pk_bytes,vector::empty(), vector::empty());

if (amount > 0) {
mint_and_add_stake(validator, amount);
Expand Down Expand Up @@ -1931,6 +1937,7 @@ module supra_framework::stake {
voting_power: 0,
config: ValidatorConfig {
consensus_pubkey: ed25519::unvalidated_public_key_to_bytes(pk),
consensus_bls_pubkey: vector[],
network_addresses: b"",
fullnode_addresses: b"",
validator_index: 0,
Expand Down
3 changes: 3 additions & 0 deletions aptos-move/framework/supra-framework/sources/stake.spec.move
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ spec supra_framework::stake {
spec initialize_validator(
account: &signer,
consensus_pubkey: vector<u8>,
consensus_bls_pubkey: vector<u8>,
network_addresses: vector<u8>,
fullnode_addresses: vector<u8>,
){
Expand All @@ -149,6 +150,7 @@ spec supra_framework::stake {
ensures global<OwnerCapability>(post_addr) == OwnerCapability { pool_address: post_addr };
ensures global<ValidatorConfig>(post_addr) == ValidatorConfig {
consensus_pubkey,
consensus_bls_pubkey,
network_addresses,
fullnode_addresses,
validator_index: 0,
Expand Down Expand Up @@ -717,6 +719,7 @@ spec supra_framework::stake {
let addr = signer::address_of(owner);
ensures global<ValidatorConfig>(addr) == ValidatorConfig {
consensus_pubkey: vector::empty(),
consensus_bls_pubkey: vector::empty(),
network_addresses: vector::empty(),
fullnode_addresses: vector::empty(),
validator_index: 0,
Expand Down
1 change: 1 addition & 0 deletions crates/aptos/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ impl CliCommand<TransactionSummary> for InitializeValidator {
self.txn_options
.submit_transaction(aptos_stdlib::stake_initialize_validator(
consensus_public_key.to_bytes().to_vec(),
vec![],
// BCS encode, so that we can hide the original type
bcs::to_bytes(&validator_network_addresses)?,
bcs::to_bytes(&full_node_network_addresses)?,
Expand Down

0 comments on commit 3bf72f9

Please sign in to comment.