Skip to content

Commit

Permalink
Revert "Add measuring support."
Browse files Browse the repository at this point in the history
This reverts commit 210ee55.
  • Loading branch information
joshuajbouw committed Jun 29, 2021
1 parent 3f449d5 commit a7868e8
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 164 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 0 additions & 4 deletions runtime/near-vm-logic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,3 @@ pub use near_vm_errors::{HostError, VMLogicError};
pub use types::ReturnData;

pub use gas_counter::with_ext_cost_counter;
#[cfg(feature = "protocol_feature_math_extension")]
pub use logic::ecrecover;
#[cfg(feature = "protocol_feature_math_extension")]
pub use logic::ripemd160;
46 changes: 15 additions & 31 deletions runtime/near-vm-logic/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use crate::utils::split_method_names;
use crate::ValuePtr;
use byteorder::ByteOrder;
#[cfg(feature = "protocol_feature_math_extension")]
use near_crypto::Secp256K1PublicKey;
#[cfg(feature = "protocol_feature_math_extension")]
use near_crypto::Secp256K1Signature;
use near_primitives::checked_feature;
use near_primitives::version::is_implicit_account_creation_enabled;
Expand Down Expand Up @@ -981,8 +979,10 @@ impl<'a> VMLogic<'a> {

self.gas_counter.pay_per(ripemd160_block, message_blocks as u64)?;

let value_hash = ripemd160(&value);
self.internal_write_register(register_id, value_hash)
use ripemd160::Digest;

let value_hash = ripemd160::Ripemd160::digest(&value);
self.internal_write_register(register_id, value_hash.as_slice().to_vec())
}

