From 79590b2eb5cfb65d65eb2b7d729500b6f25b6f90 Mon Sep 17 00:00:00 2001 From: playXE Date: Thu, 25 Jul 2024 14:22:14 +0700 Subject: [PATCH 1/2] chore(gtest): Update gtest weights to match onchain weights --- gtest/src/lib.rs | 32 +++++++++++++++++++++++++++----- gtest/src/manager.rs | 17 +++++++++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/gtest/src/lib.rs b/gtest/src/lib.rs index 4c42b9b5312..7a60fb6c139 100644 --- a/gtest/src/lib.rs +++ b/gtest/src/lib.rs @@ -487,13 +487,13 @@ pub mod constants { /// Extra amount of blocks must be reserved for storing in storage. pub const RESERVE_FOR: Block = 1; /// Cost of read access into storage. - pub const READ_COST: Gas = 25; + pub const READ_COST: Gas = 25000000; /// Per-byte extra cost of read access into storage. - pub const READ_PER_BYTE_COST: Gas = 10; + pub const READ_PER_BYTE_COST: Gas = 584; /// Cost of write access into storage. - pub const WRITE_COST: Gas = 100; + pub const WRITE_COST: Gas = 100000000; /// Per-byte extra cost of write access into storage. - pub const WRITE_PER_BYTE_COST: Gas = 10; + pub const WRITE_PER_BYTE_COST: Gas = 97656; /* Rent-related constants */ @@ -517,7 +517,7 @@ pub mod constants { pub const MODULE_DATA_SECTION_INSTANTIATION_BYTE_COST: Gas = 452; /// Cost of wasm module global section instantiation before execution per /// byte of code. - pub const MODULE_GLOBAL_SECTION_INSTANTIATION_BYTE_COST: Gas = 2360; + pub const MODULE_GLOBAL_SECTION_INSTANTIATION_BYTE_COST: Gas = 2359; /// Cost of wasm module table section instantiation before execution per /// byte of code. pub const MODULE_TABLE_SECTION_INSTANTIATION_BYTE_COST: Gas = 350; @@ -533,4 +533,26 @@ pub mod constants { pub const MODULE_INSTRUMENTATION_BYTE_COST: Gas = 13; /// Initial random seed for testing environment. pub const INITIAL_RANDOM_SEED: u64 = 42; + + /* Memory-related constants */ + /// Memory grow cost. + pub const MEM_GROW_COST: usize = 810343; + /// Memory grow per page cost. + pub const MEM_GROW_PER_PAGE_COST: usize = 0; + /* Lazy pages related constants */ + + /// First read page access cost. + pub const SIGNAL_READ_COST: Gas = 28385632; + /// First write page access cost. + pub const SIGNAL_WRITE_COST: Gas = 137635397; + /// First read page access cost for page, which has been already read accessed. + pub const SIGNAL_WRITE_AFTER_READ_COST: Gas = 112552575; + /// First read page access cost from host function call. + pub const HOST_FUNC_READ_COST: Gas = 31201248; + /// First write page access cost from host function call. + pub const HOST_FUNC_WRITE_COST: Gas = 141387608; + /// First write page access cost from host function call. + pub const HOST_FUNC_WRITE_AFTER_READ_COST: Gas = 115129057; + /// Loading page data from storage cost. + pub const LOAD_PAGE_STORAGE_DATA_COST: Gas = 10630903; } diff --git a/gtest/src/manager.rs b/gtest/src/manager.rs index 85e3174d981..d97c375dba3 100644 --- a/gtest/src/manager.rs +++ b/gtest/src/manager.rs @@ -23,13 +23,14 @@ use crate::{ mailbox::MailboxManager, program::{Gas, WasmProgram}, Result, TestError, DISPATCH_HOLD_COST, EPOCH_DURATION_IN_BLOCKS, EXISTENTIAL_DEPOSIT, - GAS_ALLOWANCE, INITIAL_RANDOM_SEED, MAILBOX_THRESHOLD, MAX_RESERVATIONS, + GAS_ALLOWANCE, HOST_FUNC_READ_COST, HOST_FUNC_WRITE_AFTER_READ_COST, HOST_FUNC_WRITE_COST, + INITIAL_RANDOM_SEED, LOAD_PAGE_STORAGE_DATA_COST, MAILBOX_THRESHOLD, MAX_RESERVATIONS, MODULE_CODE_SECTION_INSTANTIATION_BYTE_COST, MODULE_DATA_SECTION_INSTANTIATION_BYTE_COST, MODULE_ELEMENT_SECTION_INSTANTIATION_BYTE_COST, MODULE_GLOBAL_SECTION_INSTANTIATION_BYTE_COST, MODULE_INSTRUMENTATION_BYTE_COST, MODULE_INSTRUMENTATION_COST, MODULE_TABLE_SECTION_INSTANTIATION_BYTE_COST, MODULE_TYPE_SECTION_INSTANTIATION_BYTE_COST, - READ_COST, READ_PER_BYTE_COST, RESERVATION_COST, RESERVE_FOR, VALUE_PER_GAS, WAITLIST_COST, - WRITE_COST, + READ_COST, READ_PER_BYTE_COST, RESERVATION_COST, RESERVE_FOR, SIGNAL_READ_COST, + SIGNAL_WRITE_AFTER_READ_COST, SIGNAL_WRITE_COST, VALUE_PER_GAS, WAITLIST_COST, WRITE_COST, }; use core_processor::{ common::*, @@ -870,7 +871,15 @@ impl ExtManager { mem_grow: Default::default(), mem_grow_per_page: Default::default(), }, - lazy_pages: LazyPagesCosts::default(), + lazy_pages: LazyPagesCosts { + host_func_read: HOST_FUNC_READ_COST.into(), + host_func_write: HOST_FUNC_WRITE_COST.into(), + host_func_write_after_read: HOST_FUNC_WRITE_AFTER_READ_COST.into(), + load_page_storage_data: LOAD_PAGE_STORAGE_DATA_COST.into(), + signal_read: SIGNAL_READ_COST.into(), + signal_write: SIGNAL_WRITE_COST.into(), + signal_write_after_read: SIGNAL_WRITE_AFTER_READ_COST.into(), + }, read: READ_COST.into(), read_per_byte: READ_PER_BYTE_COST.into(), write: WRITE_COST.into(), From a5348ef77a7fcb04a56a7db28d1de0634b5a19ae Mon Sep 17 00:00:00 2001 From: playXE Date: Thu, 25 Jul 2024 16:26:58 +0700 Subject: [PATCH 2/2] fix formatting --- gtest/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gtest/src/lib.rs b/gtest/src/lib.rs index 7a60fb6c139..8ab24a851c6 100644 --- a/gtest/src/lib.rs +++ b/gtest/src/lib.rs @@ -545,7 +545,8 @@ pub mod constants { pub const SIGNAL_READ_COST: Gas = 28385632; /// First write page access cost. pub const SIGNAL_WRITE_COST: Gas = 137635397; - /// First read page access cost for page, which has been already read accessed. + /// First read page access cost for page, which has been already read + /// accessed. pub const SIGNAL_WRITE_AFTER_READ_COST: Gas = 112552575; /// First read page access cost from host function call. pub const HOST_FUNC_READ_COST: Gas = 31201248;