Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[natives] expose all feature flags inside NativeContext as an extension #7038

Merged
merged 5 commits into from
Mar 11, 2023
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
10 changes: 5 additions & 5 deletions aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use move_table_extension::NativeTableContext;
use move_vm_runtime::{
config::VMConfig, move_vm::MoveVM, native_extensions::NativeContextExtensions,
};
use std::ops::Deref;
use std::{ops::Deref, sync::Arc};

pub struct MoveVmExt {
inner: MoveVM,
Expand All @@ -44,19 +44,19 @@ impl MoveVmExt {
5
};

let treat_friend_as_private = features.is_enabled(FeatureFlag::TREAT_FRIEND_AS_PRIVATE);

Ok(Self {
inner: MoveVM::new_with_config(
aptos_natives(
native_gas_params,
abs_val_size_gas_params,
gas_feature_version,
timed_features.clone(),
Arc::new(features),
),
VMConfig {
verifier: verifier_config(
features.is_enabled(FeatureFlag::TREAT_FRIEND_AS_PRIVATE),
&timed_features,
),
verifier: verifier_config(treat_friend_as_private, &timed_features),
max_binary_format_version,
paranoid_type_checks: crate::AptosVM::get_paranoid_checks(),
},
Expand Down
11 changes: 9 additions & 2 deletions aptos-move/aptos-vm/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
use aptos_gas::{AbstractValueSizeGasParameters, NativeGasParameters, LATEST_GAS_FEATURE_VERSION};
#[cfg(feature = "testing")]
use aptos_types::chain_id::ChainId;
use aptos_types::{account_config::CORE_CODE_ADDRESS, on_chain_config::TimedFeatures};
use aptos_types::{
account_config::CORE_CODE_ADDRESS,
on_chain_config::{Features, TimedFeatures},
};
use move_vm_runtime::native_functions::NativeFunctionTable;
use std::sync::Arc;
#[cfg(feature = "testing")]
use {
aptos_framework::natives::{
Expand All @@ -27,6 +31,7 @@ pub fn aptos_natives(
abs_val_size_gas_params: AbstractValueSizeGasParameters,
gas_feature_version: u64,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> NativeFunctionTable {
move_stdlib::natives::all_natives(CORE_CODE_ADDRESS, gas_params.move_stdlib)
.into_iter()
Expand All @@ -35,6 +40,7 @@ pub fn aptos_natives(
CORE_CODE_ADDRESS,
gas_params.aptos_framework,
timed_features,
features,
move |val| abs_val_size_gas_params.abstract_value_size(val, gas_feature_version),
))
.chain(move_table_extension::table_natives(
Expand All @@ -61,7 +67,8 @@ pub fn assert_no_test_natives(err_msg: &str) {
NativeGasParameters::zeros(),
AbstractValueSizeGasParameters::zeros(),
LATEST_GAS_FEATURE_VERSION,
TimedFeatures::enable_all()
TimedFeatures::enable_all(),
Arc::new(Features::default())
)
.into_iter()
.all(|(_, module_name, func_name, _)| {
Expand Down
7 changes: 5 additions & 2 deletions aptos-move/framework/src/natives/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::{
},
safely_pop_arg,
};
use aptos_types::on_chain_config::TimedFeatures;
use aptos_types::on_chain_config::{Features, TimedFeatures};
use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas};
use move_vm_runtime::native_functions::NativeFunction;
use move_vm_types::{loaded_data::runtime_types::Type, values::Value};
use smallvec::{smallvec, SmallVec};
use std::collections::VecDeque;
use std::{collections::VecDeque, sync::Arc};

/***************************************************************************************************
* native fun create_address
Expand Down Expand Up @@ -62,13 +62,15 @@ pub struct GasParameters {
pub fn make_all(
gas_params: GasParameters,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> impl Iterator<Item = (String, NativeFunction)> {
let natives = [
(
"create_address",
make_safe_native(
gas_params.create_address,
timed_features.clone(),
features.clone(),
native_create_address,
),
),
Expand All @@ -79,6 +81,7 @@ pub fn make_all(
make_safe_native(
gas_params.create_signer,
timed_features,
features,
create_signer::native_create_signer,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use crate::{
safely_pop_arg,
};
use aptos_aggregator::aggregator_extension::AggregatorID;
use aptos_types::on_chain_config::TimedFeatures;
use aptos_types::on_chain_config::{Features, TimedFeatures};
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::native_functions::NativeFunction;
use move_vm_types::{
loaded_data::runtime_types::Type,
values::{Struct, StructRef, Value},
};
use smallvec::{smallvec, SmallVec};
use std::collections::VecDeque;
use std::{collections::VecDeque, sync::Arc};

/***************************************************************************************************
* native fun add(aggregator: &mut Aggregator, value: u128);
Expand Down Expand Up @@ -177,23 +177,39 @@ pub struct GasParameters {
pub fn make_all(
gas_params: GasParameters,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> impl Iterator<Item = (String, NativeFunction)> {
let natives = [
(
"add",
make_safe_native(gas_params.add, timed_features.clone(), native_add),
make_safe_native(
gas_params.add,
timed_features.clone(),
features.clone(),
native_add,
),
),
(
"read",
make_safe_native(gas_params.read, timed_features.clone(), native_read),
make_safe_native(
gas_params.read,
timed_features.clone(),
features.clone(),
native_read,
),
),
(
"sub",
make_safe_native(gas_params.sub, timed_features.clone(), native_sub),
make_safe_native(
gas_params.sub,
timed_features.clone(),
features.clone(),
native_sub,
),
),
(
"destroy",
make_safe_native(gas_params.destroy, timed_features, native_destroy),
make_safe_native(gas_params.destroy, timed_features, features, native_destroy),
),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ use crate::{
};
use aptos_aggregator::aggregator_extension::{extension_error, AggregatorHandle, AggregatorID};
use aptos_crypto::hash::DefaultHasher;
use aptos_types::{account_address::AccountAddress, on_chain_config::TimedFeatures};
use aptos_types::{
account_address::AccountAddress,
on_chain_config::{Features, TimedFeatures},
};
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::native_functions::NativeFunction;
use move_vm_types::{
loaded_data::runtime_types::Type,
values::{Struct, StructRef, Value},
};
use smallvec::{smallvec, SmallVec};
use std::collections::VecDeque;
use std::{collections::VecDeque, sync::Arc};

/***************************************************************************************************
* native fun new_aggregator(aggregator_factory: &mut AggregatorFactory, limit: u128): Aggregator;
Expand Down Expand Up @@ -86,12 +89,14 @@ pub struct GasParameters {
pub fn make_all(
gas_params: GasParameters,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> impl Iterator<Item = (String, NativeFunction)> {
let natives = [(
"new_aggregator",
make_safe_native(
gas_params.new_aggregator,
timed_features,
features,
native_new_aggregator,
),
)];
Expand Down
8 changes: 7 additions & 1 deletion aptos-move/framework/src/natives/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::{
};
use anyhow::bail;
use aptos_types::{
on_chain_config::TimedFeatures, transaction::ModuleBundle, vm_status::StatusCode,
on_chain_config::{Features, TimedFeatures},
transaction::ModuleBundle,
vm_status::StatusCode,
};
use better_any::{Tid, TidAble};
use move_binary_format::errors::{PartialVMError, PartialVMResult};
Expand All @@ -29,6 +31,7 @@ use std::{
collections::{btree_map::Entry, BTreeMap, BTreeSet, VecDeque},
fmt,
str::FromStr,
sync::Arc,
};

/// A wrapper around the representation of a Move Option, which is a vector with 0 or 1 element.
Expand Down Expand Up @@ -310,13 +313,15 @@ pub struct GasParameters {
pub fn make_all(
gas_params: GasParameters,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> impl Iterator<Item = (String, NativeFunction)> {
let natives = [
(
"request_publish",
make_safe_native(
gas_params.request_publish.clone(),
timed_features.clone(),
features.clone(),
native_request_publish,
),
),
Expand All @@ -325,6 +330,7 @@ pub fn make_all(
make_safe_native(
gas_params.request_publish,
timed_features,
features,
native_request_publish,
),
),
Expand Down
7 changes: 4 additions & 3 deletions aptos-move/framework/src/natives/create_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use crate::{
natives::helpers::{make_safe_native, SafeNativeContext, SafeNativeResult},
safely_pop_arg,
};
use aptos_types::on_chain_config::TimedFeatures;
use aptos_types::on_chain_config::{Features, TimedFeatures};
use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas};
use move_vm_runtime::native_functions::NativeFunction;
use move_vm_types::{loaded_data::runtime_types::Type, values::Value};
use smallvec::{smallvec, SmallVec};
use std::collections::VecDeque;
use std::{collections::VecDeque, sync::Arc};

/***************************************************************************************************
* native fun create_signer
Expand Down Expand Up @@ -45,10 +45,11 @@ pub struct CreateSignerGasParameters {
pub fn make_all(
gas_param: CreateSignerGasParameters,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> impl Iterator<Item = (String, NativeFunction)> {
let natives = [(
"create_signer",
make_safe_native(gas_param, timed_features, native_create_signer),
make_safe_native(gas_param, timed_features, features, native_create_signer),
)];

crate::natives::helpers::make_module_natives(natives)
Expand Down
14 changes: 12 additions & 2 deletions aptos-move/framework/src/natives/cryptography/bls12381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use aptos_crypto::{
test_utils::KeyPair,
SigningKey, Uniform,
};
use aptos_types::on_chain_config::TimedFeatures;
use aptos_types::on_chain_config::{Features, TimedFeatures};
use move_binary_format::errors::PartialVMError;
use move_core_types::{
gas_algebra::{InternalGas, InternalGasPerArg, InternalGasPerByte, NumArgs, NumBytes},
Expand All @@ -35,7 +35,7 @@ use move_vm_types::{
#[cfg(feature = "testing")]
use rand_core::OsRng;
use smallvec::{smallvec, SmallVec};
use std::{collections::VecDeque, convert::TryFrom};
use std::{collections::VecDeque, convert::TryFrom, sync::Arc};

/// Pops a `Vec<T>` off the argument stack and converts it to a `Vec<Vec<u8>>` by reading the first
/// field of `T`, which is a `Vec<u8>` field named `bytes`.
Expand Down Expand Up @@ -685,6 +685,7 @@ pub fn native_generate_proof_of_possession(
pub fn make_all(
gas_params: GasParameters,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> impl Iterator<Item = (String, NativeFunction)> {
let mut natives = vec![];
natives.append(&mut vec![
Expand All @@ -694,6 +695,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_aggregate_pubkeys,
),
),
Expand All @@ -702,6 +704,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_aggregate_signatures,
),
),
Expand All @@ -710,6 +713,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_signature_subgroup_check,
),
),
Expand All @@ -718,6 +722,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_validate_pubkey,
),
),
Expand All @@ -726,6 +731,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_verify_aggregate_signature,
),
),
Expand All @@ -734,6 +740,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_verify_multisignature,
),
),
Expand All @@ -742,6 +749,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_verify_normal_signature,
),
),
Expand All @@ -750,6 +758,7 @@ pub fn make_all(
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_bls12381_verify_proof_of_possession,
),
),
Expand All @@ -758,6 +767,7 @@ pub fn make_all(
make_safe_native(
gas_params,
timed_features,
features,
native_bls12381_verify_signature_share,
),
),
Expand Down
Loading