Skip to content

Commit 5bef1c5

Browse files
committed
Change gas
1 parent 7b3a911 commit 5bef1c5

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

contracts/hackatom/tests/integration.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fn execute_allocate_large_memory() {
412412
// Gas consumption is relatively small
413413
// Note: the exact gas usage depends on the Rust version used to compile Wasm,
414414
// which we only fix when using rust-optimizer, not integration tests.
415-
assert_approx_eq!(gas_used, 4413600, "0.2");
415+
assert_approx_eq!(gas_used, 9470400, "0.2");
416416
let used = deps.memory_pages();
417417
assert_eq!(used, pages_before + 48, "Memory used: {used} pages");
418418
pages_before += 48;
@@ -431,7 +431,7 @@ fn execute_allocate_large_memory() {
431431
// Gas consumption is relatively small
432432
// Note: the exact gas usage depends on the Rust version used to compile Wasm,
433433
// which we only fix when using rust-optimizer, not integration tests.
434-
let expected = 4859700; // +/- 20%
434+
let expected = 9553320; // +/- 20%
435435
assert!(gas_used > expected * 80 / 100, "Gas used: {gas_used}");
436436
assert!(gas_used < expected * 120 / 100, "Gas used: {gas_used}");
437437
let used = deps.memory_pages();

packages/vm/src/instance.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ mod tests {
858858

859859
let report2 = instance.create_gas_report();
860860
assert_eq!(report2.used_externally, 251);
861-
assert_eq!(report2.used_internally, 8461548);
861+
assert_eq!(report2.used_internally, 15479658);
862862
assert_eq!(report2.limit, LIMIT);
863863
assert_eq!(
864864
report2.remaining,
@@ -1049,7 +1049,7 @@ mod tests {
10491049
.unwrap();
10501050

10511051
let init_used = orig_gas - instance.get_gas_left();
1052-
assert_eq!(init_used, 8461799);
1052+
assert_eq!(init_used, 15479909);
10531053
}
10541054

10551055
#[test]
@@ -1074,7 +1074,7 @@ mod tests {
10741074
.unwrap();
10751075

10761076
let execute_used = gas_before_execute - instance.get_gas_left();
1077-
assert_eq!(execute_used, 11181706);
1077+
assert_eq!(execute_used, 20477581);
10781078
}
10791079

10801080
#[test]
@@ -1117,6 +1117,6 @@ mod tests {
11171117
);
11181118

11191119
let query_used = gas_before_query - instance.get_gas_left();
1120-
assert_eq!(query_used, 7142556);
1120+
assert_eq!(query_used, 12737176);
11211121
}
11221122
}

packages/vm/src/wasm_backend/engine.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,27 @@ use super::limiting_tunables::LimitingTunables;
2020
/// https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md
2121
const MAX_WASM_PAGES: u32 = 65536;
2222

23-
fn cost(_operator: &Operator) -> u64 {
23+
fn cost(operator: &Operator) -> u64 {
2424
// A flat fee for each operation
2525
// The target is 1 Teragas per second (see GAS.md).
2626
//
2727
// In https://github.com/CosmWasm/cosmwasm/pull/1042 a profiler is developed to
2828
// identify runtime differences between different Wasm operation, but this is not yet
2929
// precise enough to derive insights from it.
30-
150
30+
const GAS_PER_OPERATION: u64 = 115;
31+
32+
match operator {
33+
Operator::Loop { .. }
34+
| Operator::End
35+
| Operator::Else
36+
| Operator::Br { .. }
37+
| Operator::BrTable { .. }
38+
| Operator::BrIf { .. }
39+
| Operator::Call { .. }
40+
| Operator::CallIndirect { .. }
41+
| Operator::Return => GAS_PER_OPERATION * 14,
42+
_ => GAS_PER_OPERATION,
43+
}
3144
}
3245

3346
/// Creates an engine without a compiler.

0 commit comments

Comments
 (0)