Skip to content

Commit

Permalink
[timed_features] Clean up already enabled flags
Browse files Browse the repository at this point in the history
  • Loading branch information
runtian-zhou committed May 12, 2023
1 parent f3fc710 commit 9baf67b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 357 deletions.
37 changes: 7 additions & 30 deletions aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl MoveVmExt {

let enable_invariant_violation_check_in_swap_loc =
!timed_features.is_enabled(TimedFeatureFlag::DisableInvariantViolationCheckInSwapLoc);
let type_size_limit = timed_features.is_enabled(TimedFeatureFlag::EntryTypeSizeLimit);
let type_size_limit = true;

let verifier_config = verifier_config(&features, &timed_features);
let features = Arc::new(features);
Expand Down Expand Up @@ -132,30 +132,7 @@ impl Deref for MoveVmExt {
}
}

pub fn verifier_config(features: &Features, timed_features: &TimedFeatures) -> VerifierConfig {
let mut max_back_edges_per_function = None;
let mut max_back_edges_per_module = None;
let mut max_basic_blocks_in_script = None;

let mut max_per_fun_meter_units = None;
let mut max_per_mod_meter_units = None;

let legacy_limit_back_edges =
timed_features.is_enabled(TimedFeatureFlag::VerifierLimitBackEdges);
let metering = timed_features.is_enabled(TimedFeatureFlag::VerifierMetering);

if legacy_limit_back_edges && !metering {
// Turn on limit on back edges, as long as metering is not active
max_back_edges_per_function = Some(20);
max_back_edges_per_module = Some(400);
max_basic_blocks_in_script = Some(1024);
}

if metering {
max_per_fun_meter_units = Some(1000 * 80000);
max_per_mod_meter_units = Some(1000 * 80000);
}

pub fn verifier_config(features: &Features, _timed_features: &TimedFeatures) -> VerifierConfig {
VerifierConfig {
max_loop_depth: Some(5),
max_generic_instantiation_length: Some(32),
Expand All @@ -168,11 +145,11 @@ pub fn verifier_config(features: &Features, timed_features: &TimedFeatures) -> V
max_struct_definitions: None,
max_fields_in_struct: None,
max_function_definitions: None,
max_back_edges_per_function,
max_back_edges_per_module,
max_basic_blocks_in_script,
max_per_fun_meter_units,
max_per_mod_meter_units,
max_back_edges_per_function: None,
max_back_edges_per_module: None,
max_basic_blocks_in_script: None,
max_per_fun_meter_units: Some(1000 * 80000),
max_per_mod_meter_units: Some(1000 * 80000),
use_signature_checker_v2: features.is_enabled(FeatureFlag::SIGNATURE_CHECKER_V2),
}
}
115 changes: 0 additions & 115 deletions aptos-move/e2e-testsuite/src/tests/back_edges.rs

This file was deleted.

1 change: 0 additions & 1 deletion aptos-move/e2e-testsuite/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! Set env REGENERATE_GOLDENFILES to update the golden files when running tests..
mod account_universe;
mod back_edges;
mod create_account;
mod data_store;
mod execution_strategies;
Expand Down
69 changes: 8 additions & 61 deletions aptos-move/framework/src/natives/cryptography/multi_ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::natives::helpers::make_test_only_native_from_func;
use crate::{
natives::{
cryptography::ed25519::GasParameters,
helpers::{make_native_from_func, make_safe_native, SafeNativeContext, SafeNativeResult},
helpers::{make_safe_native, SafeNativeContext, SafeNativeResult},
},
safely_assert_eq, safely_pop_arg,
};
Expand All @@ -20,7 +20,7 @@ use aptos_crypto::{
multi_ed25519,
traits::*,
};
use aptos_types::on_chain_config::{Features, TimedFeatureFlag, TimedFeatures};
use aptos_types::on_chain_config::{Features, TimedFeatures};
use curve25519_dalek::edwards::CompressedEdwardsY;
use move_binary_format::errors::PartialVMResult;
#[cfg(feature = "testing")]
Expand All @@ -35,53 +35,6 @@ use rand_core::OsRng;
use smallvec::{smallvec, SmallVec};
use std::{collections::VecDeque, convert::TryFrom, sync::Arc};

/// DEPRECATED: See `public_key_validate_internal` comments in `multi_ed25519.move`.
///
/// Simply put, this function should have checked that `num_sub_pks > 0` and should abort PK
/// validation as soon as an invalid sub-PK is found, charging gas accordingly, rather than charge
/// gas for validating all `num_sub_pks` sub-PKs.
fn native_public_key_validate(
gas_params: &GasParameters,
_context: &mut NativeContext,
_ty_args: Vec<Type>,
mut arguments: VecDeque<Value>,
) -> PartialVMResult<NativeResult> {
debug_assert!(_ty_args.is_empty());
debug_assert!(arguments.len() == 1);

let pks_bytes = pop_arg!(arguments, Vec<u8>);

let num_sub_pks = pks_bytes.len() / ED25519_PUBLIC_KEY_LENGTH;

let mut cost = gas_params.base;

if num_sub_pks > multi_ed25519::MAX_NUM_OF_KEYS {
return Ok(NativeResult::ok(cost, smallvec![Value::bool(false)]));
};

let num_valid = pks_bytes
.chunks_exact(ED25519_PUBLIC_KEY_LENGTH)
.filter(|&pk_bytes| {
<[u8; ED25519_PUBLIC_KEY_LENGTH]>::try_from(pk_bytes)
.ok()
.and_then(|slice| CompressedEdwardsY(slice).decompress())
.map_or(false, |point| !point.is_small_order())
})
.count();

let all_valid = num_valid == num_sub_pks;
let mut num_checked = num_valid;
if !all_valid {
num_checked += 1;
}

let num_checked = NumArgs::new(num_checked as u64);
cost += gas_params.per_pubkey_deserialize * num_checked
+ gas_params.per_pubkey_small_order_check * num_checked;

Ok(NativeResult::ok(cost, smallvec![Value::bool(all_valid)]))
}

/// See `public_key_validate_v2_internal` comments in `multi_ed25519.move`.
fn native_public_key_validate_v2(
gas_params: &GasParameters,
Expand Down Expand Up @@ -275,18 +228,12 @@ pub fn make_all(
// MultiEd25519
(
"public_key_validate_internal",
if timed_features
.is_enabled(TimedFeatureFlag::MultiEd25519NativePublicKeyValidateGasFix)
{
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_public_key_validate_with_gas_fix,
)
} else {
make_native_from_func(gas_params.clone(), native_public_key_validate)
},
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
native_public_key_validate_with_gas_fix,
),
),
(
"public_key_validate_v2_internal",
Expand Down
30 changes: 7 additions & 23 deletions aptos-move/framework/src/natives/cryptography/ristretto255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
safely_assert_eq, safely_pop_arg,
};
use aptos_types::{
on_chain_config::{Features, TimedFeatureFlag, TimedFeatures},
on_chain_config::{Features, TimedFeatures},
vm_status::StatusCode,
};
use curve25519_dalek::scalar::Scalar;
Expand Down Expand Up @@ -182,28 +182,12 @@ pub fn make_all(
),
(
"multi_scalar_mul_internal",
if timed_features.is_enabled(TimedFeatureFlag::Ristretto255NativeFloatingPointFix) {
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
ristretto255_point::safe_native_multi_scalar_mul_no_floating_point,
)
} else {
// NOTE: We could not keep the old "unsafe" variant of this native because all the
// helper functions that the old "unsafe" native used were modified to return
// `SafeNativeResult`'s instead of `PartialVMResult`'s. This would've resulted in
// a lot of awkward error-handling, so we chose to simply make the native "safe".
//
// The only difference between this and the `safe_native_multi_scalar_mul_no_floating_point`
// from above, is this native still uses the flawed floating-point arithmetic gas formula.
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
ristretto255_point::native_multi_scalar_mul,
)
},
make_safe_native(
gas_params.clone(),
timed_features.clone(),
features.clone(),
ristretto255_point::safe_native_multi_scalar_mul_no_floating_point,
),
),
(
"scalar_is_canonical_internal",
Expand Down
Loading

0 comments on commit 9baf67b

Please sign in to comment.