Skip to content

Conversation

@popzxc
Copy link
Member

@popzxc popzxc commented Jan 15, 2025

Fixes the gas_per_pubdata_limit field calculation. Right now, we provide the value we get from deriving the existing batch input, which is most likely lower than limit provided in fee estimation request.
Given that we scale the overall fee, it should be safe to scale the limit as well, as long as we don't go beyond the limit supplied in the tx.

Providing the limit as-is without scaling can be very flaky: transaction risks to be left in the mempool over minor gas_per_pubdata changes.

@popzxc popzxc marked this pull request as ready for review January 15, 2025 07:56
Copy link
Contributor

@slowli slowli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question: Do I understand correctly that the changed logic influences zks_estimateFee output only? (There are 2 other uses of gas estimation, eth_estimateGas and zks_estimateL1ToL2Gas, but they both seem to output only Fee.gas_limit.) If so, gas_per_pubdata_limit is overwritten before estimation to a hard-coded value (50,000); is this fine?

tx.common_data.fee.max_priority_fee_per_gas = 0u64.into();
tx.common_data.fee.gas_per_pubdata_limit = U256::from(DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE);
self.estimate_fee(tx.into(), block_args, state_override)
.await

It sort of contradicts "we should not exceed the limit that was provided by the user in the initial request", since the value provided by the user is ignored.

@popzxc
Copy link
Member Author

popzxc commented Jan 15, 2025

@slowli

Do I understand correctly that the changed logic influences zks_estimateFee output only?

Yes.

If so, gas_per_pubdata_limit is overwritten before estimation to a hard-coded value (50,000); is this fine?

Huh, that's both fine and not fine. I would expect zks_estimateFee to respect the value if provided, but the reality we're in is that probably nobody actively monitors this value (there is no good tooling and/or documentation for that). So my comment was about the correctness of the implementation, but if we are to discuss the real state of affairs -- it's OK to exceed, since I'm fairly sure that nobody relies on this logic.

@popzxc popzxc requested review from perekopskiy and slowli January 28, 2025 13:52
@popzxc
Copy link
Member Author

popzxc commented Jan 30, 2025

@perekopskiy @slowli do we want to merge this PR, or do you think a bigger rework is mandatory?

@slowli
Copy link
Contributor

slowli commented Jan 30, 2025

