Skip to content

Commit

Permalink
Enable floats but prohibit some CPU architectures (#1941)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
* Merge branch 'staging' into enable_floats
* Nit
  • Loading branch information
MaksymZavershynskyi authored and nearprotocol-bulldozer[bot] committed Jan 14, 2020
1 parent 08ea611 commit cddfcb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion runtime/near-vm-logic/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

// ################
Expand Down
4 changes: 1 addition & 3 deletions runtime/near-vm-runner/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ impl<'a> ContractModule<'a> {

fn inject_gas_metering(self) -> Result<Self, PrepareError> {
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 })
Expand Down
6 changes: 6 additions & 0 deletions runtime/near-vm-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub fn run<'a>(
fees_config: &'a RuntimeFeesConfig,
promise_results: &'a [PromiseResult],
) -> (Option<VMOutcome>, Option<VMError>) {
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,
Expand Down

0 comments on commit cddfcb4

Please sign in to comment.