Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ aptos-cargo-cli = { path = "devtools/aptos-cargo-cli" }

# External crate dependencies.
# Please do not add any test features here: they should be declared by the individual crate.
blsttc = {package = "blsttc", git = "https://github.com/Entropy-Foundation/blsttc-supra.git", rev = "431f403dfd0d625515363711ee58dac84d0c1ebc"}
aes-gcm = "0.10.3"
ahash = "0.8.11"
atty = "0.2.14"
Expand Down Expand Up @@ -692,7 +693,7 @@ quote = "1.0.18"
rand = "0.7.3"
rand_core = "0.5.1"
random_word = "0.3.0"
rayon = "1.5.2"
rayon = "1.10.0"
redis = { version = "0.22.3", features = [
"tokio-comp",
"script",
Expand Down
4 changes: 4 additions & 0 deletions aptos-move/framework/supra-framework/sources/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module supra_framework::genesis {
voter_address: address,
stake_amount: u64,
consensus_pubkey: vector<u8>,
consensus_bls_pubkey: vector<u8>,
network_addresses: vector<u8>,
full_node_network_addresses: vector<u8>,
}
Expand Down Expand Up @@ -830,6 +831,7 @@ module supra_framework::genesis {
voter_address: @0x121343,
stake_amount: 0,
consensus_pubkey: _pk_1,
consensus_bls_pubkey: vector[],
network_addresses: x"222222",
full_node_network_addresses: x"333333",
},
Expand Down Expand Up @@ -887,6 +889,7 @@ module supra_framework::genesis {
voter_address: @0x121343,
stake_amount: 100 * ONE_SUPRA,
consensus_pubkey: _pk_1,
consensus_bls_pubkey: vector[],
network_addresses: x"222222",
full_node_network_addresses: x"333333",
},
Expand Down Expand Up @@ -930,6 +933,7 @@ module supra_framework::genesis {
voter_address: @0x121346,
stake_amount: 100 * ONE_SUPRA,
consensus_pubkey: _pk_2,
consensus_bls_pubkey: vector[],
network_addresses: x"222222",
full_node_network_addresses: x"333333",
},
Expand Down
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.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will need to ensure that the bytes comprise a valid BLS key.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this verification, we required native function in move VM.

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[];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are calling this function anywhere, then this could be causing deserialization problems. The value needs to be initialized.


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
15 changes: 12 additions & 3 deletions aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ mod genesis_context;
use std::hash::{Hash, Hasher};
use crate::genesis_context::GenesisStateView;
use aptos_crypto::{
ed25519,
ed25519::{Ed25519PrivateKey, Ed25519PublicKey},
HashValue, PrivateKey, Uniform,
blsttc, ed25519::{self, Ed25519PrivateKey, Ed25519PublicKey}, HashValue, PrivateKey, Uniform
};
use aptos_framework::{ReleaseBundle, ReleasePackage};
use aptos_gas_schedule::{
Expand Down Expand Up @@ -1049,6 +1047,10 @@ pub struct Validator {

/// ed25519 public key used to sign consensus messages.
pub consensus_pubkey: Vec<u8>,

//need to add new feild for bls publickey
pub consensus_bls_pubkey: Vec<u8>,

/// `NetworkAddress` for the validator.
pub network_addresses: Vec<u8>,
/// `NetworkAddress` for the validator's full node.
Expand All @@ -1058,6 +1060,7 @@ pub struct Validator {
pub struct TestValidator {
pub key: Ed25519PrivateKey,
pub consensus_key: ed25519::PrivateKey,
pub consensus_bls_key: blsttc::BlsPrivateKey,
pub data: Validator,
}

Expand All @@ -1075,6 +1078,9 @@ impl TestValidator {
let owner_address = auth_key.account_address();
let consensus_key = ed25519::PrivateKey::generate(rng);
let consensus_pubkey = consensus_key.public_key().to_bytes().to_vec();

let consensus_bls_key = blsttc::BlsPrivateKey::generate_random();
let consensus_bls_pubkey = consensus_bls_key.public_key().to_bytes().to_vec();
let network_address = [0u8; 0].to_vec();
let full_node_network_address = [0u8; 0].to_vec();

Expand All @@ -1083,9 +1089,11 @@ impl TestValidator {
} else {
0
};

let data = Validator {
owner_address,
consensus_pubkey,
consensus_bls_pubkey,
operator_address: owner_address,
voter_address: owner_address,
network_addresses: network_address,
Expand All @@ -1095,6 +1103,7 @@ impl TestValidator {
Self {
key,
consensus_key,
consensus_bls_key,
data,
}
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/safety-rules/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn empty_proof() -> Proof {

pub fn make_genesis(signer: &ValidatorSigner) -> (EpochChangeProof, QuorumCert) {
let validator_info =
ValidatorInfo::new_with_test_network_keys(signer.author(), signer.public_key(), 1, 0);
ValidatorInfo::new_with_test_network_keys(signer.author(), signer.public_key(), None, 1, 0);
let validator_set = ValidatorSet::new(vec![validator_info]);
let li = LedgerInfo::mock_genesis(Some(validator_set));
let block = Block::make_genesis_block_from_ledger_info(&li);
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn make_timeout_cert(

pub fn validator_signers_to_ledger_info(signers: &[&ValidatorSigner]) -> LedgerInfo {
let infos = signers.iter().enumerate().map(|(index, v)| {
ValidatorInfo::new_with_test_network_keys(v.author(), v.public_key(), 1, index as u64)
ValidatorInfo::new_with_test_network_keys(v.author(), v.public_key(), None, 1, index as u64)
});
let validator_set = ValidatorSet::new(infos.collect());
LedgerInfo::mock_genesis(Some(validator_set))
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/round_manager_fuzzing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn build_empty_store(
// helpers for safety rule initialization
fn make_initial_epoch_change_proof(signer: &ValidatorSigner) -> EpochChangeProof {
let validator_info =
ValidatorInfo::new_with_test_network_keys(signer.author(), signer.public_key(), 1, 0);
ValidatorInfo::new_with_test_network_keys(signer.author(), signer.public_key(), None, 1, 0);
let validator_set = ValidatorSet::new(vec![validator_info]);
let li = LedgerInfo::mock_genesis(Some(validator_set));
let lis = LedgerInfoWithSignatures::new(li, AggregateSignature::empty());
Expand Down
1 change: 1 addition & 0 deletions consensus/src/twins/twins_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl SMRNode {
ValidatorInfo::new_with_test_network_keys(
sr_test_config.author,
sr_test_config.consensus_key.as_ref().unwrap().public_key(),
None,
1,
index as u64,
)
Expand Down
1 change: 1 addition & 0 deletions crates/aptos-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repository = { workspace = true }
rust-version = { workspace = true }

[dependencies]
blsttc = { workspace = true }
aes-gcm = { workspace = true }
anyhow = { workspace = true }
aptos-crypto-derive = { workspace = true }
Expand Down
Loading