I think this PR is fine to merge (AFAIU, it shouldn't break anything), but I won't pretend I'm an expert on the domain, so it's difficult for me to estimate how complete this fix is.

@popzxc popzxc enabled auto-merge February 6, 2025 08:12
@popzxc popzxc added this pull request to the merge queue Feb 6, 2025
Merged via the queue into main with commit bda1b25 Feb 6, 2025
34 checks passed
@popzxc popzxc deleted the popzxc-fix-gas-estimation branch February 6, 2025 12:53
github-merge-queue bot pushed a commit that referenced this pull request Feb 12, 2025
🤖 I have created a release *beep* *boop*
---


##
[26.3.0](core-v26.2.1...core-v26.3.0)
(2025-02-12)


### Features

* **contract-verifier:** Do not allow verification requests for verified
contracts
([#3578](#3578))
([6a1f1b8](6a1f1b8))
* **contract-verifier:** Partial matching & automatic verification
([#3527](#3527))
([bf9fe85](bf9fe85))
* **contract-verifier:** Support missing options for EVM in API
([#3592](#3592))
([309fdf4](309fdf4))
* **en:** better EN default req entities limit, improved documentation
for API limits
([#3546](#3546))
([e7eb716](e7eb716))
* make `zksync_types` thinner
([#3574](#3574))
([e7f93e4](e7f93e4))
* new da_dispatcher metrics
([#3464](#3464))
([75a7c08](75a7c08))
* update FFLONK protocol version
([#3572](#3572))
([a352852](a352852))
* **vm:** Allow caching signature verification
([#3505](#3505))
([7bb5ed3](7bb5ed3))
* **vm:** Support missed storage invocation limit in fast VM
([#3548](#3548))
([ef67694](ef67694))


### Bug Fixes

* Add debug information to object store retries
([#3576](#3576))
([036315c](036315c))
* allow configuring NoDA client via ENV
([#3599](#3599))
([a72ab63](a72ab63))
* **api:** Change `contractAddress` assignment for transaction receipts
([#3452](#3452))
([4179711](4179711))
* **api:** Improve estimation for gas_per_pubdata_limit
([#3475](#3475))
([bda1b25](bda1b25))
* Avail gas relay decoding issues
([#3547](#3547))
([a171433](a171433))
* **ci:** commenting out getFilterChanges test until fix is ready
([#3582](#3582))
([99c3905](99c3905))
* Support newer versions of foundry-zksync
([#3556](#3556))
([d39fb6d](d39fb6d))
* **vm:** Fix VM divergences related to validation
([#3567](#3567))
([170d194](170d194))


### Performance Improvements

* **db:** Remove `events.tx_initiator_address` writes and index
([#3559](#3559))
([298abd2](298abd2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: zksync-era-bot <[email protected]>
zkzoomer pushed a commit that referenced this pull request Jun 21, 2025
🤖 I have created a release *beep* *boop*
---


##
[26.3.0](core-v26.2.1...core-v26.3.0)
(2025-02-12)


### Features

* **contract-verifier:** Do not allow verification requests for verified
contracts
([#3578](#3578))
([6a1f1b8](6a1f1b8))
* **contract-verifier:** Partial matching & automatic verification
([#3527](#3527))
([b94d1ad](b94d1ad))
* **contract-verifier:** Support missing options for EVM in API
([#3592](#3592))
([309fdf4](309fdf4))
* **en:** better EN default req entities limit, improved documentation
for API limits
([#3546](#3546))
([e7eb716](e7eb716))
* make `zksync_types` thinner
([#3574](#3574))
([292e731](292e731))
* new da_dispatcher metrics
([#3464](#3464))
([75a7c08](75a7c08))
* update FFLONK protocol version
([#3572](#3572))
([a352852](a352852))
* **vm:** Allow caching signature verification
([#3505](#3505))
([7bb5ed3](7bb5ed3))
* **vm:** Support missed storage invocation limit in fast VM
([#3548](#3548))
([ef67694](ef67694))


### Bug Fixes

* Add debug information to object store retries
([#3576](#3576))
([036315c](036315c))
* allow configuring NoDA client via ENV
([#3599](#3599))
([a72ab63](a72ab63))
* **api:** Change `contractAddress` assignment for transaction receipts
([#3452](#3452))
([4179711](4179711))
* **api:** Improve estimation for gas_per_pubdata_limit
([#3475](#3475))
([bda1b25](bda1b25))
* Avail gas relay decoding issues
([#3547](#3547))
([a171433](a171433))
* **ci:** commenting out getFilterChanges test until fix is ready
([#3582](#3582))
([99c3905](99c3905))
* Support newer versions of foundry-zksync
([#3556](#3556))
([d39fb6d](d39fb6d))
* **vm:** Fix VM divergences related to validation
([#3567](#3567))
([170d194](170d194))


### Performance Improvements

* **db:** Remove `events.tx_initiator_address` writes and index
([#3559](#3559))
([298abd2](298abd2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: zksync-era-bot <[email protected]>
dutterbutter pushed a commit to dutterbutter/zkstack-cli that referenced this pull request Jul 3, 2025
🤖 I have created a release *beep* *boop*
---


##
[26.3.0](matter-labs/zksync-era@core-v26.2.1...core-v26.3.0)
(2025-02-12)


### Features

* **contract-verifier:** Do not allow verification requests for verified
contracts
([#3578](matter-labs/zksync-era#3578))
([6a1f1b8](matter-labs/zksync-era@6a1f1b8))
* **contract-verifier:** Partial matching & automatic verification
([#3527](matter-labs/zksync-era#3527))
([a0b7ca1](matter-labs/zksync-era@a0b7ca1))
* **contract-verifier:** Support missing options for EVM in API
([#3592](matter-labs/zksync-era#3592))
([309fdf4](matter-labs/zksync-era@309fdf4))
* **en:** better EN default req entities limit, improved documentation
for API limits
([#3546](matter-labs/zksync-era#3546))
([e7eb716](matter-labs/zksync-era@e7eb716))
* make `zksync_types` thinner
([#3574](matter-labs/zksync-era#3574))
([fc84832](matter-labs/zksync-era@fc84832))
* new da_dispatcher metrics
([#3464](matter-labs/zksync-era#3464))
([75a7c08](matter-labs/zksync-era@75a7c08))
* update FFLONK protocol version
([#3572](matter-labs/zksync-era#3572))
([a352852](matter-labs/zksync-era@a352852))
* **vm:** Allow caching signature verification
([#3505](matter-labs/zksync-era#3505))
([7bb5ed3](matter-labs/zksync-era@7bb5ed3))
* **vm:** Support missed storage invocation limit in fast VM
([#3548](matter-labs/zksync-era#3548))
([ef67694](matter-labs/zksync-era@ef67694))


### Bug Fixes

* Add debug information to object store retries
([#3576](matter-labs/zksync-era#3576))
([036315c](matter-labs/zksync-era@036315c))
* allow configuring NoDA client via ENV
([#3599](matter-labs/zksync-era#3599))
([a72ab63](matter-labs/zksync-era@a72ab63))
* **api:** Change `contractAddress` assignment for transaction receipts
([#3452](matter-labs/zksync-era#3452))
([4179711](matter-labs/zksync-era@4179711))
* **api:** Improve estimation for gas_per_pubdata_limit
([#3475](matter-labs/zksync-era#3475))
([bda1b25](matter-labs/zksync-era@bda1b25))
* Avail gas relay decoding issues
([#3547](matter-labs/zksync-era#3547))
([a171433](matter-labs/zksync-era@a171433))
* **ci:** commenting out getFilterChanges test until fix is ready
([#3582](matter-labs/zksync-era#3582))
([99c3905](matter-labs/zksync-era@99c3905))
* Support newer versions of foundry-zksync
([#3556](matter-labs/zksync-era#3556))
([d39fb6d](matter-labs/zksync-era@d39fb6d))
* **vm:** Fix VM divergences related to validation
([#3567](matter-labs/zksync-era#3567))
([170d194](matter-labs/zksync-era@170d194))


### Performance Improvements

* **db:** Remove `events.tx_initiator_address` writes and index
([#3559](matter-labs/zksync-era#3559))
([298abd2](matter-labs/zksync-era@298abd2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: zksync-era-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants