Skip to content

Commit

Permalink
Preview randomness (#12327)
Browse files Browse the repository at this point in the history
* randomness type update 3 (#12202)

* randomness #4: RandManager update from randomnet (#12224)

* RandManager update from randomnet

* lint

* lint

* randomness #5: consensus update from randomnet (#12225)

* consensus update from randomnet

* update

* randomness #6: dkg manager update from randomnet (#12226)

* consensus update from randomnet

* update

* update execution client api

* dkg manager update from randomnet

* avoid panic

* make api, indexer, fake aptos db aware of block metadata ext txns (#12227)

* randomness #8: framework update from randomnet (#12228)

* framework update from randomnet

Squashed commit of the following to fix jwk smoke tests:

commit 3bd0154
Author: zhoujun.ma <[email protected]>
Date:   Tue Feb 27 02:47:57 2024 -0800

    update

commit 2eb6add
Author: zhoujun.ma <[email protected]>
Date:   Tue Feb 27 02:12:27 2024 -0800

    update

commit 9d82151
Author: zhoujun.ma <[email protected]>
Date:   Tue Feb 27 01:51:08 2024 -0800

    debug

fix doc test

fix spec

fix doc

update initialization in genesis

update features.move

initialize randomness in genesis

update golden files

private entry fun check and vm updates

* postpone release builder changes

* update goldenfiles

* fix is_safe_call spec

* randomness #9: smoke tests from randomnet (#12282)

* smoke test deps and 1st case from randomnet

* update

* more smoke tests

* randomness #10: randomness API update from randomnet (#12335)

* [move] fixes to `randomness.move` (#12250)

* [move] fixes to randomness.move

* Fixed the Prover spec

Fixed the spec to unblock the PR.

Need to prove the introduced assumptions with proper loop invariants, which should be provable.

* lint

---------

Co-authored-by: Junkil Park <[email protected]>
Co-authored-by: danielxiangzl <[email protected]>

* fix specs

---------

Co-authored-by: Alin Tomescu <[email protected]>
Co-authored-by: Junkil Park <[email protected]>
Co-authored-by: danielxiangzl <[email protected]>

* lint

* update genesis

* on-chain resources to indicate dkg/randomness failure injection (#12345)

* dkg/randomness failure injection

* update

* smoke test

* update

* update

* fix scripts

---------

Co-authored-by: Alin Tomescu <[email protected]>
Co-authored-by: Junkil Park <[email protected]>
Co-authored-by: danielxiangzl <[email protected]>
  • Loading branch information
4 people authored Mar 3, 2024
1 parent 1e729d0 commit cc977b4
Show file tree
Hide file tree
Showing 164 changed files with 11,609 additions and 1,032 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down Expand Up @@ -420,6 +435,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down Expand Up @@ -741,6 +771,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down Expand Up @@ -1062,6 +1107,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down Expand Up @@ -1383,6 +1443,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down Expand Up @@ -1704,6 +1779,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down Expand Up @@ -2025,6 +2115,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down Expand Up @@ -2346,6 +2451,21 @@
},
"type": "write_resource"
},
{
"address": "0x1",
"state_key_hash": "",
"data": {
"type": "0x1::randomness::PerBlockRandomness",
"data": {
"epoch": "1",
"round": "1",
"seed": {
"vec": []
}
}
},
"type": "write_resource"
},
{
"state_key_hash": "",
"handle": "0x38ff67f17cf7998cd41ed5267b52cff7af37d06a22e8b390ce44b69680fc0e97",
Expand Down
4 changes: 3 additions & 1 deletion api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ impl Context {
.into_iter()
.map(|t| {
// Update the timestamp if the next block occurs
if let Some(txn) = t.transaction.try_as_block_metadata() {
if let Some(txn) = t.transaction.try_as_block_metadata_ext() {
timestamp = txn.timestamp_usecs();
} else if let Some(txn) = t.transaction.try_as_block_metadata() {
timestamp = txn.timestamp_usecs();
}
let txn = converter.try_into_onchain_transaction(timestamp, t)?;
Expand Down
17 changes: 16 additions & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use crate::{
use anyhow::anyhow;
use aptos_block_executor::txn_commit_hook::NoOpTransactionCommitHook;
use aptos_crypto::HashValue;
use aptos_framework::{natives::code::PublishRequest, RuntimeModuleMetadataV1};
use aptos_framework::{
natives::{code::PublishRequest, transaction_context::NativeTransactionContext},
RuntimeModuleMetadataV1,
};
use aptos_gas_algebra::{Gas, GasQuantity, Octa};
use aptos_gas_meter::{AptosGasMeter, GasAlgebra, StandardGasAlgebra, StandardGasMeter};
use aptos_gas_schedule::{AptosGasParameters, VMGasParameters};
Expand Down Expand Up @@ -677,6 +680,18 @@ impl AptosVM {
senders: Vec<AccountAddress>,
entry_fn: &EntryFunction,
) -> Result<SerializedReturnValues, VMStatus> {
let is_friend_or_private = session.load_function_def_is_friend_or_private(
entry_fn.module(),
entry_fn.function(),
entry_fn.ty_args(),
)?;
if is_friend_or_private {
let txn_context = session
.get_native_extensions()
.get_mut::<NativeTransactionContext>();
txn_context.set_is_friend_or_private_entry_func();
}

let function =
session.load_function(entry_fn.module(), entry_fn.function(), entry_fn.ty_args())?;
let args = verifier::transaction_arg_validation::validate_combine_signer_and_txn_args(
Expand Down
2 changes: 2 additions & 0 deletions aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use aptos_framework::natives::{
code::NativeCodeContext,
cryptography::{algebra::AlgebraContext, ristretto255_point::NativeRistrettoPointContext},
event::NativeEventContext,
randomness::RandomnessContext,
state_storage::NativeStateStorageContext,
transaction_context::NativeTransactionContext,
};
Expand Down Expand Up @@ -201,6 +202,7 @@ impl MoveVmExt {
extensions.add(NativeRistrettoPointContext::new());
extensions.add(AlgebraContext::new());
extensions.add(NativeAggregatorContext::new(txn_hash, resolver, resolver));
extensions.add(RandomnessContext::new());
extensions.add(NativeTransactionContext::new(
txn_hash.to_vec(),
session_id.into_script_hash(),
Expand Down
11 changes: 6 additions & 5 deletions aptos-move/aptos-vm/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use aptos_aggregator::{
#[cfg(feature = "testing")]
use aptos_aggregator::{resolver::TDelayedFieldView, types::DelayedFieldValue};
#[cfg(feature = "testing")]
use aptos_framework::natives::randomness::RandomnessContext;
#[cfg(feature = "testing")]
use aptos_framework::natives::{cryptography::algebra::AlgebraContext, event::NativeEventContext};
use aptos_gas_schedule::{MiscGasParameters, NativeGasParameters, LATEST_GAS_FEATURE_VERSION};
use aptos_native_interface::SafeNativeBuilder;
Expand Down Expand Up @@ -225,11 +227,9 @@ fn unit_test_extensions_hook(exts: &mut NativeContextExtensions) {

exts.add(NativeTableContext::new([0u8; 32], &*DUMMY_RESOLVER));
exts.add(NativeCodeContext::default());
exts.add(NativeTransactionContext::new(
vec![1],
vec![1],
ChainId::test().id(),
)); // We use the testing environment chain ID here
let mut txn_context = NativeTransactionContext::new(vec![1], vec![1], ChainId::test().id());
txn_context.set_is_friend_or_private_entry_func();
exts.add(txn_context); // We use the testing environment chain ID here
exts.add(NativeAggregatorContext::new(
[0; 32],
&*DUMMY_RESOLVER,
Expand All @@ -238,4 +238,5 @@ fn unit_test_extensions_hook(exts: &mut NativeContextExtensions) {
exts.add(NativeRistrettoPointContext::new());
exts.add(AlgebraContext::new());
exts.add(NativeEventContext::default());
exts.add(RandomnessContext::new());
}
9 changes: 6 additions & 3 deletions aptos-move/aptos-vm/src/validator_txns/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use aptos_types::{
dkg::{DKGState, DKGTrait, DKGTranscript, DefaultDKG},
fee_statement::FeeStatement,
move_utils::as_move_value::AsMoveValue,
on_chain_config::OnChainConfig,
on_chain_config::{ConfigurationResource, OnChainConfig},
transaction::{ExecutionStatus, TransactionStatus},
};
use aptos_vm_logging::log_schema::AdapterLogSchema;
Expand All @@ -27,6 +27,7 @@ use move_core_types::{
};
use move_vm_types::gas::UnmeteredGasMeter;

#[derive(Debug)]
enum ExpectedFailure {
// Move equivalent: `errors::invalid_argument(*)`
EpochNotCurrent = 0x10001,
Expand All @@ -36,6 +37,7 @@ enum ExpectedFailure {
// Move equivalent: `errors::invalid_state(*)`
MissingResourceDKGState = 0x30001,
MissingResourceInprogressDKGSession = 0x30002,
MissingResourceConfiguration = 0x30003,
}

enum ExecutionFailure {
Expand Down Expand Up @@ -73,13 +75,14 @@ impl AptosVM {
) -> Result<(VMStatus, VMOutput), ExecutionFailure> {
let dkg_state = OnChainConfig::fetch_config(resolver)
.ok_or_else(|| Expected(MissingResourceDKGState))?;

let config_resource = ConfigurationResource::fetch_config(resolver)
.ok_or_else(|| Expected(MissingResourceConfiguration))?;
let DKGState { in_progress, .. } = dkg_state;
let in_progress_session_state =
in_progress.ok_or_else(|| Expected(MissingResourceInprogressDKGSession))?;

// Check epoch number.
if dkg_node.metadata.epoch != in_progress_session_state.metadata.dealer_epoch {
if dkg_node.metadata.epoch != config_resource.epoch() {
return Err(Expected(EpochNotCurrent));
}

Expand Down
Loading

0 comments on commit cc977b4

Please sign in to comment.