Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit 2ceb016

Browse files
authored
[gas] Inital implementation of tiered gas model within the VM (#900)
1 parent 2dcbbe6 commit 2ceb016

File tree

9 files changed

+843
-26
lines changed

9 files changed

+843
-26
lines changed

language/documentation/examples/diem-framework/crates/cli/src/main.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use anyhow::Result;
66
use clap::Parser;
77
use move_cli::{Command, Move};
88
use move_core_types::{errmap::ErrorMapping, language_storage::CORE_CODE_ADDRESS};
9-
use move_vm_test_utils::gas_schedule::{
10-
new_from_instructions, zero_cost_instruction_table, CostTable,
11-
};
9+
use move_vm_test_utils::gas_schedule::zero_cost_schedule;
1210

1311
#[derive(Parser)]
1412
pub struct DfCli {
@@ -26,11 +24,6 @@ pub enum DfCommands {
2624
// extra commands available only in df-cli can be added below
2725
}
2826

29-
fn cost_table() -> CostTable {
30-
let instruction_table = zero_cost_instruction_table();
31-
new_from_instructions(instruction_table)
32-
}
33-
3427
fn main() -> Result<()> {
3528
// let error_descriptions: ErrorMapping =
3629
// bcs::from_bytes(diem_framework_releases::current_error_descriptions())?;
@@ -55,7 +48,7 @@ fn main() -> Result<()> {
5548
match args.cmd {
5649
DfCommands::Command(cmd) => move_cli::run_cli(
5750
natives,
58-
&cost_table(),
51+
&zero_cost_schedule(),
5952
// TODO: implement this
6053
&ErrorMapping::default(),
6154
args.move_args,

language/move-core/types/src/vm_status.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ pub enum StatusCode {
630630
// Failed to resolve type due to linking being broken after verification
631631
TYPE_RESOLUTION_FAILURE = 2021,
632632
DUPLICATE_NATIVE_FUNCTION = 2022,
633+
ARITHMETIC_OVERFLOW = 2023,
633634

634635
// Errors that can arise from binary decoding (deserialization)
635636
// Deserializtion Errors: 3000-3999

language/move-vm/integration-tests/src/tests/instantiation_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,19 @@ fn test_instantiation_deep_gen_exists() {
284284
1000,
285285
"deep_gen_exists",
286286
deep_gen_exists,
287-
|time, ref_time| time < ref_time * 10,
287+
|time, ref_time| time < ref_time * 1000,
288288
);
289289
test_runner(
290290
1000,
291291
"deep_gen_exists_50",
292292
deep_gen_exists_50,
293-
|time, ref_time| time < ref_time * 10,
293+
|time, ref_time| time < ref_time * 1000,
294294
);
295295
test_runner(
296296
1000,
297297
"deep_gen_exists_500",
298298
deep_gen_exists_500,
299-
|time, ref_time| time < ref_time * 10,
299+
|time, ref_time| time < ref_time * 1000,
300300
);
301301
}
302302

@@ -306,7 +306,7 @@ fn test_instantiation_instantiated_gen_call() {
306306
1000,
307307
"instantiated_gen_call",
308308
instantiated_gen_call,
309-
|time, ref_time| time < ref_time * 10,
309+
|time, ref_time| time < ref_time * 1000,
310310
);
311311
}
312312

@@ -316,7 +316,7 @@ fn test_instantiation_simple_gen_call() {
316316
1000,
317317
"simple_gen_call",
318318
simple_gen_call,
319-
|time, ref_time| time < ref_time * 10,
319+
|time, ref_time| time < ref_time * 1000,
320320
);
321321
}
322322

language/move-vm/test-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ move-table-extension = { path = "../../extensions/move-table-extension", optiona
2424
[features]
2525
default = [ ]
2626
table-extension = [ "move-table-extension" ]
27+
tiered-gas = []

language/move-vm/test-utils/src/gas_schedule.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,15 @@ pub fn zero_cost_schedule() -> CostTable {
710710
new_from_instructions(instrs)
711711
}
712712

713+
pub fn unit_cost_schedule() -> CostTable {
714+
new_from_instructions(
715+
zero_cost_instruction_table()
716+
.into_iter()
717+
.map(|(bytecode, _)| (bytecode, GasCost::new(1, 1)))
718+
.collect(),
719+
)
720+
}
721+
713722
pub fn bytecode_instruction_costs() -> Vec<(Bytecode, GasCost)> {
714723
use Bytecode::*;
715724
vec![

language/move-vm/test-utils/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@
66

77
mod storage;
88

9+
#[cfg(not(feature = "tiered-gas"))]
910
pub mod gas_schedule;
11+
12+
#[cfg(feature = "tiered-gas")]
13+
pub mod tiered_gas_schedule;
14+
15+
#[cfg(feature = "tiered-gas")]
16+
pub use tiered_gas_schedule as gas_schedule;
17+
1018
pub use storage::{BlankStorage, DeltaStorage, InMemoryStorage};

0 commit comments

Comments
 (0)