Skip to content

Commit

Permalink
Merge #4593
Browse files Browse the repository at this point in the history
4593: v1.5.6 merge to dev r=alsrdn a=alsrdn

Merge release v.1.5.6 to dev

Co-authored-by: Michał Papierski <michal@casperlabs.io>
Co-authored-by: Marc Brinkmann <marc@casperlabs.io>
Co-authored-by: Ed Hastings <ed@casperlabs.io>
Co-authored-by: Joe Sacher <321623+sacherjj@users.noreply.github.com>
Co-authored-by: Karan Dhareshwar <karan@casperlabs.io>
Co-authored-by: sacherjj <321623+sacherjj@users.noreply.github.com>
Co-authored-by: Fraser Hutchison <fraser@casperlabs.io>
Co-authored-by: casperlabs-bors-ng[bot] <82463608+casperlabs-bors-ng[bot]@users.noreply.github.com>
Co-authored-by: Bartłomiej Kamiński <bart@casperlabs.io>
  • Loading branch information
8 people authored Mar 8, 2024
2 parents 5b95c0d + aa2f7e3 commit bc43388
Show file tree
Hide file tree
Showing 62 changed files with 3,497 additions and 380 deletions.
22 changes: 15 additions & 7 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ test: test-rs-no-default-features test-rs test-as

.PHONY: test-contracts-rs
test-contracts-rs: build-contracts-rs
$(DISABLE_LOGGING) $(CARGO) test $(CARGO_FLAGS) -p casper-engine-tests -- --ignored
$(DISABLE_LOGGING) $(CARGO) test $(CARGO_FLAGS) -p casper-engine-tests -- --ignored --skip repeated_ffi_call_should_gas_out_quickly

.PHONY: test-contracts-timings
test-contracts-timings: build-contracts-rs
$(DISABLE_LOGGING) $(CARGO) test --release $(filter-out --release, $(CARGO_FLAGS)) -p casper-engine-tests -- --ignored --test-threads=1 repeated_ffi_call_should_gas_out_quickly

.PHONY: test-contracts-as
test-contracts-as: build-contracts-rs build-contracts-as
Expand Down
15 changes: 15 additions & 0 deletions execution_engine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ All notable changes to this project will be documented in this file. The format
[comment]: <> (Fixed: any bug fixes)
[comment]: <> (Security: in case of vulnerabilities)

## 7.0.1

### Changed
* Change the cost of `wasm.storage_costs.gas_per_byte` and `shared::storage_costs::DEFAULT_GAS_PER_BYTE_COST` from `630_000` to `1_117_587`.
* Change the cost of the host function `casper_add_associated_key` from `9_000` to `1_200_000`.
* Change the cost of the argument `entry_points_size` of host function `casper_add_contract_version` from `0` to `120_000`.
* Change the cost of the host function `casper_blake2b`and its argument `in_size` from `200` and `0` respectively to `1_200_000` to `120_000`.
* Change the cost of the host function `casper_call_contract` and its arguments `entry_point_name_size` and `runtime_args_size` from `4_500`, `0` and `420` respectively to `300_000_000`, `120_000` and `120_000`.
* Change the cost of the host function `casper_call_versioned_contract` and the arguments `entry_point_name_size` and `runtime_args_size` from `4_500`, `0` and `420` respectively to `300_000_000`, `120_000` and `120_000`.
* Change the cost of the host function `casper_get_balance` from `3_800` to `3_000_000`.
* Change the cost of arguments `name_size` and `dest_size` of host function `casper_get_named_arg` from `0` to `120_000`.
* Change the cost of the host function `casper_put_key` and its arguments `name_size` and `key_size` from `38_000`, `1_100` and `0` respectively to `100_000_000`, `120_000` and `120_000`.
* Change the cost of the host function `casper_read_value` and its argument `key_size` from `6_000` and `0` respectively to `60_000` and `120_000`.
* Change the cost of the argument `urefs_size` of host function `casper_remove_contract_user_group_urefs` from `0` to `120_000`.
* Change the cost of the host function `casper_transfer_from_purse_to_purse` from `82_000` to `82_000_000`.



Expand Down
2 changes: 1 addition & 1 deletion execution_engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casper-execution-engine"
version = "7.0.0" # when updating, also update 'html_root_url' in lib.rs
version = "7.0.1" # when updating, also update 'html_root_url' in lib.rs
authors = ["Henry Till <henrytill@gmail.com>", "Ed Hastings <ed@casperlabs.io>"]
edition = "2021"
description = "Casper execution engine crates."
Expand Down
6 changes: 6 additions & 0 deletions execution_engine/src/core/engine_state/engine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ impl EngineConfig {
pub fn fee_handling(&self) -> FeeHandling {
self.fee_handling
}

/// Sets the `wasm_config.max_memory` to `new_value`.
#[cfg(feature = "test-support")]
pub fn set_max_memory(&mut self, new_value: u32) {
self.wasm_config.max_memory = new_value;
}
}

/// A builder for an [`EngineConfig`].
Expand Down
13 changes: 8 additions & 5 deletions execution_engine/src/core/runtime/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use casper_types::{
use super::{args::Args, Error, Runtime};
use crate::{
core::resolvers::v1_function_index::FunctionIndex,
shared::host_function_costs::{Cost, HostFunction, DEFAULT_HOST_FUNCTION_NEW_DICTIONARY},
shared::host_function_costs::{Cost, HostFunction},
storage::global_state::StateReader,
};

Expand Down Expand Up @@ -562,6 +562,9 @@ where
existing_urefs_size,
output_size_ptr,
) = Args::parse(args)?;

// TODO - use `num_new_urefs` * costs for unit uref, assuming these aren't
// already charged.
self.charge_host_function_call(
&host_function_costs.create_contract_user_group,
[
Expand Down Expand Up @@ -837,6 +840,7 @@ where
// args(4) = output of size value of host bytes data
let (package_ptr, package_size, label_ptr, label_size, value_size_ptr) =
Args::parse(args)?;
// TODO - add cost for 1x unit uref, assuming this isn't already charged
self.charge_host_function_call(
&host_function_costs.provision_contract_user_group_uref,
[
Expand Down Expand Up @@ -954,10 +958,9 @@ where
// args(0) = pointer to output size (output param)
let (output_size_ptr,): (u32,) = Args::parse(args)?;

self.charge_host_function_call(
&DEFAULT_HOST_FUNCTION_NEW_DICTIONARY,
[output_size_ptr],
)?;
// TODO - dynamically calculate the size of the new data. Currently using
// hard-coded 33 which is correct as of now.
self.charge_host_function_call(&host_function_costs.new_uref, [0, 0, 33])?;
let ret = self.new_dictionary(output_size_ptr)?;
Ok(Some(RuntimeValue::I32(api_error::i32_from(ret))))
}
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The engine which executes smart contracts on the Casper network.

#![doc(html_root_url = "https://docs.rs/casper-execution-engine/7.0.0")]
#![doc(html_root_url = "https://docs.rs/casper-execution-engine/7.0.1")]
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/casper-network/casper-node/blob/dev/images/Casper_Logo_Favicon_48.png",
html_logo_url = "https://raw.githubusercontent.com/casper-network/casper-node/blob/dev/images/Casper_Logo_Favicon.png",
Expand Down
76 changes: 53 additions & 23 deletions execution_engine/src/shared/host_function_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ const NOT_USED: Cost = 0;
const DEFAULT_FIXED_COST: Cost = 200;

const DEFAULT_ADD_COST: u32 = 5_800;
const DEFAULT_ADD_ASSOCIATED_KEY_COST: u32 = 9_000;
const DEFAULT_ADD_ASSOCIATED_KEY_COST: u32 = 1_200_000;

const DEFAULT_CALL_CONTRACT_COST: u32 = 4_500;
const DEFAULT_CALL_CONTRACT_ARGS_SIZE_WEIGHT: u32 = 420;
const DEFAULT_CALL_CONTRACT_COST: u32 = 300_000_000;

const DEFAULT_CREATE_PURSE_COST: u32 = 2_500_000_000;
const DEFAULT_GET_BALANCE_COST: u32 = 3_800;
const DEFAULT_GET_BALANCE_COST: u32 = 3_000_000;
const DEFAULT_GET_BLOCKTIME_COST: u32 = 330;
const DEFAULT_GET_CALLER_COST: u32 = 380;
const DEFAULT_GET_KEY_COST: u32 = 2_000;
Expand All @@ -44,13 +43,13 @@ const DEFAULT_NEW_UREF_VALUE_SIZE_WEIGHT: u32 = 590;
const DEFAULT_PRINT_COST: u32 = 20_000;
const DEFAULT_PRINT_TEXT_SIZE_WEIGHT: u32 = 4_600;

const DEFAULT_PUT_KEY_COST: u32 = 38_000;
const DEFAULT_PUT_KEY_NAME_SIZE_WEIGHT: u32 = 1_100;
const DEFAULT_PUT_KEY_COST: u32 = 100_000_000;
const DEFAULT_PUT_KEY_NAME_SIZE_WEIGHT: u32 = 120_000;

const DEFAULT_READ_HOST_BUFFER_COST: u32 = 3_500;
const DEFAULT_READ_HOST_BUFFER_DEST_SIZE_WEIGHT: u32 = 310;

const DEFAULT_READ_VALUE_COST: u32 = 6_000;
const DEFAULT_READ_VALUE_COST: u32 = 60_000;
const DEFAULT_DICTIONARY_GET_COST: u32 = 5_500;
const DEFAULT_DICTIONARY_GET_KEY_SIZE_WEIGHT: u32 = 590;

Expand All @@ -65,21 +64,19 @@ const DEFAULT_RET_VALUE_SIZE_WEIGHT: u32 = 420_000;
const DEFAULT_REVERT_COST: u32 = 500;
const DEFAULT_SET_ACTION_THRESHOLD_COST: u32 = 74_000;
const DEFAULT_TRANSFER_FROM_PURSE_TO_ACCOUNT_COST: u32 = 2_500_000_000;
const DEFAULT_TRANSFER_FROM_PURSE_TO_PURSE_COST: u32 = 82_000;
const DEFAULT_TRANSFER_FROM_PURSE_TO_PURSE_COST: u32 = 82_000_000;
const DEFAULT_TRANSFER_TO_ACCOUNT_COST: u32 = 2_500_000_000;
const DEFAULT_UPDATE_ASSOCIATED_KEY_COST: u32 = 4_200;

const DEFAULT_WRITE_COST: u32 = 14_000;
const DEFAULT_WRITE_VALUE_SIZE_WEIGHT: u32 = 980;

const DEFAULT_ARG_CHARGE: u32 = 120_000;

const DEFAULT_DICTIONARY_PUT_COST: u32 = 9_500;
const DEFAULT_DICTIONARY_PUT_KEY_BYTES_SIZE_WEIGHT: u32 = 1_800;
const DEFAULT_DICTIONARY_PUT_VALUE_SIZE_WEIGHT: u32 = 520;

const DEFAULT_NEW_DICTIONARY_COST: u32 = DEFAULT_NEW_UREF_COST;

pub(crate) const DEFAULT_HOST_FUNCTION_NEW_DICTIONARY: HostFunction<[Cost; 1]> =
HostFunction::new(DEFAULT_NEW_DICTIONARY_COST, [NOT_USED]);
const DEFAULT_BLAKE2B_COST: u32 = 1_200_000;

/// Representation of a host function cost.
///
Expand Down Expand Up @@ -295,7 +292,10 @@ pub struct HostFunctionCosts {
impl Default for HostFunctionCosts {
fn default() -> Self {
Self {
read_value: HostFunction::fixed(DEFAULT_READ_VALUE_COST),
read_value: HostFunction::new(
DEFAULT_READ_VALUE_COST,
[NOT_USED, DEFAULT_ARG_CHARGE, NOT_USED],
),
dictionary_get: HostFunction::new(
DEFAULT_DICTIONARY_GET_COST,
[NOT_USED, DEFAULT_DICTIONARY_GET_KEY_SIZE_WEIGHT, NOT_USED],
Expand Down Expand Up @@ -345,7 +345,7 @@ impl Default for HostFunctionCosts {
NOT_USED,
DEFAULT_PUT_KEY_NAME_SIZE_WEIGHT,
NOT_USED,
NOT_USED,
DEFAULT_ARG_CHARGE,
],
),
remove_key: HostFunction::new(
Expand Down Expand Up @@ -382,17 +382,31 @@ impl Default for HostFunctionCosts {
),
create_contract_package_at_hash: HostFunction::default(),
create_contract_user_group: HostFunction::default(),
add_contract_version: HostFunction::default(),
add_contract_version: HostFunction::new(
200,
[
NOT_USED,
NOT_USED,
NOT_USED,
NOT_USED,
DEFAULT_ARG_CHARGE,
NOT_USED,
NOT_USED,
NOT_USED,
NOT_USED,
NOT_USED,
],
),
disable_contract_version: HostFunction::default(),
call_contract: HostFunction::new(
DEFAULT_CALL_CONTRACT_COST,
[
NOT_USED,
NOT_USED,
NOT_USED,
DEFAULT_ARG_CHARGE,
NOT_USED,
NOT_USED,
DEFAULT_CALL_CONTRACT_ARGS_SIZE_WEIGHT,
DEFAULT_ARG_CHARGE,
NOT_USED,
],
),
Expand All @@ -404,22 +418,38 @@ impl Default for HostFunctionCosts {
NOT_USED,
NOT_USED,
NOT_USED,
DEFAULT_ARG_CHARGE,
NOT_USED,
NOT_USED,
DEFAULT_CALL_CONTRACT_ARGS_SIZE_WEIGHT,
DEFAULT_ARG_CHARGE,
NOT_USED,
],
),
get_named_arg_size: HostFunction::default(),
get_named_arg: HostFunction::default(),
get_named_arg: HostFunction::new(
200,
[NOT_USED, DEFAULT_ARG_CHARGE, NOT_USED, DEFAULT_ARG_CHARGE],
),
remove_contract_user_group: HostFunction::default(),
provision_contract_user_group_uref: HostFunction::default(),
remove_contract_user_group_urefs: HostFunction::default(),
remove_contract_user_group_urefs: HostFunction::new(
200,
[
NOT_USED,
NOT_USED,
NOT_USED,
NOT_USED,
NOT_USED,
DEFAULT_ARG_CHARGE,
],
),
print: HostFunction::new(
DEFAULT_PRINT_COST,
[NOT_USED, DEFAULT_PRINT_TEXT_SIZE_WEIGHT],
),
blake2b: HostFunction::default(),
blake2b: HostFunction::new(
DEFAULT_BLAKE2B_COST,
[NOT_USED, DEFAULT_ARG_CHARGE, NOT_USED, NOT_USED],
),
random_bytes: HostFunction::default(),
enable_contract_version: HostFunction::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/shared/storage_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use casper_types::{
};

/// Default gas cost per byte stored.
pub const DEFAULT_GAS_PER_BYTE_COST: u32 = 630_000;
pub const DEFAULT_GAS_PER_BYTE_COST: u32 = 1_117_587;

/// Represents a cost table for storage costs.
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug, DataSize)]
Expand Down
10 changes: 10 additions & 0 deletions execution_engine_testing/test_support/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ All notable changes to this project will be documented in this file. The format



## 7.0.1

### Added
* Provide `from_chainspec_path` and `max_associated_keys` helper methods on `ChainspecConfig`.
* Provide functions for converting from `ChainspecConfig` to `EngineConfig`.
* Provide `try_exec` method on `WamTestBuilder` for fallible contract execution.
* Provide `PRODUCTION_CHAINSPEC_PATH`: a lazy static defining the path to the production chainspec.toml file.



## 7.0.0

### Added
Expand Down
4 changes: 2 additions & 2 deletions execution_engine_testing/test_support/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casper-engine-test-support"
version = "7.0.0" # when updating, also update 'html_root_url' in lib.rs
version = "7.0.1" # when updating, also update 'html_root_url' in lib.rs
authors = ["Fraser Hutchison <fraser@casperlabs.io>"]
edition = "2021"
description = "Library to support testing of Wasm smart contracts for use on the Casper network."
Expand All @@ -11,7 +11,7 @@ repository = "https://github.com/CasperLabs/casper-node/tree/master/execution_en
license = "Apache-2.0"

[dependencies]
casper-execution-engine = { version = "7.0.0", path = "../../execution_engine", features = ["test-support"] }
casper-execution-engine = { version = "7.0.1", path = "../../execution_engine", features = ["test-support"] }
casper-hashing = { version = "3.0.0", path = "../../hashing" }
casper-types = { version = "4.0.1", path = "../../types" }
humantime = "2"
Expand Down
Loading

0 comments on commit bc43388

Please sign in to comment.