Skip to content

Commit

Permalink
Merge #4387
Browse files Browse the repository at this point in the history
4387: Lower chainspec control flow costs. r=AlexanderLimonov a=mpapierski

This lowers the gas costs for `br`, `br_if`, `br_table`, `call`, and `call_indirect` costs. The researched value is lower than current costs, and also secure for the upcoming 16-second blocks. The impact on NFT contract:

measurement | cost before | costs modified | impact
-- | -- | -- | --
install_cost | 268614304810 | 254901355810 | 94.89%
second_mint_gas_costs | 12184348140 | 2536357140 | 20.82%
third_mint_gas_costs | 12184348140 | 2536357140 | 20.82%
reverse_lookup_gas_cost | 269147109850 | 255096390850 | 94.78%
no_lookup_gas_cost | 268364628780 | 254799495780 | 94.95%
reverse_lookup_gas_cost | 269147110490 | 255096391490 | 94.78%
no_lookup_gas_cost | 268364628780 | 254799495780 | 94.95%
second_transfer_gas_cost | 19648823480 | 3936857480 | 20.04%
third_transfer_gas_cost | 19648823480 | 3936857480 | 20.04%

The operating expenses are cheaper (mint, transfer) at around 80%, while the upfront costs for installation are about ~5% cheaper.

Co-authored-by: Michał Papierski <michal@casperlabs.io>
  • Loading branch information
casperlabs-bors-ng[bot] and Michał Papierski authored Oct 31, 2023
2 parents be8e93c + 8f917d2 commit 913fc2e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions execution_engine/src/shared/opcode_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ pub const DEFAULT_CONTROL_FLOW_ELSE_OPCODE: u32 = 440;
/// Default cost of the `end` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_END_OPCODE: u32 = 440;
/// Default cost of the `br` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_BR_OPCODE: u32 = 440_000;
pub const DEFAULT_CONTROL_FLOW_BR_OPCODE: u32 = 35_000;
/// Default cost of the `br_if` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_BR_IF_OPCODE: u32 = 440_000;
pub const DEFAULT_CONTROL_FLOW_BR_IF_OPCODE: u32 = 35_000;
/// Default cost of the `return` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_RETURN_OPCODE: u32 = 440;
/// Default cost of the `select` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_SELECT_OPCODE: u32 = 440;
/// Default cost of the `call` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_CALL_OPCODE: u32 = 140_000;
pub const DEFAULT_CONTROL_FLOW_CALL_OPCODE: u32 = 68_000;
/// Default cost of the `call_indirect` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_CALL_INDIRECT_OPCODE: u32 = 140_000;
pub const DEFAULT_CONTROL_FLOW_CALL_INDIRECT_OPCODE: u32 = 68_000;
/// Default cost of the `drop` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_DROP_OPCODE: u32 = 440;
/// Default fixed cost of the `br_table` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE: u32 = 440_000;
pub const DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE: u32 = 35_000;
/// Default multiplier for the size of targets in `br_table` Wasm opcode.
pub const DEFAULT_CONTROL_FLOW_BR_TABLE_MULTIPLIER: u32 = 100;

Expand Down
10 changes: 5 additions & 5 deletions resources/local/chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ loop = 440
if = 440
else = 440
end = 440
br = 440_000
br_if = 440_000
br = 35_000
br_if = 35_000
return = 440
select = 440
call = 140_000
call_indirect = 140_000
call = 68_000
call_indirect = 68_000
drop = 440

[wasm.opcode_costs.control_flow.br_table]
# Fixed cost per `br_table` opcode
cost = 440_000
cost = 35_000
# Size of target labels in the `br_table` opcode will be multiplied by `size_multiplier`
size_multiplier = 100

Expand Down
14 changes: 7 additions & 7 deletions resources/production/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ era_duration = '120 minutes'
# minimum height.
minimum_era_height = 20
# Minimum difference between a block's and its child's timestamp.
minimum_block_time = '32768 ms'
minimum_block_time = '16384 ms'
# Number of slots available in validator auction.
validator_slots = 100
# A number between 0 and 1 representing the fault tolerance threshold as a fraction, used by the internal finalizer.
Expand Down Expand Up @@ -135,7 +135,7 @@ block_max_transfer_count = 1250
# The maximum number of approvals permitted in a single block.
block_max_approval_count = 2600
# The upper limit of total gas of all deploys in a block.
block_gas_limit = 10_000_000_000_000
block_gas_limit = 4_000_000_000_000
# The limit of length of serialized payment code arguments.
payment_args_max_length = 1024
# The limit of length of serialized session code arguments.
Expand Down Expand Up @@ -194,17 +194,17 @@ loop = 440
if = 440
else = 440
end = 440
br = 440_000
br_if = 440_000
br = 35_000
br_if = 35_000
return = 440
select = 440
call = 140_000
call_indirect = 140_000
call = 68_000
call_indirect = 68_000
drop = 440

[wasm.opcode_costs.control_flow.br_table]
# Fixed cost per `br_table` opcode
cost = 440_000
cost = 35_000
# Size of target labels in the `br_table` opcode will be multiplied by `size_multiplier`
size_multiplier = 100

Expand Down

0 comments on commit 913fc2e

Please sign in to comment.