/// Recovers an ECDSA signer address and returns it into `register_id`.
Expand Down Expand Up @@ -1018,7 +1018,7 @@ impl<'a> VMLogic<'a> {
) -> Result<u64> {
self.gas_counter.pay_base(ecrecover_base)?;

let signature_data = {
let signature = {
let vec = self.get_vec_from_memory_or_register(sig_ptr, sig_len)?;
if vec.len() != 64 {
return Err(VMLogicError::HostError(HostError::ECRecoverError {
Expand All @@ -1034,7 +1034,7 @@ impl<'a> VMLogic<'a> {

if v < 4 {
bytes[64] = v as u8;
bytes
Secp256K1Signature::from(bytes)
} else {
return Err(VMLogicError::HostError(HostError::ECRecoverError {
msg: format!("V recovery byte 0 through 3 are valid but was provided {}", v),
Expand All @@ -1058,13 +1058,16 @@ impl<'a> VMLogic<'a> {
bytes
};

match ecrecover(signature_data, hash, malleability_flag) {
Some(key) => {
self.internal_write_register(register_id, key.as_ref().to_vec())?;
Ok(true as u64)
}
None => Ok(false as u64),
if !signature.check_signature_values(malleability_flag != 0) {
return Ok(false as u64);
}

if let Ok(pk) = signature.recover(hash) {
self.internal_write_register(register_id, pk.as_ref().to_vec())?;
return Ok(true as u64);
};

Ok(false as u64)
}

/// Called by gas metering injected into Wasm. Counts both towards `burnt_gas` and `used_gas`.
Expand Down Expand Up @@ -2582,22 +2585,3 @@ impl std::fmt::Debug for VMOutcome {
)
}
}

#[cfg(feature = "protocol_feature_math_extension")]
pub fn ecrecover(
signature_data: [u8; 65],
hash_data: [u8; 32],
malleability_flag: u64,
) -> Option<Secp256K1PublicKey> {
let signature = Secp256K1Signature::from(signature_data);
if !signature.check_signature_values(malleability_flag != 0) {
return None;
}
signature.recover(hash_data).map_or(None, |result| Some(result))
}

#[cfg(feature = "protocol_feature_math_extension")]
pub fn ripemd160(data: &[u8]) -> Vec<u8> {
use ripemd160::Digest;
ripemd160::Ripemd160::digest(data).as_slice().to_vec()
}
1 change: 0 additions & 1 deletion runtime/runtime-params-estimator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ once_cell = "1"
num-traits = "0.2.12"
libc = "0.2.81"
wabt = "0.9"
ripemd160 = "0.9.0"

[features]
default = ["costs_counting"]
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime-params-estimator/src/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ pub fn run(mut config: Config, only_compile: bool) -> RuntimeConfig {
// m.plot(PathBuf::from(&config.state_dump_path).as_path());
}

pub(crate) fn ratio_to_gas(gas_metric: GasMetric, value: Ratio<u64>) -> u64 {
fn ratio_to_gas(gas_metric: GasMetric, value: Ratio<u64>) -> u64 {
let divisor = match gas_metric {
// We use factor of 8 to approximately match the price of SHA256 operation between
// time-based and icount-based metric as measured on 3.2Ghz Core i5.
Expand Down
9 changes: 4 additions & 5 deletions runtime/runtime-params-estimator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::path::Path;

use once_cell::sync::OnceCell;

/// Lists all cases that we want to measure.
pub mod cases;
// Generates runtime fees from the measurements.
Expand All @@ -16,9 +12,12 @@ pub mod stats;
pub mod testbed;
// Prepares transactions and feeds them to the testbed in batches. Performs the warm up, takes care
// of nonces.
mod math_ops_cost;
pub mod testbed_runners;

use std::path::Path;

use once_cell::sync::OnceCell;

/// Lazily loads contract's code from a directory in the source tree.
pub(crate) struct TestContract {
path: &'static str,
Expand Down
101 changes: 0 additions & 101 deletions runtime/runtime-params-estimator/src/math_ops_cost.rs

This file was deleted.

7 changes: 2 additions & 5 deletions runtime/runtime-params-estimator/src/vm_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const SIGNER_ACCOUNT_ID: &str = "bob";
const SIGNER_ACCOUNT_PK: [u8; 3] = [0, 1, 2];
const PREDECESSOR_ACCOUNT_ID: &str = "carol";

pub(crate) fn create_context(input: Vec<u8>) -> VMContext {
fn create_context(input: Vec<u8>) -> VMContext {
VMContext {
current_account_id: CURRENT_ACCOUNT_ID.to_owned(),
signer_account_id: SIGNER_ACCOUNT_ID.to_owned(),
Expand Down Expand Up @@ -162,10 +162,7 @@ impl CompiledContractCache for MockCompiledContractCache {
}
}

pub(crate) fn least_squares_method(
xs: &Vec<u64>,
ys: &Vec<u64>,
) -> (Ratio<i128>, Ratio<i128>, Vec<i128>) {
fn least_squares_method(xs: &Vec<u64>, ys: &Vec<u64>) -> (Ratio<i128>, Ratio<i128>, Vec<i128>) {
let n = xs.len();
let n128 = n as i128;

Expand Down
27 changes: 12 additions & 15 deletions runtime/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
use std::cmp::max;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
use std::sync::Arc;

use log::debug;

use near_chain_configs::Genesis;
pub use near_crypto;
use near_crypto::PublicKey;
pub use near_primitives;
#[cfg(feature = "sandbox")]
use near_primitives::contract::ContractCode;
pub use near_primitives::runtime::apply_state::ApplyState;
use near_primitives::runtime::fees::RuntimeFeesConfig;
use near_primitives::runtime::get_insufficient_storage_stake;
use near_primitives::runtime::migration_data::{MigrationData, MigrationFlags};
use near_primitives::transaction::ExecutionMetadata;
use near_primitives::version::{
is_implicit_account_creation_enabled, ProtocolFeature, ProtocolVersion,
};
use near_primitives::{
account::Account,
checked_feature,
Expand Down Expand Up @@ -62,6 +51,17 @@ use crate::config::{
use crate::genesis::{GenesisStateApplier, StorageComputer};
use crate::verifier::validate_receipt;
pub use crate::verifier::{validate_transaction, verify_and_charge_transaction};
#[cfg(feature = "sandbox")]
use near_primitives::contract::ContractCode;
pub use near_primitives::runtime::apply_state::ApplyState;
use near_primitives::runtime::fees::RuntimeFeesConfig;
use near_primitives::runtime::migration_data::{MigrationData, MigrationFlags};
use near_primitives::transaction::ExecutionMetadata;
use near_primitives::version::{
is_implicit_account_creation_enabled, ProtocolFeature, ProtocolVersion,
};
use std::rc::Rc;
use std::sync::Arc;

mod actions;
pub mod adapter;
Expand Down Expand Up @@ -1458,7 +1458,7 @@ impl Runtime {

#[cfg(test)]
mod tests {
use std::sync::Arc;
use super::*;

use near_crypto::{InMemorySigner, KeyType, Signer};
use near_primitives::account::AccessKey;
Expand All @@ -1477,11 +1477,8 @@ mod tests {
use near_store::test_utils::create_tries;
use near_store::StoreCompiledContractCache;
use near_vm_runner::{get_contract_cache_key, VMKind};
use std::sync::Arc;
use testlib::runtime_utils::{alice_account, bob_account};

use super::*;

const GAS_PRICE: Balance = 5000;

fn to_yocto(near: Balance) -> Balance {
Expand Down

0 comments on commit a7868e8

Please sign in to comment.