From 84568e551f81dc203a31dbf9cbc8fc587ecb1edb Mon Sep 17 00:00:00 2001 From: Maksym Zavershynskyi <35039879+nearmax@users.noreply.github.com> Date: Mon, 13 Jan 2020 16:24:37 -0800 Subject: [PATCH] Enable floats but prohibit some CPU architectures (#1941) * Enable floats but prohibit some CPU architectures * Merge branch 'staging' into enable_floats * Merge refs/heads/staging into enable_floats * Avoid overflowing u32 during contract preparation (#1946) * Update runtime/near-vm-runner/src/runner.rs Co-Authored-By: Evgeny Kuzyakov * Merge branch 'staging' into enable_floats * Nit --- runtime/near-vm-logic/src/logic.rs | 3 ++- runtime/near-vm-runner/src/prepare.rs | 4 +--- runtime/near-vm-runner/src/runner.rs | 6 ++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/runtime/near-vm-logic/src/logic.rs b/runtime/near-vm-logic/src/logic.rs index f1bcfbf748b..b7f44a6f3f4 100644 --- a/runtime/near-vm-logic/src/logic.rs +++ b/runtime/near-vm-logic/src/logic.rs @@ -653,7 +653,8 @@ impl<'a> VMLogic<'a> { /// * If we exceed usage limit imposed on burnt gas returns `GasLimitExceeded`; /// * If we exceed the `prepaid_gas` then returns `GasExceeded`. pub fn gas(&mut self, gas_amount: u32) -> Result<()> { - self.gas_counter.deduct_gas(Gas::from(gas_amount), Gas::from(gas_amount)) + let value = Gas::from(gas_amount) * Gas::from(self.config.regular_op_cost); + self.gas_counter.deduct_gas(value, value) } // ################ diff --git a/runtime/near-vm-runner/src/prepare.rs b/runtime/near-vm-runner/src/prepare.rs index 7f489e382bc..9b5205bb7a8 100644 --- a/runtime/near-vm-runner/src/prepare.rs +++ b/runtime/near-vm-runner/src/prepare.rs @@ -56,9 +56,7 @@ impl<'a> ContractModule<'a> { fn inject_gas_metering(self) -> Result { let Self { module, config } = self; - let gas_rules = rules::Set::new(config.regular_op_cost, Default::default()) - .with_forbidden_floats() - .with_grow_cost(config.grow_mem_cost); + let gas_rules = rules::Set::new(1, Default::default()).with_grow_cost(config.grow_mem_cost); let module = pwasm_utils::inject_gas_counter(module, &gas_rules) .map_err(|_| PrepareError::GasInstrumentation)?; Ok(Self { module, config }) diff --git a/runtime/near-vm-runner/src/runner.rs b/runtime/near-vm-runner/src/runner.rs index be830cbb3fd..d4933db9ccb 100644 --- a/runtime/near-vm-runner/src/runner.rs +++ b/runtime/near-vm-runner/src/runner.rs @@ -48,6 +48,12 @@ pub fn run<'a>( fees_config: &'a RuntimeFeesConfig, promise_results: &'a [PromiseResult], ) -> (Option, Option) { + if !cfg!(target_arch = "x86") && !cfg!(target_arch = "x86_64") { + // TODO(#1940): Remove once NaN is standardized by the VM. + panic!( + "Execution of smart contracts is only supported for x86 and x86_64 CPU architectures." + ); + } if method_name.is_empty() { return ( None,