diff --git a/Cargo.lock b/Cargo.lock index 8824686daa..6cf56a93ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1389,7 +1389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -2056,7 +2056,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -2870,7 +2870,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ "hermit-abi", "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -4298,6 +4298,7 @@ dependencies = [ "alloy-signer", "alloy-signer-local", "auto_impl", + "cfg-if", "derive-where", "revm-bytecode", "revm-context", @@ -4590,7 +4591,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -4623,7 +4624,8 @@ dependencies = [ [[package]] name = "rwasm" version = "0.3.2" -source = "git+https://github.com/fluentlabs-xyz/rwasm?branch=devel#61894b725fb6a9f31ccb237328a74e29e7b9002d" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b36169175e8ed473a54baf2a23ff6cf3391c12abf12c339a18d18e4990ee3c8" dependencies = [ "bincode 2.0.1", "bitvec", @@ -5192,7 +5194,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -6239,7 +6241,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 22516286ea..2a49558831 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,7 +125,7 @@ triehash = "0.8" walkdir = "2.5" # rwasm -rwasm = { git = "https://github.com/fluentlabs-xyz/rwasm", branch = "devel", default-features = false } +rwasm = { version = "0.3.2", default-features = false } #rwasm = { path = "../rwasm", default-features = false } [workspace.package] diff --git a/crates/handler/Cargo.toml b/crates/handler/Cargo.toml index 176e337938..f5ce9e055f 100644 --- a/crates/handler/Cargo.toml +++ b/crates/handler/Cargo.toml @@ -30,6 +30,7 @@ bytecode.workspace = true auto_impl.workspace = true derive-where.workspace = true +cfg-if.workspace = true # Optional serde = { version = "1.0", default-features = false, features = [ @@ -73,4 +74,5 @@ serde = [ "derive-where/serde" ] serde-json = ["serde"] -debug-print = [] \ No newline at end of file +debug-print = [] +fluent-testnet = [] # Compatibility with Fluent testnet \ No newline at end of file diff --git a/crates/handler/src/validation.rs b/crates/handler/src/validation.rs index 35d0e83911..c5b1271b8e 100644 --- a/crates/handler/src/validation.rs +++ b/crates/handler/src/validation.rs @@ -4,7 +4,7 @@ use context_interface::{ Block, Cfg, ContextTr, }; use core::cmp; -use interpreter::gas::{self, InitialAndFloorGas, FUEL_DENOM_RATE}; +use interpreter::gas::{self, InitialAndFloorGas}; use primitives::wasm::WASM_MAGIC_BYTES; use primitives::{eip4844, hardfork::SpecId, wasm::wasm_max_code_size, B256}; @@ -299,8 +299,20 @@ pub fn validate_initial_tx_gas( } let mut floor_gas = gas.floor_gas; + + // Fuel denomination rate rwasm -> evm + // Testnet uses legacy rate (1000), correct rate is 20 + // see more details here: + // https://github.com/fluentlabs-xyz/fluentbase/blob/devel/crates/types/src/lib.rs#L63 + if tx.input().starts_with(&WASM_MAGIC_BYTES) { - floor_gas /= FUEL_DENOM_RATE; + cfg_if::cfg_if! { + if #[cfg(feature = "fluent-testnet")] { + floor_gas /= 1000; + } else { + floor_gas /= 20; + } + } } // EIP-7623: Increase calldata cost diff --git a/crates/interpreter/src/gas.rs b/crates/interpreter/src/gas.rs index 7a2b1c5bfd..8cc52c2026 100644 --- a/crates/interpreter/src/gas.rs +++ b/crates/interpreter/src/gas.rs @@ -167,23 +167,6 @@ impl Gas { MemoryExtensionResult::Extended } - - /// Records the denominated fuel cost by converting the provided raw fuel cost - /// with a predefined fuel denomination rate (FUEL_DENOM_RATE) and logs it. - /// This operation does not round up due to syncing requirements between gas - /// and fuel rates. - #[inline] - pub fn record_denominated_cost(&mut self, fuel_cost: u64) -> bool { - // TODO(dmitry123): "we can't do round ceil here because we need to sync gas/fuel rates" - // self.record_cost((fuel_cost + FUEL_DENOM_RATE - 1) / FUEL_DENOM_RATE) - self.record_cost(fuel_cost / FUEL_DENOM_RATE) - } - - /// Records a denominated fuel refund value. - #[inline] - pub fn record_denominated_refund(&mut self, fuel_refund: i64) { - self.record_refund(fuel_refund / FUEL_DENOM_RATE as i64) - } } /// Result of attempting to extend memory during execution. diff --git a/crates/interpreter/src/gas/constants.rs b/crates/interpreter/src/gas/constants.rs index bf4bacf875..057d2d899f 100644 --- a/crates/interpreter/src/gas/constants.rs +++ b/crates/interpreter/src/gas/constants.rs @@ -100,8 +100,3 @@ pub const INITCODE_WORD_COST: u64 = 2; pub const CALL_STIPEND: u64 = 2300; /// Minimum gas that must be provided to a callee. pub const MIN_CALLEE_GAS: u64 = CALL_STIPEND; - -/// A fuel denomination rate for rWasm vs. EVM opcodes -/// -/// Make sure this value is synchronized with a Fluentbase version -pub const FUEL_DENOM_RATE: u64 = 1000;