Skip to content

fix: all account overrides + gas limits#22173

Merged
Thunkar merged 23 commits intomerge-train/fairiesfrom
gj/wallet_improvements
Apr 7, 2026
Merged

fix: all account overrides + gas limits#22173
Thunkar merged 23 commits intomerge-train/fairiesfrom
gj/wallet_improvements

Conversation

@Thunkar
Copy link
Copy Markdown
Contributor

@Thunkar Thunkar commented Mar 31, 2026

The introduction of NO_FROM means that sometimes we might want to override account contracts during simulations that are not the from of the transaction (for example, to do authwit capture when the entrypoint is an FPC). This PR overrides accounts also in the additionalScopes list before simulating.

Gas estimations were poorly defined in the previous implementation. Simulation always estimates gas, and our default gas limits for sending embedded in the protocol. These constants have been removed and moved to GasSettings with proper explanations. Furthermore, the pipeline is simplified:

  • BaseWallet will use the user-provided gas limits for everything, and then resort to the an arbitrary max (during sending) or the estimation values (during simulation) if they're not provided.
  • EmbeddedWallet will do the same for simulation, but for sending will simulate first and then apply the estimated gas with a padding to the tx if the user didn't provide limits.

Why respect the user-provided gas limits during simulation/gas estimation? Sometimes the tx itself will enforce certain conditions on the gas/fee consumed (during teardown, for example). Setting the max limit on teardown will cause those transactions to fail simulation, since teardown gas is charged unconditionally.

Closes: https://linear.app/aztec-labs/issue/F-404/decrease-or-remove-default-gas-limits

@Thunkar Thunkar requested review from benesjan and mverzilli March 31, 2026 04:50
@Thunkar Thunkar self-assigned this Mar 31, 2026
@benesjan
Copy link
Copy Markdown
Contributor

Merged merge-train/fairies to get a clean CI pass

@Thunkar Thunkar added ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure ci-draft Run CI on draft PRs. labels Mar 31, 2026
@Thunkar Thunkar marked this pull request as draft March 31, 2026 08:47
@Thunkar Thunkar marked this pull request as ready for review March 31, 2026 13:01
Copy link
Copy Markdown
Contributor

@sirasistant sirasistant left a comment

Choose a reason for hiding this comment

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

Inner gas stuff LGTM but haven't read much of the wallet side.

Copy link
Copy Markdown
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

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

Docs and naming Karen is back!

Comment thread boxes/boxes/vanilla/app/embedded-wallet.ts Outdated
Comment thread yarn-project/bb-prover/src/avm_proving_tests/avm_check_circuit3.test.ts Outdated
/** User-provided partial gas settings. */
gasSettings?: Partial<FieldsOf<GasSettings>>;
/** If true, uses high gas limits for estimation/simulation. If false, uses protocol max limits. */
forEstimation?: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it called forEstimation?

Could you also explain the difference between high gas limits and protocol max limits? I don't really understand it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understood the naming from below. Maybe something like "canExceedProtocolLimits" would be better?

Then we could explain here why it's fine and desirable to exceed the limits when simulating.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is only every used for estimation with the combination of skipFeeEnforcement and skipTxValidation. I wouldn't complicate it further

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am fine with keeping it as "forEstimation" but would explain here that the high gas limits are higher than the protocol max and how is it even possible and why do we do it. Setting here higher limits than protocol max is very confusing and I think wallet builders will want to understand this so would not dismiss this as it being just an unimportant setting that noone will see (even if it was just for internal team it would make sense to explain).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see it updated. If you don't want to repeat the explanation here then would point to where it's explained.

Comment thread yarn-project/wallet-sdk/src/base-wallet/base_wallet.ts
Comment thread yarn-project/wallet-sdk/src/base-wallet/base_wallet.ts
Comment thread yarn-project/wallets/src/embedded/embedded_wallet.ts Outdated
Comment thread yarn-project/stdlib/src/gas/gas_settings.ts Outdated
@Thunkar Thunkar requested a review from benesjan April 1, 2026 15:11
Comment thread yarn-project/wallet-sdk/src/base-wallet/base_wallet.ts Outdated
Comment thread yarn-project/stdlib/src/gas/gas_settings.ts Outdated
@Thunkar Thunkar marked this pull request as draft April 6, 2026 04:18
@Thunkar Thunkar marked this pull request as ready for review April 6, 2026 05:08
Copy link
Copy Markdown
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

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

Looks good 👍

/** Default gas settings to use when user has not provided them. Requires explicit max fees per gas. */
static default(overrides: {
/**
* Fills in gas limits high enough for transactions to be included in most cases.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"in most cases"

I would expect everyone to be asking what are the cases this will fail.

Would also explain here why it's called fallback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Explained cases where this would fail

* Fills in gas limits high enough for transactions to be included in most cases.
* gasLimits is set to the maximum the protocol allows; since teardown gas is reserved
* from gasLimits during private execution (see gas_meter.nr), the effective gas available
* for app logic will be gasLimits - teardownGasLimits - privateOverhead.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unrelated to your PR but the fact that we cannot just use the max protocol limits makes me think the constants were incorrectly defined and now the complexity leaks all the way here and is vomited in the dev's face.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not a constants definition problem, but a chicken-and-egg problem. You need to pay for teardown unconditionally, so you need to allocate some gas to it. How much? Well, you don't know until you estimate. Hence, there's no "max" in the protocol, since you could potentially allocate MAX_PROCESSABLE_L2_GAS to teardown...but then you cannot do anything else

Comment on lines 127 to 128
l2Gas: DEFAULT_TEARDOWN_L2_GAS_LIMIT,
daGas: DEFAULT_TEARDOWN_DA_GAS_LIMIT,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These 2 constants now have stale naming.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mmm, I thought it was fine keeping them the same, since it's an arbitrary value. Maybe FALLBACK_TEARDOWN_L2_GAS_LIMIT?

Comment thread yarn-project/stdlib/src/gas/gas_settings.ts Outdated
/** User-provided partial gas settings. */
gasSettings?: Partial<FieldsOf<GasSettings>>;
/** If true, uses high gas limits for estimation/simulation. If false, uses protocol max limits. */
forEstimation?: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see it updated. If you don't want to repeat the explanation here then would point to where it's explained.

Comment thread yarn-project/wallets/src/embedded/embedded_wallet.ts Outdated
@Thunkar Thunkar enabled auto-merge (squash) April 7, 2026 09:31
@Thunkar Thunkar merged commit 41ee481 into merge-train/fairies Apr 7, 2026
12 checks passed
@Thunkar Thunkar deleted the gj/wallet_improvements branch April 7, 2026 09:38
AztecBot pushed a commit that referenced this pull request Apr 7, 2026
The introduction of `NO_FROM` means that sometimes we might want to
override account contracts during simulations that are not the `from` of
the transaction (for example, to do authwit capture when the entrypoint
is an FPC). This PR overrides accounts also in the `additionalScopes`
list before simulating.

Gas estimations were poorly defined in the previous implementation.
Simulation always estimates gas, and our default gas limits for sending
embedded in the protocol. These constants have been removed and moved to
`GasSettings` with proper explanations. Furthermore, the pipeline is
simplified:

* `BaseWallet` will use the user-provided gas limits for everything, and
then resort to the an arbitrary max (during sending) or the estimation
values (during simulation) if they're not provided.
* `EmbeddedWallet` will do the same for simulation, but for sending will
simulate first and then apply the estimated gas with a padding to the tx
*if the user didn't provide limits*.

Why respect the user-provided gas limits during simulation/gas
estimation? Sometimes the tx itself will enforce certain conditions on
the gas/fee consumed (during teardown, for example). Setting the max
limit on teardown will cause those transactions to fail simulation,
since teardown gas is charged unconditionally.

Closes:
https://linear.app/aztec-labs/issue/F-404/decrease-or-remove-default-gas-limits

---------

Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
@AztecBot
Copy link
Copy Markdown
Collaborator

AztecBot commented Apr 7, 2026

✅ Successfully backported to backport-to-v4-next-staging #22258.

github-merge-queue Bot pushed a commit that referenced this pull request Apr 7, 2026
BEGIN_COMMIT_OVERRIDE
chore: remove dead to_be_bytes fn (#22243)
fix: correct args length in `#[authorize_once]` (#22209)
chore: fix inconsistent usage of contract class hash fn (#22248)
chore: delete old field comparison fns in favor of lt (#22249)
fix: all account overrides + gas limits (#22173)
feat: allow for runtime length arrays of sorts and selects (#22250)
chore: remove dead pub global vars reexport (#22244)
chore: changed default wait behavior (#22325)
chore: apply code consistency consolidation (#22251)
END_COMMIT_OVERRIDE
AztecBot added a commit that referenced this pull request Apr 8, 2026
BEGIN_COMMIT_OVERRIDE
fix: pippenger edge case (#22256)
cherry-pick: fix: separate fisherman StatefulSet from rpc-node and stop
archiver pollution (#22183) — WITH CONFLICTS
fix: separate fisherman StatefulSet from rpc-node and stop archiver
pollution (backport #22183) (#22284)
fix: preserve DeployAccountMethod type in with() method chaining
(#22322)
docs: backport docs build/release infrastructure from #22106 and #22144
(#22223)
chore(docs): remove v5 nightly and devnet versioned docs (backport
#22193) (#22236)
chore: improve release-docs skill and add release-network-docs skill
(#22328)
chore: remove dead to_be_bytes fn (#22243)
fix: correct args length in `#[authorize_once]` (#22209)
chore: fix inconsistent usage of contract class hash fn (#22248)
chore: delete old field comparison fns in favor of lt (#22249)
fix: all account overrides + gas limits (#22173)
feat: allow for runtime length arrays of sorts and selects (#22250)
chore: remove dead pub global vars reexport (#22244)
chore: changed default wait behavior (#22325)
chore: apply code consistency consolidation (#22251)
fix(docs): simplify TypeScript API reference links (backport #22232)
(#22369)
fix: remove detailed revert codes (#22380)
fix: backport #21673 — prevent HA peer proposals from blocking
equivocation in duplicate proposal test (#21693)
fix: subfield note selectors (#22211)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v4-next ci-draft Run CI on draft PRs. ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants