这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ event-listener = "2.5.3"
fail = "0.5.0"
ff = "0.13"
field_count = "0.1.1"
fixed = "1.25.1"
flate2 = "1.0.24"
futures = "0.3.29"
futures-channel = "0.3.29"
Expand Down
42 changes: 39 additions & 3 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ use aptos_types::{
partitioner::PartitionedTransactions,
},
block_metadata::BlockMetadata,
block_metadata_ext::BlockMetadataExt,
block_metadata_ext::{BlockMetadataExt, BlockMetadataWithRandomness},
chain_id::ChainId,
fee_statement::FeeStatement,
move_utils::as_move_value::AsMoveValue,
on_chain_config::{
new_epoch_event_key, ConfigurationResource, FeatureFlag, Features, OnChainConfig,
TimedFeatureOverride, TimedFeatures, TimedFeaturesBuilder,
},
randomness::Randomness,
state_store::{StateView, TStateView},
transaction::{
authenticator::AnySignature, signature_verified_transaction::SignatureVerifiedTransaction,
Expand Down Expand Up @@ -1700,13 +1702,47 @@ impl AptosVM {
let mut session =
self.new_session(resolver, SessionId::block_meta_ext(&block_metadata_ext));

let args = serialize_values(&block_metadata_ext.get_prologue_ext_move_args());
let block_metadata_with_randomness = match block_metadata_ext {
BlockMetadataExt::V0(_) => unreachable!(),
BlockMetadataExt::V1(v1) => v1,
};

let BlockMetadataWithRandomness {
id,
epoch,
round,
proposer,
previous_block_votes_bitvec,
failed_proposer_indices,
timestamp_usecs,
randomness,
} = block_metadata_with_randomness;

let args = vec![
MoveValue::Signer(AccountAddress::ZERO), // Run as 0x0
MoveValue::Address(AccountAddress::from_bytes(id.to_vec()).unwrap()),
MoveValue::U64(epoch),
MoveValue::U64(round),
MoveValue::Address(proposer),
failed_proposer_indices
.into_iter()
.map(|i| i as u64)
.collect::<Vec<_>>()
.as_move_value(),
previous_block_votes_bitvec.as_move_value(),
MoveValue::U64(timestamp_usecs),
randomness
.as_ref()
.map(Randomness::randomness_cloned)
.as_move_value(),
];

session
.execute_function_bypass_visibility(
&BLOCK_MODULE,
BLOCK_PROLOGUE_EXT,
vec![],
args,
serialize_values(&args),
&mut gas_meter,
)
.map(|_return_vals| ())
Expand Down
10 changes: 5 additions & 5 deletions dkg/src/dkg_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use aptos_validator_transaction_pool::{TxnGuard, VTxnPoolState};
use futures_channel::oneshot;
use futures_util::{future::AbortHandle, FutureExt, StreamExt};
use move_core_types::account_address::AccountAddress;
use rand::thread_rng;
use rand::{prelude::StdRng, thread_rng, SeedableRng};
use std::sync::Arc;

#[allow(dead_code)]
Expand Down Expand Up @@ -207,12 +207,12 @@ impl<DKG: DKGTrait> DKGManager<DKG> {
self.state = match &self.state {
InnerState::NotStarted => {
let public_params = DKG::new_public_params(dkg_session_metadata);
let mut rng = thread_rng();
let input_secret = if cfg!(feature = "smoke-test") {
DKG::generate_predictable_input_secret_for_testing(self.dealer_sk.as_ref())
let mut rng = if cfg!(feature = "smoke-test") {
StdRng::from_seed(self.my_addr.into_bytes())
} else {
DKG::InputSecret::generate(&mut rng)
StdRng::from_rng(thread_rng()).unwrap()
};
let input_secret = DKG::InputSecret::generate(&mut rng);

let trx = DKG::generate_transcript(
&mut rng,
Expand Down
3 changes: 1 addition & 2 deletions dkg/src/transcript_aggregation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ impl<S: DKGTrait> BroadcastStatus<DKGMessage> for Arc<TranscriptAggregationState
// All checks passed. Aggregating.
trx_aggregator.contributors.insert(metadata.author);
if let Some(agg_trx) = trx_aggregator.trx.as_mut() {
let acc = std::mem::take(agg_trx);
*agg_trx = S::aggregate_transcripts(&self.dkg_pub_params, vec![acc, transcript]);
S::aggregate_transcripts(&self.dkg_pub_params, agg_trx, transcript);
} else {
trx_aggregator.trx = Some(transcript);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ fn count_event_notifications_and_ensure_ordering(listener: &mut EventNotificatio
notification_count += 1;
assert_lt!(
last_version_received,
event_notification.version.try_into().unwrap()
std::convert::TryInto::<i64>::try_into(event_notification.version).unwrap()
);
last_version_received = event_notification.version.try_into().unwrap();
} else {
Expand Down
2 changes: 2 additions & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyhow = { workspace = true }
aptos-bitvec = { workspace = true }
aptos-crypto = { workspace = true }
aptos-crypto-derive = { workspace = true }
aptos-dkg = { workspace = true }
aptos-experimental-runtimes = { workspace = true }
ark-bn254 = { workspace = true }
ark-ff = { workspace = true }
Expand All @@ -28,6 +29,7 @@ bcs = { workspace = true }
bytes = { workspace = true }
chrono = { workspace = true }
derivative = { workspace = true }
fixed = { workspace = true }
hex = { workspace = true }
itertools = { workspace = true }
jsonwebtoken = { workspace = true }
Expand Down
59 changes: 9 additions & 50 deletions types/src/block_metadata_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{block_metadata::BlockMetadata, randomness::Randomness};
use aptos_crypto::HashValue;
use move_core_types::{account_address::AccountAddress, value::MoveValue};
use move_core_types::account_address::AccountAddress;
use serde::{Deserialize, Serialize};

/// The extended block metadata.
Expand All @@ -21,15 +21,15 @@ pub enum BlockMetadataExt {

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlockMetadataWithRandomness {
id: HashValue,
epoch: u64,
round: u64,
proposer: AccountAddress,
pub id: HashValue,
pub epoch: u64,
pub round: u64,
pub proposer: AccountAddress,
#[serde(with = "serde_bytes")]
previous_block_votes_bitvec: Vec<u8>,
failed_proposer_indices: Vec<u32>,
timestamp_usecs: u64,
randomness: Option<Randomness>,
pub previous_block_votes_bitvec: Vec<u8>,
pub failed_proposer_indices: Vec<u32>,
pub timestamp_usecs: u64,
pub randomness: Option<Randomness>,
}

impl BlockMetadataExt {
Expand Down Expand Up @@ -62,47 +62,6 @@ impl BlockMetadataExt {
}
}

pub fn get_prologue_ext_move_args(self) -> Vec<MoveValue> {
let mut ret = vec![
MoveValue::Signer(AccountAddress::ONE),
MoveValue::Address(AccountAddress::from_bytes(self.id().to_vec()).unwrap()),
MoveValue::U64(self.epoch()),
MoveValue::U64(self.round()),
MoveValue::Address(self.proposer()),
MoveValue::Vector(
self.failed_proposer_indices()
.iter()
.map(|x| MoveValue::U64((*x) as u64))
.collect(),
),
MoveValue::Vector(
self.previous_block_votes_bitvec()
.iter()
.map(|x| MoveValue::U8(*x))
.collect(),
),
MoveValue::U64(self.timestamp_usecs()),
];

match self.randomness() {
None => {
ret.push(MoveValue::Bool(false));
ret.push(MoveValue::Vector(vec![]));
},
Some(randomness) => {
let move_bytes = randomness
.randomness()
.iter()
.copied()
.map(MoveValue::U8)
.collect();
ret.push(MoveValue::Bool(true));
ret.push(MoveValue::Vector(move_bytes));
},
}
ret
}

pub fn timestamp_usecs(&self) -> u64 {
match self {
BlockMetadataExt::V0(obj) => obj.timestamp_usecs(),
Expand Down
49 changes: 20 additions & 29 deletions types/src/dkg/dummy_dkg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct DummyDKG {}

impl DKGTrait for DummyDKG {
type DealerPrivateKey = bls12381::PrivateKey;
type DealtPubKeyShare = ();
type DealtSecret = DummySecret;
type DealtSecretShare = DummySecret;
type InputSecret = DummySecret;
Expand All @@ -29,11 +30,14 @@ impl DKGTrait for DummyDKG {
DummySecret::aggregate(secrets)
}

fn dealt_secret_from_input(input: &Self::InputSecret) -> Self::DealtSecret {
fn dealt_secret_from_input(
_pub_params: &Self::PublicParams,
input: &Self::InputSecret,
) -> Self::DealtSecret {
*input
}

fn generate_transcript<R: CryptoRng>(
fn generate_transcript<R: CryptoRng + RngCore>(
_rng: &mut R,
_params: &Self::PublicParams,
input_secret: &Self::InputSecret,
Expand Down Expand Up @@ -63,31 +67,27 @@ impl DKGTrait for DummyDKG {

fn aggregate_transcripts(
_params: &Self::PublicParams,
transcripts: Vec<DummyDKGTranscript>,
) -> DummyDKGTranscript {
let mut all_secrets = vec![];
let mut agg_contributions_by_dealer = BTreeMap::new();
for transcript in transcripts {
let DummyDKGTranscript {
secret,
contributions_by_dealer,
} = transcript;
all_secrets.push(secret);
agg_contributions_by_dealer.extend(contributions_by_dealer);
}
DummyDKGTranscript {
secret: DummySecret::aggregate(all_secrets),
contributions_by_dealer: agg_contributions_by_dealer,
}
accumulator: &mut Self::Transcript,
element: Self::Transcript,
) {
let DummyDKGTranscript {
secret,
contributions_by_dealer,
} = element;
accumulator
.contributions_by_dealer
.extend(contributions_by_dealer);
accumulator.secret =
DummySecret::aggregate(vec![std::mem::take(&mut accumulator.secret), secret]);
}

fn decrypt_secret_share_from_transcript(
_pub_params: &Self::PublicParams,
transcript: &DummyDKGTranscript,
_player_idx: u64,
_dk: &Self::NewValidatorDecryptKey,
) -> anyhow::Result<DummySecret> {
Ok(transcript.secret)
) -> anyhow::Result<(DummySecret, ())> {
Ok((transcript.secret, ()))
}

fn reconstruct_secret_from_shares(
Expand All @@ -108,15 +108,6 @@ impl DKGTrait for DummyDKG {
fn get_dealers(transcript: &DummyDKGTranscript) -> BTreeSet<u64> {
transcript.contributions_by_dealer.keys().copied().collect()
}

fn generate_predictable_input_secret_for_testing(
dealer_sk: &bls12381::PrivateKey,
) -> DummySecret {
let bytes_8: [u8; 8] = dealer_sk.to_bytes()[0..8].try_into().unwrap();
DummySecret {
val: u64::from_be_bytes(bytes_8),
}
}
}

#[derive(Copy, Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand Down
17 changes: 12 additions & 5 deletions types/src/dkg/dummy_dkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ fn test_dummy_dkg_correctness() {
.iter()
.map(|state| state.transcript.clone().unwrap())
.collect();
let agg_transcript = DummyDKG::aggregate_transcripts(&pub_params, all_transcripts);
let mut agg_transcript = DummyDKGTranscript::default();
all_transcripts.into_iter().for_each(|trx| {
DummyDKG::aggregate_transcripts(&pub_params, &mut agg_transcript, trx);
});

assert!(DummyDKG::verify_transcript(&pub_params, &agg_transcript).is_ok());

// Optional check: bad transcript should be rejected.
Expand All @@ -128,13 +132,14 @@ fn test_dummy_dkg_correctness() {

// Every new validator decrypt their own secret share.
for (idx, nvi) in new_validator_states.iter_mut().enumerate() {
nvi.secret_share = DummyDKG::decrypt_secret_share_from_transcript(
let (secret, _pub_key) = DummyDKG::decrypt_secret_share_from_transcript(
&pub_params,
&agg_transcript,
idx as u64,
&nvi.sk,
)
.ok()
.unwrap();
nvi.secret_share = Some(secret);
}

// The dealt secret should be reconstructable.
Expand All @@ -147,7 +152,9 @@ fn test_dummy_dkg_correctness() {
DummyDKG::reconstruct_secret_from_shares(&pub_params, player_share_pairs).unwrap();

let all_input_secrets = dealer_states.iter().map(|ds| ds.input_secret).collect();
let dealt_secret_from_input =
DummyDKG::dealt_secret_from_input(&DummyDKG::aggregate_input_secret(all_input_secrets));
let dealt_secret_from_input = DummyDKG::dealt_secret_from_input(
&pub_params,
&DummyDKG::aggregate_input_secret(all_input_secrets),
);
assert_eq!(dealt_secret_from_reconstruct, dealt_secret_from_input);
}
Loading