From 1d72eae6e9400b5b6caed5e60093e7c32eee8abb Mon Sep 17 00:00:00 2001 From: Dima Zhornyk <55756184+dimazhornyk@users.noreply.github.com> Date: Wed, 29 May 2024 10:56:34 +0200 Subject: [PATCH] fix: double gas limit, bootloader memory layout (#289) --- e2e-tests/test/zks-apis.test.ts | 2 +- src/bootloader_debug.rs | 4 ++-- src/node/in_memory.rs | 20 +++++++++----------- src/node/zks.rs | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/e2e-tests/test/zks-apis.test.ts b/e2e-tests/test/zks-apis.test.ts index df7e7f6a..2966fe19 100644 --- a/e2e-tests/test/zks-apis.test.ts +++ b/e2e-tests/test/zks-apis.test.ts @@ -30,7 +30,7 @@ describe("zks_estimateFee", function () { // Act const response: Fee = await provider.send("zks_estimateFee", [transaction]); // Assert - expect(ethers.BigNumber.from(response.gas_limit)).to.eql(ethers.BigNumber.from("7203486"), "Unexpected gas_limit"); + expect(ethers.BigNumber.from(response.gas_limit)).to.eql(ethers.BigNumber.from("3606743"), "Unexpected gas_limit"); expect(ethers.BigNumber.from(response.gas_per_pubdata_limit)).to.eql( ethers.BigNumber.from("50000"), "Unexpected gas_per_pubdata_limit" diff --git a/src/bootloader_debug.rs b/src/bootloader_debug.rs index a4005ab0..f090761e 100644 --- a/src/bootloader_debug.rs +++ b/src/bootloader_debug.rs @@ -14,14 +14,14 @@ use zksync_state::WriteStorage; const DEBUG_START_SENTINEL: u64 = 1337; // Taken from bootloader.yul (MAX_MEM_SIZE) -const MAX_MEMORY_BYTES: usize = 30_000_000; +const MAX_MEMORY_BYTES: usize = 63_800_000; // Taken from Systemconfig.json const MAX_TRANSACTIONS: usize = 10000; const RESULTS_BYTES_OFFSET: usize = MAX_MEMORY_BYTES - MAX_TRANSACTIONS * 32; -const VM_HOOKS_PARAMS: usize = 2; +const VM_HOOKS_PARAMS: usize = 3; const VM_HOOKS_START: usize = RESULTS_BYTES_OFFSET - (VM_HOOKS_PARAMS + 1) * 32; diff --git a/src/node/in_memory.rs b/src/node/in_memory.rs index 9da07315..bbf495b4 100644 --- a/src/node/in_memory.rs +++ b/src/node/in_memory.rs @@ -665,9 +665,7 @@ impl InMemoryNodeInner { ))) } ExecutionResult::Success { .. } => { - let full_gas_limit = match suggested_gas_limit - .overflowing_add(suggested_gas_limit + overhead) - { + let full_gas_limit = match suggested_gas_limit.overflowing_add(overhead) { (value, false) => value, (_, true) => { tracing::info!("{}", "Overflow when calculating gas estimation. We've exceeded the block gas limit by summing the following values:".red()); @@ -1366,8 +1364,8 @@ impl InMemoryNode { ) -> Result { let inner = self .inner - .write() - .map_err(|e| format!("Failed to acquire write lock: {}", e))?; + .read() + .map_err(|e| format!("Failed to acquire read lock: {}", e))?; let storage = StorageView::new(inner.fork_storage.clone()).into_rc_ptr(); @@ -1438,13 +1436,13 @@ impl InMemoryNode { "Use --show-gas-details flag or call config_setShowGasDetails to display more info" ), ShowGasDetails::All => { - if self - .display_detailed_gas_info(bootloader_debug_result.get(), spent_on_pubdata) - .is_err() - { + let info = + self.display_detailed_gas_info(bootloader_debug_result.get(), spent_on_pubdata); + if info.is_err() { tracing::info!( - "{}", - "!!! FAILED TO GET DETAILED GAS INFO !!!".to_owned().red() + "{}\nError: {}", + "!!! FAILED TO GET DETAILED GAS INFO !!!".to_owned().red(), + info.unwrap_err() ); } } diff --git a/src/node/zks.rs b/src/node/zks.rs index b34c8831..e21ed855 100644 --- a/src/node/zks.rs +++ b/src/node/zks.rs @@ -590,7 +590,7 @@ mod tests { let result = node.estimate_fee(mock_request).await.unwrap(); - assert_eq!(result.gas_limit, U256::from(8970736)); + assert_eq!(result.gas_limit, U256::from(4490368)); assert_eq!(result.max_fee_per_gas, U256::from(37500000)); assert_eq!(result.max_priority_fee_per_gas, U256::from(0)); assert_eq!(result.gas_per_pubdata_limit, U256::from(50000));