From 2392b0dccca6b4548fd23ab33ba46baa493ca5d1 Mon Sep 17 00:00:00 2001 From: green Date: Wed, 2 Aug 2023 19:08:02 +0100 Subject: [PATCH 1/3] Actualization of the gas prices for the `fuel-core 0.20` release --- CHANGELOG.md | 9 ++ .../gas/default_gas_costs.rs | 94 +++++++++---------- fuel-vm/src/interpreter/flow/tests.rs | 36 +++---- fuel-vm/src/interpreter/gas.rs | 2 +- fuel-vm/src/interpreter/gas/tests.rs | 8 +- 5 files changed, 79 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447af40d1b..7762ed5a10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [#527](https://github.com/FuelLabs/fuel-vm/pull/527): The balances are empty during predicate estimation/verification. +## [Version 0.35.2] + +### Changed + +#### Breaking + +- [#538](https://github.com/FuelLabs/fuel-vm/pull/538/): Rollbacked the change for the gas charging formula. + Actualized the gas prices for opcodes. + ## [Version 0.35.1] ### Added diff --git a/fuel-tx/src/transaction/consensus_parameters/gas/default_gas_costs.rs b/fuel-tx/src/transaction/consensus_parameters/gas/default_gas_costs.rs index 50b9f08822..cc82ddd0f8 100644 --- a/fuel-tx/src/transaction/consensus_parameters/gas/default_gas_costs.rs +++ b/fuel-tx/src/transaction/consensus_parameters/gas/default_gas_costs.rs @@ -1,25 +1,25 @@ use super::*; /// File generated by fuel-core: benches/src/bin/collect.rs:440. With the following git /// hash -pub const GIT: &str = "9f1cecfbf8bd316e86f2359bb09813304d9e0986"; -pub const fn default_gas_costs() -> GasCostsValues { +pub const GIT: &str = "98341e564b75d1157e61d7d5f38612f6224a5b30"; +pub fn default_gas_costs() -> GasCostsValues { GasCostsValues { add: 1, addi: 1, aloc: 1, and: 1, andi: 1, - bal: 22, + bal: 13, bhei: 1, bhsh: 1, - burn: 126, + burn: 132, cb: 1, cfei: 1, cfsi: 1, - croo: 20, + croo: 16, div: 1, divi: 1, - eck1: 1592, + eck1: 951, ecr1: 3000, ed19: 3000, eq: 1, @@ -40,16 +40,16 @@ pub const fn default_gas_costs() -> GasCostsValues { jnzb: 1, jnef: 1, jneb: 1, - k256: 16, + k256: 11, lb: 1, - log: 43, + log: 9, lt: 1, lw: 1, - mcpi: 3, - mint: 127, + mcpi: 33, + mint: 135, mlog: 1, srwq: DependentCost { - base: 44, + base: 47, dep_per_unit: 5, }, modi: 1, @@ -64,83 +64,83 @@ pub const fn default_gas_costs() -> GasCostsValues { or: 1, ori: 1, move_op: 1, - ret: 63, - s256: 4, + ret: 13, + s256: 2, sb: 1, - scwq: 23, + scwq: 13, sll: 1, slli: 1, srl: 1, srli: 1, - srw: 21, + srw: 12, sub: 1, subi: 1, sw: 1, - sww: 67, - swwq: 68, + sww: 43, + swwq: 44, time: 1, - tr: 255, - tro: 196, + tr: 105, + tro: 60, wdcm: 1, wqcm: 1, wdop: 1, wqop: 1, wdml: 1, - wqml: 2, - wddv: 2, - wqdv: 3, - wdmd: 4, - wqmd: 7, - wdam: 3, - wqam: 4, - wdmm: 4, - wqmm: 4, + wqml: 1, + wddv: 1, + wqdv: 2, + wdmd: 3, + wqmd: 4, + wdam: 2, + wqam: 3, + wdmm: 3, + wqmm: 3, xor: 1, xori: 1, call: DependentCost { - base: 173, - dep_per_unit: 180, + base: 144, + dep_per_unit: 214, }, ccp: DependentCost { - base: 22, - dep_per_unit: 152, + base: 15, + dep_per_unit: 103, }, csiz: DependentCost { - base: 16, - dep_per_unit: 868, + base: 17, + dep_per_unit: 790, }, ldc: DependentCost { - base: 22, - dep_per_unit: 150, + base: 15, + dep_per_unit: 272, }, logd: DependentCost { - base: 48, - dep_per_unit: 18, + base: 26, + dep_per_unit: 64, }, mcl: DependentCost { base: 1, - dep_per_unit: 2503, + dep_per_unit: 3333, }, mcli: DependentCost { base: 1, - dep_per_unit: 2559, + dep_per_unit: 3333, }, mcp: DependentCost { base: 1, - dep_per_unit: 1301, + dep_per_unit: 2000, }, meq: DependentCost { base: 1, - dep_per_unit: 1747, + dep_per_unit: 2500, }, - rvrt: 65, + rvrt: 13, smo: DependentCost { - base: 207, - dep_per_unit: 18, + base: 209, + dep_per_unit: 55, }, retd: DependentCost { - base: 71, - dep_per_unit: 18, + base: 29, + dep_per_unit: 62, }, } } diff --git a/fuel-vm/src/interpreter/flow/tests.rs b/fuel-vm/src/interpreter/flow/tests.rs index f76a07cd4b..07ff172ca5 100644 --- a/fuel-vm/src/interpreter/flow/tests.rs +++ b/fuel-vm/src/interpreter/flow/tests.rs @@ -109,7 +109,7 @@ impl Default for Output { frames: vec![CallFrame::new( Default::default(), Default::default(), - make_reg(&[(HP, 1000), (SP, 100), (SSP, 100), (CGAS, 0), (GGAS, 0)]), + make_reg(&[(HP, 1000), (SP, 100), (SSP, 100), (CGAS, 10), (GGAS, 10)]), 10, 0, 0, @@ -150,11 +150,11 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 0, }, - reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 170, ggas: 170 }, + reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 21, ggas: 21 }, context: Context::Script{ block_height: Default::default() }, ..Default::default() } => using check_output(Ok(Output{ - reg: RegInput{hp: 1000, sp: 716, ssp: 716, fp: 100, pc: 700, is: 700, bal: 0, cgas: 0, ggas: 0 }, + reg: RegInput{hp: 1000, sp: 716, ssp: 716, fp: 100, pc: 700, is: 700, bal: 0, cgas: 0, ggas: 10 }, ..Default::default() })); "basic call working" )] @@ -166,7 +166,7 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 2000, amount_of_gas_to_forward: 30, }, - reg: RegInput{hp: 1000, sp: 200, ssp: 200, fp: 0, pc: 0, is: 0, bal: 0, cgas: 1080, ggas: 1150 }, + reg: RegInput{hp: 1000, sp: 200, ssp: 200, fp: 0, pc: 0, is: 0, bal: 0, cgas: 201, ggas: 201 }, context: Context::Script{ block_height: Default::default() }, input_contracts: vec![ContractId::from([1u8; 32])], memory: mem(&[(2000, vec![2; 32]), (2032, Call::new(ContractId::from([1u8; 32]), 4, 5).into())]), @@ -175,12 +175,12 @@ fn mem(set: &[(usize, Vec)]) -> Memory { script: Some(Default::default()), ..Default::default() } => using check_output({ - let frame = CallFrame::new(ContractId::from([1u8; 32]), AssetId::from([2u8; 32]), make_reg(&[(HP, 1000), (SP, 200), (SSP, 200), (CGAS, 0), (GGAS, 100)]), 100, 4, 5); + let frame = CallFrame::new(ContractId::from([1u8; 32]), AssetId::from([2u8; 32]), make_reg(&[(HP, 1000), (SP, 200), (SSP, 200), (CGAS, 151), (GGAS, 181)]), 100, 4, 5); let mut receipt = Receipt::call(ContractId::zeroed(), ContractId::from([1u8; 32]), 20, AssetId::from([2u8; 32]), 30, 4, 5, 800, 800); let mut script = Script::default(); *script.receipts_root_mut() = crypto::ephemeral_merkle_root([receipt.to_bytes()].into_iter()); Ok(Output{ - reg: RegInput{hp: 1000, sp: 904, ssp: 904, fp: 200, pc: 800, is: 800, bal: 20, cgas: 30, ggas: 100 }, + reg: RegInput{hp: 1000, sp: 904, ssp: 904, fp: 200, pc: 800, is: 800, bal: 20, cgas: 30, ggas: 181 }, receipts: vec![receipt].into(), frames: vec![frame.clone()], memory: CheckMem::Check(vec![(200, frame.into()), (2000, vec![2; 32]), (2032, Call::new(ContractId::from([1u8; 32]), 4, 5).into())]), @@ -197,7 +197,7 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 0, }, - reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 170, ggas: 170 }, + reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 11, ggas: 11 }, context: Context::Script{ block_height: Default::default() }, balance: [(AssetId::default(), 30)].into_iter().collect(), ..Default::default() @@ -216,14 +216,14 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 10, }, - reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 180, ggas: 200 }, + reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 40, ggas: 80 }, context: Context::Script{ block_height: Default::default() }, balance: [(AssetId::default(), 30)].into_iter().collect(), ..Default::default() } => using check_output(Ok(Output{ - reg: RegInput{hp: 1000, sp: 716, ssp: 716, fp: 100, pc: 700, is: 700, bal: 20, cgas: 10, ggas: 30 }, + reg: RegInput{hp: 1000, sp: 716, ssp: 716, fp: 100, pc: 700, is: 700, bal: 20, cgas: 10, ggas: 69 }, receipts: vec![Receipt::call(Default::default(), Default::default(), 20, Default::default(), 10, 0, 0, 700, 700)].into(), - frames: vec![CallFrame::new(Default::default(), Default::default(), make_reg(&[(HP, 1000), (SP, 100), (SSP, 100), (CGAS, 0), (GGAS, 30)]), 10, 0, 0)], + frames: vec![CallFrame::new(Default::default(), Default::default(), make_reg(&[(HP, 1000), (SP, 100), (SSP, 100), (CGAS, 19), (GGAS, 69)]), 10, 0, 0)], ..Default::default() })); "forwards gas" )] @@ -235,14 +235,14 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 100, }, - reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 180, ggas: 200 }, + reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 40, ggas: 80 }, context: Context::Script{ block_height: Default::default() }, balance: [(AssetId::default(), 30)].into_iter().collect(), ..Default::default() } => using check_output(Ok(Output{ - reg: RegInput{hp: 1000, sp: 716, ssp: 716, fp: 100, pc: 700, is: 700, bal: 20, cgas: 10, ggas: 30 }, - receipts: vec![Receipt::call(Default::default(), Default::default(), 20, Default::default(), 10, 0, 0, 700, 700)].into(), - frames: vec![CallFrame::new(Default::default(), Default::default(), make_reg(&[(HP, 1000), (SP, 100), (SSP, 100), (CGAS, 0), (GGAS, 30)]), 10, 0, 0)], + reg: RegInput{hp: 1000, sp: 716, ssp: 716, fp: 100, pc: 700, is: 700, bal: 20, cgas: 29, ggas: 69 }, + receipts: vec![Receipt::call(Default::default(), Default::default(), 20, Default::default(), 29, 0, 0, 700, 700)].into(), + frames: vec![CallFrame::new(Default::default(), Default::default(), make_reg(&[(HP, 1000), (SP, 100), (SSP, 100), (CGAS, 0), (GGAS, 69)]), 10, 0, 0)], ..Default::default() })); "the receipt shows forwarded gas correctly when limited by available gas" )] @@ -254,7 +254,7 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 0, }, - reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 170, ggas: 170 }, + reg: RegInput{hp: 1000, sp: 100, ssp: 100, fp: 0, pc: 0, is: 0, bal: 0, cgas: 11, ggas: 11 }, context: Context::Call{ block_height: Default::default() }, storage_balance: [(AssetId::default(), 30)].into_iter().collect(), ..Default::default() @@ -273,7 +273,7 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 0, }, - reg: RegInput{hp: 1000, sp: 0, ssp: 0, fp: 0, pc: 0, is: 0, bal: 0, cgas: 170, ggas: 170 }, + reg: RegInput{hp: 1000, sp: 0, ssp: 0, fp: 0, pc: 0, is: 0, bal: 0, cgas: 11, ggas: 11 }, context: Context::Script{ block_height: Default::default() }, ..Default::default() } => using check_output(Err(RuntimeError::Recoverable(PanicReason::NotEnoughBalance))); "Tries to forward more coins than the contract has" @@ -286,7 +286,7 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 0, }, - reg: RegInput{hp: 1000, sp: 0, ssp: 0, fp: 0, pc: 0, is: 0, bal: 0, cgas: 170, ggas: 170 }, + reg: RegInput{hp: 1000, sp: 0, ssp: 0, fp: 0, pc: 0, is: 0, bal: 0, cgas: 11, ggas: 11 }, context: Context::Script{ block_height: Default::default() }, ..Default::default() } => using check_output(Err(RuntimeError::Recoverable(PanicReason::MemoryOverflow))); "call_params_mem_address overflow" @@ -312,7 +312,7 @@ fn mem(set: &[(usize, Vec)]) -> Memory { asset_id_mem_address: 0, amount_of_gas_to_forward: 0, }, - reg: RegInput{hp: 1000, sp: 0, ssp: 0, fp: 0, pc: 0, is: 0, bal: 0, cgas: 170, ggas: 170 }, + reg: RegInput{hp: 1000, sp: 0, ssp: 0, fp: 0, pc: 0, is: 0, bal: 0, cgas: 11, ggas: 11 }, context: Context::Call{ block_height: Default::default() }, balance: [(AssetId::default(), 30)].into_iter().collect(), ..Default::default() diff --git a/fuel-vm/src/interpreter/gas.rs b/fuel-vm/src/interpreter/gas.rs index b8c71659eb..44a062c52b 100644 --- a/fuel-vm/src/interpreter/gas.rs +++ b/fuel-vm/src/interpreter/gas.rs @@ -97,7 +97,7 @@ fn dependent_gas_charge_inner( ) -> Result { let cost = gas_cost .base - .saturating_add(arg.saturating_mul(gas_cost.dep_per_unit)); + .saturating_add(arg.saturating_div(gas_cost.dep_per_unit)); gas_charge_inner(cgas, ggas, cost).map(|_| cost) } diff --git a/fuel-vm/src/interpreter/gas/tests.rs b/fuel-vm/src/interpreter/gas/tests.rs index 61dec9820e..d0304e7160 100644 --- a/fuel-vm/src/interpreter/gas/tests.rs +++ b/fuel-vm/src/interpreter/gas/tests.rs @@ -66,21 +66,21 @@ struct DepGasChargeInput { )] #[test_case( DepGasChargeInput{ - input: GasChargeInput{cgas: 3, ggas: 3, dependent_factor: 1}, + input: GasChargeInput{cgas: 1, ggas: 1, dependent_factor: 1}, gas_cost: DependentCost{base: 1, dep_per_unit: 2} } => Ok(GasChargeOutput{ cgas: 0, ggas: 0}); "just base with gas" )] #[test_case( DepGasChargeInput{ - input: GasChargeInput{cgas: 33, ggas: 33, dependent_factor: 8}, + input: GasChargeInput{cgas: 3, ggas: 3, dependent_factor: 8}, gas_cost: DependentCost{base: 1, dep_per_unit: 4} } => Ok(GasChargeOutput{ cgas: 0, ggas: 0}); "base with gas and a unit" )] #[test_case( DepGasChargeInput{ - input: GasChargeInput{cgas: 30, ggas: 30, dependent_factor: 5}, + input: GasChargeInput{cgas: 3, ggas: 3, dependent_factor: 5}, gas_cost: DependentCost{base: 0, dep_per_unit: 4} - } => Ok(GasChargeOutput{ cgas: 10, ggas: 10}); "base with gas and a unit and left over" + } => Ok(GasChargeOutput{ cgas: 2, ggas: 2}); "base with gas and a unit and left over" )] #[test_case( DepGasChargeInput{ From 5e288c48c8a6600fcc22a3fad1b1a2a6d1a9f04f Mon Sep 17 00:00:00 2001 From: green Date: Wed, 2 Aug 2023 19:50:06 +0100 Subject: [PATCH 2/3] Bump version to `0.35.2` --- Cargo.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f37daa2dc..10cb3480b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,15 +18,15 @@ edition = "2021" homepage = "https://fuel.network/" license = "BUSL-1.1" repository = "https://github.com/FuelLabs/fuel-vm" -version = "0.35.1" +version = "0.35.2" [workspace.dependencies] -fuel-asm = { version = "0.35.1", path = "fuel-asm", default-features = false } -fuel-crypto = { version = "0.35.1", path = "fuel-crypto", default-features = false } -fuel-merkle = { version = "0.35.1", path = "fuel-merkle", default-features = false } -fuel-storage = { version = "0.35.1", path = "fuel-storage", default-features = false } -fuel-tx = { version = "0.35.1", path = "fuel-tx", default-features = false } -fuel-types = { version = "0.35.1", path = "fuel-types", default-features = false } -fuel-vm = { version = "0.35.1", path = "fuel-vm", default-features = false } +fuel-asm = { version = "0.35.2", path = "fuel-asm", default-features = false } +fuel-crypto = { version = "0.35.2", path = "fuel-crypto", default-features = false } +fuel-merkle = { version = "0.35.2", path = "fuel-merkle", default-features = false } +fuel-storage = { version = "0.35.2", path = "fuel-storage", default-features = false } +fuel-tx = { version = "0.35.2", path = "fuel-tx", default-features = false } +fuel-types = { version = "0.35.2", path = "fuel-types", default-features = false } +fuel-vm = { version = "0.35.2", path = "fuel-vm", default-features = false } bincode = { version = "1.3", default-features = false } criterion = "0.5.0" From b24ef0fbe767b7dbccef9976396d1c069fab7fbc Mon Sep 17 00:00:00 2001 From: green Date: Thu, 3 Aug 2023 02:07:28 +0100 Subject: [PATCH 3/3] Fix CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7762ed5a10..5fa2ed715f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). #### Breaking -- [#538](https://github.com/FuelLabs/fuel-vm/pull/538/): Rollbacked the change for the gas charging formula. +- [#539](https://github.com/FuelLabs/fuel-vm/pull/539/): Rollbacked the change for the gas charging formula. Actualized the gas prices for opcodes. ## [Version 0.35.1]