Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wasm lanes and opcode costs #5022

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions execution_engine/src/bin/run_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ struct RunWasmInfo {

fn run_wasm(
module_bytes: Vec<u8>,
cli_args: &Args,
chainspec: &ChainspecConfig,
func_name: &str,
args: &[String],
) -> (
Result<Option<RuntimeValue>, 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);

Expand All @@ -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())
Expand All @@ -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<Option<RuntimeValue>, casper_wasmi::Error> =
instance
.clone()
Expand All @@ -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<u64>,
#[arg(long = "invoke", value_name = "FUNCTION")]
invoke: Option<String>,
/// Arguments given to the Wasm module or the invoked function.
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions execution_engine_testing/tests/src/test/explorer/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
67 changes: 35 additions & 32 deletions resources/local/chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down
69 changes: 36 additions & 33 deletions resources/production/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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

Expand Down
Loading
Loading