Skip to content

Commit

Permalink
fix: double gas limit, bootloader memory layout (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimazhornyk authored May 29, 2024
1 parent e009070 commit 1d72eae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/test/zks-apis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/bootloader_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 9 additions & 11 deletions src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,7 @@ impl<S: std::fmt::Debug + ForkSource> InMemoryNodeInner<S> {
)))
}
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());
Expand Down Expand Up @@ -1366,8 +1364,8 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
) -> Result<L2TxResult, String> {
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();

Expand Down Expand Up @@ -1438,13 +1436,13 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
"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()
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/node/zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 1d72eae

Please sign in to comment.