Skip to content

Fix fast-path executed price to match the recorded bid and quote - #4981

Merged
MartinquaXD merged 7 commits into
mainfrom
aryan/fix-fast-path-executed-price
Sep 30, 2026
Merged

MartinquaXD merged 7 commits into
mainfrom
aryan/fix-fast-path-executed-price

Conversation

@AryanGodara

@AryanGodara AryanGodara commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Description

Fast-path orders settled on-chain at a buy amount that matched didn't match the of chain signed price. PR attempting to fix the issue.

Changes

  • shared::fee::adjust_bid_for_gas_costs nets the quote's gas fee out of (sell, buy) the same way the user-facing quote does (sell orders scale buy down; buy orders raise sell), with unit tests.
  • stage the quote's gas gas_cost_in_sell_token on StagedSolution (#[serde(default)] so already-staged rows keep prior behaviour).
  • autopilot fast path executes finalize_bid (account for gas cost and then apply volume fees), in both the pre-flight limit check and the recorded-bid computation.
  • driver finalize_fast_path_solution rebuilds the winning fulfillment with haircut_fee = 0, so it settles the autopilot's bid exactly.

How to test

  • added e2e test and unit test
  • updated existing e2e tests to use strict equality on executed values instead of approximate equality

@AryanGodara AryanGodara self-assigned this Sep 25, 2026
…xecuted-price

# Conflicts:
#	crates/driver/src/domain/competition/solution/mod.rs
#	crates/e2e/tests/e2e/fast_path_settle.rs
@AryanGodara
AryanGodara marked this pull request as ready for review September 29, 2026 09:07
@AryanGodara
AryanGodara requested a review from a team as a code owner September 29, 2026 09:07
@claude

claude Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @AryanGodara's task in 6m 34s —— View job


PR Review: Fix fast-path executed price

I reviewed the fast-path fee-netting change against the quoting/validation flow. Overall the core logic is sound: apply_quote_fee correctly mirrors the user-facing quote (sell orders keep the full sell and scale the buy by (sell-fee)/sell; buy orders raise the sell by fee), and applying it before the volume fee makes the recorded bid and the pre-flight limit check match what the driver settles. Nice unit tests, and the mainnet-repro test is a good touch.

I found one substantive gap, posted inline:

  • crates/shared/src/quote_storage.rs:141-146 — the staged fee is FeeParameters::fee() (bare gas), but the user-facing quote and the orderbook fast-path validation both net out fee_with_additional_cost(additional_cost) (ERC-1271 sig-verification gas, plus hook gas for unverified quotes). So for non-EOA / hooked orders the recorded bid still over-shoots the quoted buy — a smaller version of the mismatch this PR fixes. EOA (EIP-712/EthSign) orders have additional_cost == 0, which is why the tests (all EOA) don't surface it. [details inline]

Non-blocking notes:

  • The autopilot pre-flight now uses adjusted_sell = quoted_sell (full) while the orderbook check uses quote.sell_amount (= quoted_sell - fee). The autopilot value matches on-chain settlement, and the difference only makes the autopilot stricter (safe: order falls through to a regular auction), so no action needed — flagging for awareness since the PR's theme is orderbook/autopilot parity.
  • The PR description mentions a driver finalize_fast_path_solution / haircut_fee = 0 change; that already landed on main in Replace haircut logic with existing volume fee logic #4900 and isn't part of this diff — description is fine, just noting.
    · branch aryan/fix-fast-path-executed-price

Comment thread crates/shared/src/quote_storage.rs Outdated
Comment on lines +141 to +146
fee: crate::fee::FeeParameters {
gas_amount: quote.gas_amount,
gas_price: data.metadata.gas_price,
sell_token_price: data.metadata.sell_token_price,
}
.fee(),

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.

The staged fee uses FeeParameters::fee() (bare gas_amount * gas_price / sell_token_price), but the fee the user-facing quote and the orderbook fast-path validation net out is fee_with_additional_cost(additional_cost) — i.e. it also includes ERC-1271 signature-verification gas and, for unverified quotes, hook gas.

  • User-facing quote: to_final_quote → with_additional_cost(additional_cost) before with_scaled_sell_amount, so quote.buy_amount is scaled by the full fee.
  • Orderbook: OrderQuoter::find_quote applies with_additional_cost(...) (order_quoting.rs:738), and check_fast_path_limit_price_fits validates against that quote.buy_amount.

Because this only nets out the bare gas fee, apply_quote_fee in the autopilot subtracts less than the real fee, so the recorded bid ends up higher than the quoted buy for any order with non-zero additional_cost (ERC-1271 / Safe orders, or unverified quotes with hooks — see the comment at order_validation.rs:1056 "Quoted gas does not include gas for ERC1271 signatures"). That partially reintroduces the exact circuit-breaker mismatch this PR is fixing, just scaled down to the additional-cost portion.

For pure-EOA (EIP-712 / EthSign) quotes additional_cost is 0 so this path is unaffected — hence the unit/e2e tests (all EOA) don't catch it.

Consider persisting the final quote.fee_amount (with additional cost) instead of recomputing .fee() here, or threading the signing scheme / additional cost into the staged competition. Note the additional cost technically depends on the order's eventual signing scheme, so exact parity may require capturing it at placement — worth confirming the intended behaviour.

@MartinquaXD
MartinquaXD added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit 3276638 Sep 30, 2026
23 checks passed
@MartinquaXD
MartinquaXD deleted the aryan/fix-fast-path-executed-price branch September 30, 2026 09:06
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants