From 5eaeb4acb549c73e2bef1cb5b8d6ac9d7ea0291a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Papierski?= Date: Thu, 12 Dec 2024 12:14:47 +0000 Subject: [PATCH] Update wasm lanes and opcode costs --- execution_engine/src/bin/run_wasm.rs | 33 ++++++--- .../tests/src/test/explorer/faucet.rs | 8 +-- resources/local/chainspec.toml.in | 67 +++++++++--------- resources/production/chainspec.toml | 69 ++++++++++--------- types/src/chainspec/vm_config/opcode_costs.rs | 58 ++++++++-------- 5 files changed, 127 insertions(+), 108 deletions(-) diff --git a/execution_engine/src/bin/run_wasm.rs b/execution_engine/src/bin/run_wasm.rs index 0747f1b2de..98cad6e9c9 100644 --- a/execution_engine/src/bin/run_wasm.rs +++ b/execution_engine/src/bin/run_wasm.rs @@ -33,14 +33,17 @@ struct RunWasmInfo { fn run_wasm( module_bytes: Vec, + cli_args: &Args, chainspec: &ChainspecConfig, func_name: &str, - args: &[String], ) -> ( Result, casper_wasmi::Error>, RunWasmInfo, ) { - println!("Invoke export {:?} with args {:?}", func_name, args); + println!( + "Invoke export {:?} with args {:?}", + func_name, cli_args.args + ); let instance = prepare_instance(&module_bytes, chainspec); @@ -51,9 +54,13 @@ fn run_wasm( }; let args = { - assert_eq!(args.len(), params.len(), "Not enough arguments supplied"); + assert_eq!( + cli_args.args.len(), + params.len(), + "Not enough arguments supplied" + ); let mut vec = Vec::new(); - for (input_arg, func_arg) in args.iter().zip(params.into_iter()) { + for (input_arg, func_arg) in cli_args.args.iter().zip(params.into_iter()) { let value = match func_arg { casper_wasmi::ValueType::I32 => { casper_wasmi::RuntimeValue::I32(input_arg.parse().unwrap()) @@ -71,7 +78,11 @@ fn run_wasm( let start = Instant::now(); - let mut externals = MinimalWasmiExternals::new(0, chainspec.transaction_config.block_gas_limit); + let gas_limit = cli_args + .gas_limit + .unwrap_or(chainspec.transaction_config.block_gas_limit); + + let mut externals = MinimalWasmiExternals::new(0, gas_limit); let result: Result, casper_wasmi::Error> = instance .clone() @@ -87,11 +98,13 @@ fn run_wasm( use clap::Parser; use serde::Deserialize; -#[derive(Parser, Debug)] +#[derive(Parser, Clone, Debug)] #[command(author, version, about, long_about = None)] struct Args { #[arg(value_name = "MODULE")] wasm_file: PathBuf, + #[arg(long = "gas_limit")] + gas_limit: Option, #[arg(long = "invoke", value_name = "FUNCTION")] invoke: Option, /// Arguments given to the Wasm module or the invoked function. @@ -130,16 +143,16 @@ struct ChainspecConfig { fn main() { let args = Args::parse(); - let chainspec_file = args.chainspec_file.expect("chainspec file"); + let chainspec_file = args.clone().chainspec_file.expect("chainspec file"); println!("Using chainspec file {:?}", chainspec_file.display()); let chainspec_data = fs::read_to_string(chainspec_file.as_path()).expect("valid file"); let chainspec_config: ChainspecConfig = toml::from_str(&chainspec_data).expect("valid chainspec"); - let wasm_bytes = load_wasm_file(args.wasm_file); + let wasm_bytes = load_wasm_file(&args.wasm_file); - if let Some(func_name) = args.invoke { - let (result, info) = run_wasm(wasm_bytes, &chainspec_config, &func_name, &args.args); + if let Some(ref func_name) = args.invoke { + let (result, info) = run_wasm(wasm_bytes, &args, &chainspec_config, &func_name); println!("result: {:?}", result); println!("elapsed: {:?}", info.elapsed); diff --git a/execution_engine_testing/tests/src/test/explorer/faucet.rs b/execution_engine_testing/tests/src/test/explorer/faucet.rs index fd3cba66f2..d191d808ff 100644 --- a/execution_engine_testing/tests/src/test/explorer/faucet.rs +++ b/execution_engine_testing/tests/src/test/explorer/faucet.rs @@ -663,13 +663,13 @@ fn faucet_costs() { // This test will fail if execution costs vary. The expected costs should not be updated // without understanding why the cost has changed. If the costs do change, it should be // reflected in the "Costs by Entry Point" section of the faucet crate's README.md. - const EXPECTED_FAUCET_INSTALL_COST: u64 = 144_782_774_054; + const EXPECTED_FAUCET_INSTALL_COST: u64 = 145_436_440_703; - const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 70_836_755; + const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 79_611_645; - const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_645_108_193; + const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_652_664_693; - const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_545_778_741; + const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_558_340_671; let installer_account = AccountHash::new([1u8; 32]); let user_account: AccountHash = AccountHash::new([2u8; 32]); diff --git a/resources/local/chainspec.toml.in b/resources/local/chainspec.toml.in index ebc014559b..a889b91b42 100644 --- a/resources/local/chainspec.toml.in +++ b/resources/local/chainspec.toml.in @@ -178,7 +178,7 @@ block_max_approval_count = 2600 # Maximum block size in bytes including transactions contained by the block. 0 means unlimited. max_block_size = 5_242_880 # The upper limit of total gas of all transactions in a block. -block_gas_limit = 200_000_000_000 +block_gas_limit = 1_625_000_000_000 # The minimum amount in motes for a valid native transfer. native_transfer_minimum_motes = 2_500_000_000 # The maximum value to which `transaction_acceptor.timestamp_leeway` can be set in the config.toml file. @@ -206,7 +206,10 @@ vm_casper_v2 = false native_mint_lane = [0, 2048, 1024, 2_500_000_000, 650] native_auction_lane = [1, 3096, 2048, 2_500_000_000, 145] install_upgrade_lane = [2, 1_048_576, 2048, 100_000_000_000, 1] -wasm_lanes = [[3, 344_064, 1024, 100_000_000_000, 3], [4, 172_032, 1024, 50_000_000_000, 7], [5, 12_288, 512, 2_500_000_000, 25]] +wasm_lanes = [ + [3, 344_064, 1024, 100_000_000_000, 1], + [4, 172_032, 1024, 50_000_000_000, 2], + [5, 12_288, 512, 2_500_000_000, 80]] [transactions.deploy] # The maximum number of Motes allowed to be spent during payment. 0 means unlimited. @@ -228,56 +231,56 @@ gas_per_byte = 1_117_587 [wasm.v1.opcode_costs] # Bit operations multiplier. -bit = 35 +bit = 105 # Arithmetic add operations multiplier. -add = 35 +add = 105 # Mul operations multiplier. -mul = 35 +mul = 105 # Div operations multiplier. -div = 35 +div = 105 # Memory load operation multiplier. -load = 35 +load = 105 # Memory store operation multiplier. -store = 35 +store = 105 # Const store operation multiplier. -const = 35 +const = 105 # Local operations multiplier. -local = 35 +local = 105 # Global operations multiplier. -global = 35 +global = 105 # Integer operations multiplier. -integer_comparison = 35 +integer_comparison = 105 # Conversion operations multiplier. -conversion = 35 +conversion = 105 # Unreachable operation multiplier. -unreachable = 35 +unreachable = 105 # Nop operation multiplier. -nop = 35 +nop = 105 # Get current memory operation multiplier. -current_memory = 35 -# Grow memory cost, per page (64kb). -grow_memory = 300 +current_memory = 105 +# Grow memory cost, per page (192kb). +grow_memory = 900 # Sign extension operations cost -sign = 35 +sign = 105 # Control flow operations multiplier. [wasm.v1.opcode_costs.control_flow] -block = 85 -loop = 85 -if = 35 -else = 35 -end = 35 -br = 555 -br_if = 170 -return = 35 -select = 35 -call = 75 -call_indirect = 90 -drop = 35 +block = 255 +loop = 255 +if = 105 +else = 105 +end = 105 +br = 1665 +br_if = 510 +return = 105 +select = 105 +call = 225 +call_indirect = 270 +drop = 105 [wasm.v1.opcode_costs.control_flow.br_table] # Fixed cost per `br_table` opcode -cost = 50 +cost = 150 # Size of target labels in the `br_table` opcode will be multiplied by `size_multiplier` size_multiplier = 100 diff --git a/resources/production/chainspec.toml b/resources/production/chainspec.toml index 91aa8483e9..78cad1b782 100644 --- a/resources/production/chainspec.toml +++ b/resources/production/chainspec.toml @@ -185,7 +185,7 @@ block_max_approval_count = 2600 # Maximum block size in bytes including transactions contained by the block. 0 means unlimited. max_block_size = 5_242_880 # The upper limit of total gas of all transactions in a block. -block_gas_limit = 200_000_000_000 +block_gas_limit = 1_625_000_000_000 # The minimum amount in motes for a valid native transfer. native_transfer_minimum_motes = 2_500_000_000 # The maximum value to which `transaction_acceptor.timestamp_leeway` can be set in the config.toml file. @@ -212,9 +212,12 @@ vm_casper_v2 = false # [3] -> Transaction gas limit size in bytes for a given transaction in a certain lane # [4] -> The maximum number of transactions the lane can contain native_mint_lane = [0, 2048, 1024, 2_500_000_000, 650] -native_auction_lane = [1, 3096, 2048, 2_500_000_000, 145] +native_auction_lane = [1, 3096, 2048, 2_500_000_000, 650] install_upgrade_lane = [2, 1_048_576, 2048, 100_000_000_000, 1] -wasm_lanes = [[3, 344_064, 1024, 100_000_000_000, 3], [4, 172_032, 1024, 50_000_000_000, 7], [5, 12_288, 512, 2_500_000_000, 25]] +wasm_lanes = [ + [3, 344_064, 1024, 100_000_000_000, 1], + [4, 172_032, 1024, 50_000_000_000, 2], + [5, 12_288, 512, 2_500_000_000, 80]] [transactions.deploy] # The maximum number of Motes allowed to be spent during payment. 0 means unlimited. @@ -236,56 +239,56 @@ gas_per_byte = 1_117_587 [wasm.v1.opcode_costs] # Bit operations multiplier. -bit = 35 +bit = 105 # Arithmetic add operations multiplier. -add = 35 +add = 105 # Mul operations multiplier. -mul = 35 +mul = 105 # Div operations multiplier. -div = 35 +div = 105 # Memory load operation multiplier. -load = 35 +load = 105 # Memory store operation multiplier. -store = 35 +store = 105 # Const store operation multiplier. -const = 35 +const = 105 # Local operations multiplier. -local = 35 +local = 105 # Global operations multiplier. -global = 35 +global = 105 # Integer operations multiplier. -integer_comparison = 35 +integer_comparison = 105 # Conversion operations multiplier. -conversion = 35 +conversion = 105 # Unreachable operation multiplier. -unreachable = 35 +unreachable = 105 # Nop operation multiplier. -nop = 35 +nop = 105 # Get current memory operation multiplier. -current_memory = 35 -# Grow memory cost, per page (64kb). -grow_memory = 300 +current_memory = 105 +# Grow memory cost, per page (192kb). +grow_memory = 900 # Sign extension operations cost -sign = 35 +sign = 105 # Control flow operations multiplier. [wasm.v1.opcode_costs.control_flow] -block = 85 -loop = 85 -if = 35 -else = 35 -end = 35 -br = 555 -br_if = 170 -return = 35 -select = 35 -call = 75 -call_indirect = 90 -drop = 35 +block = 255 +loop = 255 +if = 105 +else = 105 +end = 105 +br = 1665 +br_if = 510 +return = 105 +select = 105 +call = 225 +call_indirect = 270 +drop = 105 [wasm.v1.opcode_costs.control_flow.br_table] # Fixed cost per `br_table` opcode -cost = 50 +cost = 150 # Size of target labels in the `br_table` opcode will be multiplied by `size_multiplier` size_multiplier = 100 diff --git a/types/src/chainspec/vm_config/opcode_costs.rs b/types/src/chainspec/vm_config/opcode_costs.rs index 42ae6aab71..176b2a89ef 100644 --- a/types/src/chainspec/vm_config/opcode_costs.rs +++ b/types/src/chainspec/vm_config/opcode_costs.rs @@ -14,65 +14,65 @@ use serde::{Deserialize, Serialize}; use crate::bytesrepr::{self, FromBytes, ToBytes}; /// Default cost of the `bit` Wasm opcode. -pub const DEFAULT_BIT_COST: u32 = 35; +pub const DEFAULT_BIT_COST: u32 = 105; /// Default cost of the `add` Wasm opcode. -pub const DEFAULT_ADD_COST: u32 = 35; +pub const DEFAULT_ADD_COST: u32 = 105; /// Default cost of the `mul` Wasm opcode. -pub const DEFAULT_MUL_COST: u32 = 35; +pub const DEFAULT_MUL_COST: u32 = 105; /// Default cost of the `div` Wasm opcode. -pub const DEFAULT_DIV_COST: u32 = 35; +pub const DEFAULT_DIV_COST: u32 = 105; /// Default cost of the `load` Wasm opcode. -pub const DEFAULT_LOAD_COST: u32 = 35; +pub const DEFAULT_LOAD_COST: u32 = 105; /// Default cost of the `store` Wasm opcode. -pub const DEFAULT_STORE_COST: u32 = 35; +pub const DEFAULT_STORE_COST: u32 = 105; /// Default cost of the `const` Wasm opcode. -pub const DEFAULT_CONST_COST: u32 = 35; +pub const DEFAULT_CONST_COST: u32 = 105; /// Default cost of the `local` Wasm opcode. -pub const DEFAULT_LOCAL_COST: u32 = 35; +pub const DEFAULT_LOCAL_COST: u32 = 105; /// Default cost of the `global` Wasm opcode. -pub const DEFAULT_GLOBAL_COST: u32 = 35; +pub const DEFAULT_GLOBAL_COST: u32 = 105; /// Default cost of the `integer_comparison` Wasm opcode. -pub const DEFAULT_INTEGER_COMPARISON_COST: u32 = 35; +pub const DEFAULT_INTEGER_COMPARISON_COST: u32 = 105; /// Default cost of the `conversion` Wasm opcode. -pub const DEFAULT_CONVERSION_COST: u32 = 35; +pub const DEFAULT_CONVERSION_COST: u32 = 105; /// Default cost of the `unreachable` Wasm opcode. -pub const DEFAULT_UNREACHABLE_COST: u32 = 35; +pub const DEFAULT_UNREACHABLE_COST: u32 = 105; /// Default cost of the `nop` Wasm opcode. -pub const DEFAULT_NOP_COST: u32 = 35; +pub const DEFAULT_NOP_COST: u32 = 105; /// Default cost of the `current_memory` Wasm opcode. -pub const DEFAULT_CURRENT_MEMORY_COST: u32 = 35; +pub const DEFAULT_CURRENT_MEMORY_COST: u32 = 105; /// Default cost of the `grow_memory` Wasm opcode. -pub const DEFAULT_GROW_MEMORY_COST: u32 = 300; +pub const DEFAULT_GROW_MEMORY_COST: u32 = 900; /// Default cost of the `block` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_BLOCK_OPCODE: u32 = 85; +pub const DEFAULT_CONTROL_FLOW_BLOCK_OPCODE: u32 = 255; /// Default cost of the `loop` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_LOOP_OPCODE: u32 = 85; +pub const DEFAULT_CONTROL_FLOW_LOOP_OPCODE: u32 = 255; /// Default cost of the `if` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_IF_OPCODE: u32 = 35; +pub const DEFAULT_CONTROL_FLOW_IF_OPCODE: u32 = 105; /// Default cost of the `else` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_ELSE_OPCODE: u32 = 35; +pub const DEFAULT_CONTROL_FLOW_ELSE_OPCODE: u32 = 105; /// Default cost of the `end` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_END_OPCODE: u32 = 35; +pub const DEFAULT_CONTROL_FLOW_END_OPCODE: u32 = 105; /// Default cost of the `br` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_BR_OPCODE: u32 = 555; +pub const DEFAULT_CONTROL_FLOW_BR_OPCODE: u32 = 1665; /// Default cost of the `br_if` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_BR_IF_OPCODE: u32 = 170; +pub const DEFAULT_CONTROL_FLOW_BR_IF_OPCODE: u32 = 510; /// Default cost of the `return` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_RETURN_OPCODE: u32 = 35; +pub const DEFAULT_CONTROL_FLOW_RETURN_OPCODE: u32 = 105; /// Default cost of the `select` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_SELECT_OPCODE: u32 = 35; +pub const DEFAULT_CONTROL_FLOW_SELECT_OPCODE: u32 = 105; /// Default cost of the `call` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_CALL_OPCODE: u32 = 75; +pub const DEFAULT_CONTROL_FLOW_CALL_OPCODE: u32 = 225; /// Default cost of the `call_indirect` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_CALL_INDIRECT_OPCODE: u32 = 90; +pub const DEFAULT_CONTROL_FLOW_CALL_INDIRECT_OPCODE: u32 = 270; /// Default cost of the `drop` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_DROP_OPCODE: u32 = 35; +pub const DEFAULT_CONTROL_FLOW_DROP_OPCODE: u32 = 105; /// Default fixed cost of the `br_table` Wasm opcode. -pub const DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE: u32 = 50; +pub const DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE: u32 = 150; /// Default multiplier for the size of targets in `br_table` Wasm opcode. pub const DEFAULT_CONTROL_FLOW_BR_TABLE_MULTIPLIER: u32 = 100; /// Default cost of the sign extension opcodes -pub const DEFAULT_SIGN_COST: u32 = 35; +pub const DEFAULT_SIGN_COST: u32 = 105; /// Definition of a cost table for a Wasm `br_table` opcode. ///