fix(swap): validate offline gas budgets for USTR routes and align fee readiness with signing #1480
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/cl8y-dex-terraclassic#1480
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem and scope
Mainnet feedback indicates that LUNC → USTR and CL8Y → USTR can remain unusable at small amounts, and that USTC → USTR can require increasing gas manually in the wallet. A short-estimate out-of-gas message was observed. High-price-impact confirmation was also observed on LUNC → cLUNC → UST1 → USTR and CL8Y → cUSTC → UST1 → USTR.
Bundle the related execution work into this issue: measured gas coverage for locally prepared routes, one consistent fee budget across display/balance reserve/signing, wallet fee handling, and accurate separation of price protection from gas failure. A high-impact confirmation alone is not proof of a pricing bug. Do not remove it to make the trade appear successful.
This is an anonymized technical summary. No conversations, screenshots, reporter identifiers, wallet balances, actor addresses, or reporter-linked transaction history are published. Wallet/app version, exact original input amounts, deployed frontend revision, and included transaction gas fields were unavailable for the reported attempts. The investigation establishes a source-level coverage gap and public quote observations, not the exact root cause of each original transaction.
Current codebase and investigation
Source reviewed:
2d1627ffa33eb3e08199acfff574a5b63fcfbd39(2026-10-12). Public read-only probes usedhttps://indexer.dex.cl8y.com; its/healthadvertised backend SHAea627f7b0e8d5ebc9fde2bb5b243f451cf159f4d. This does not attest the frontend artifact.SwapPage.tsxpasses local execution metadata toexecuteMultiHopSwaporexecuteLocalNativeRoute. Inrouter.ts, these reviewed-route paths explicitly passgasEstimation: 'offline'(including protected direct wrap/unwrap).terraBroadcast.tsconsequently usestotalGasLimitForExecuteMsgsand does not callresolveBroadcastGasLimit/resolveSwapAutoGas. This is intentional network isolation introduced by #1452, but it restores static gas as the primary budget for these paths.ceil(gas_used × 1.2)) for other swap-shaped executes, plus a static fallback. Its helper remains present; it does not protect the reviewed local routes above.terraBroadcast.autoGas.test.tsexplicitly asserts that the offline path never calls the gas reader and signs the static sum. The old auto-gas documentation therefore does not describe every current retail signing path.execute_swap_operationsuses the global router hop formula: two hops 1,910,000, three hops 2,860,000. Wrap + two legacy hops adds 400,000 wrap gas and 400,000 combination overhead: 2,710,000. At 28.325 uluna/gas these last two shapes cost approximately 81.01 and 76.76 LUNC, matching the observed UI fee classes. This agreement identifies an envelope, not an actual signed gas limit or proof that the wallet honored it.execute_route_swap_operationshas a distinct measured route-local-v1 budget,600,000 + 1,700,000 × hops, plus applicable hybrid/unwrap/combination costs. Do not conflate this funding protocol with legacyexecute_swap_operations. The live quote probes below returnedtax_funding_version: null, so legacy coverage is still relevant.SwapPage.tsxcurrently assignsswapNetworkFeeEstimate = swapNetworkFeeFallback. It does not useuseAutoGasFeeEstimate. The #1360 fee-row tests render a standalone test component using that hook; they do not establish actual Swap-page hint/signing parity or the adequacy of offline budgets. The #1264 runner also reports its filtered SwapPage invocation as passing despite matching no tests; restore meaningful entry-path assertions. Preview construction inswapNetworkFee.tsalso needs review against the actual serialized submit message, including protected wrappers and hybrid execution modes.local_quote.rsreports symmetric deviation of delivered net output from an independently priced fair output.local_reference_quote.rsbinds references to execution identities, decimals and freshness; wrapper composition includes native funding economics.swapRouteSlippage.tsprefers route-level deviation. Confirmation above 5%, Expert requirements above 30%, and nonwaivable ≥99% protection are separate from network gas. A small trade can retain a nonzero deviation because fees or the market/reference relationship are not exclusively amount-dependent AMM impact.humanizeTerraTxError.tsmaps recognized out-of-gas logs to fixed retail copy. That copy does not establish whether the dApp budget, a wallet rewrite, changing execution work, or a provider estimate caused the original failure.Public quote observations
Read-only GET
/api/v1/route/solveon 2026-10-12, exact entered raw amounts,max_spread=0.05,protection_policy=quote_relative_v1, native paths pool-only, no trader context, signatures or broadcasts:All eight returned
local_v1,quote_relative_v1, and null tax-funding version. These are observations at their respective request times, not same-generation route comparisons or funded execution proof. They did not reproduce the originally observed impact percentages. Normal new HTTPS request elapsed times were approximately 847–1171 ms; these are not initialized browser latency measurements and do not replace #1473 acceptance.Why an implementation is needed
Reducing the input or raising slippage does not repair an inadequate gas envelope. Repeated included out-of-gas transactions can charge fees without delivering output. Closed #1360/#1264 receipts measured different source, execution shapes or wallet paths and do not certify current locally prepared legacy routes. The architecture now needs evidence-backed offline gas coverage rather than relying on helper-only simulation tests or requiring users to discover a multiplier.
The fix must address the actual deficient layer. If a measured route fits the dApp envelope but the wallet lowers signed gas, fix wallet handling; if signed gas honors the dApp budget and execution exceeds it, repair the applicable global execution-family budget. Raising fee amount/gas price alone is not raising
Fee.gas.Relevant files
frontend-dapp/src/pages/SwapPage.tsx;components/trade/TradeMarketOrderPanel.tsx;hooks/useAutoGasFeeEstimate.ts;utils/swapNativeGasBalanceGate.ts;utils/maxSpendableAmount.ts— real fee display, native balance reservation and entry flows.frontend-dapp/src/services/terraclassic/router.ts,transactions.ts,terraBroadcast.ts,terraBroadcastScope.ts— exact message assembly, local/offline option propagation, canonical signing and recovery.frontend-dapp/src/services/terraclassic/terraGas.ts,swapNetworkFee.ts,terraClassicFeeEstimate.ts,hybridSwapGas.ts,terraGasRetailInventory.ts;frontend-dapp/src/utils/constants.ts— execution-family budgets and combined-message costs.frontend-dapp/src/services/terraclassic/swapAutoGas.ts,terraSimulateTx.ts,terraWalletSignTxRaw.ts;frontend-dapp/src/utils/extensionSignedFeeGuard.ts;frontend-dapp/patches/@goblinhunt+cosmes+0.0.71-ghunt.22.patch— remaining auto-gas paths, wallet behavior and existing chain-scoped guards.frontend-dapp/src/utils/swapRouteSlippage.ts,swapPayAcquireGuidance.ts,humanizeTerraTxError.ts,localRouteQuote.ts;indexer/src/api/local_quote.rs,local_reference_quote.rs,local_quote/protection.rs— independent fairness, execution protection, stale-intent and expiry boundaries.frontend-dapp/src/services/terraclassic/__tests__/terraBroadcast.autoGas.test.ts,swapAutoGasFeeHint.test.tsx,swapNetworkFee.test.ts,terraGas.retailShapes.test.ts,terraGas.mixedHybrid.test.ts;frontend-dapp/src/pages/SwapPage*.test.tsx;frontend-dapp/e2e/wrap-swap.spec.ts— extend actual path coverage.smartcontracts/contracts/pair/src/contract.rs,hook_bounds_tests.rs;smartcontracts/contracts/router/src/contract.rs,route_tax.rs; treasury/wrap-mapper dependency pins — benchmark the current compiled settlement and wrapper implementations, with rejection rollback checks.docs/adr/0014-swap-auto-gas.md,docs/adr/0004-terraclassic-retail-gas-census.md,docs/frontend.md,docs/route-solver.md; applicable gas/local-quote playbooks;packages/localnet-trading-swarm/src/gas.ts— policy reconciliation and shared constants.Recommended direction
preferNoSetFeeand guard scope; do not turn on a global mainnet fee guard without explicit evidence and wallet compatibility tests. Keep unsupported atomic-post behavior truthful.Constraints and guardrails
gasEstimation: 'offline'to reintroduce user-triggered simulation is not an acceptable fix. Non-local existing auto-gas paths remain a separate policy.uluna, including nativeuusdoffers. Keep configured gas-price minima, checked fee arithmetic, native pay+fee reservation and chain gas/transaction limits. Bound the final signed budget, not only a simulatedgas_usedfield.Acceptance criteria
gas_used < gas_wanted, expected delivered net amount and all floors respected. Cover applicable legacy/v1 modes and non-USTR control assets. Unsupported or over-limit families block before signing.Test plan: functional and failure paths
Use independently calculated expected outputs and decoded signed Fee, not assertions that simply restate a constant. Fund owned LocalTerra fixtures and compare net balance/reserve/LP effects; rejection by settlement floors must roll back economics. Device/wallet acceptance is separate from mocks and chain simulation.
Test plan: attack, hack and abuse vectors
Verification and related work
This is a follow-up after closed #1360 (auto-gas), #1264/#587 (native wrap gas), and #1452 (local quotes), with #1459/#1473 defining current local execution/protection semantics. Coordinate deployed acceptance with #1456 rather than claiming that old closures certify this regression. #1222's historical census “Stay” is not a hold on this measured-execution follow-up.
Baseline investigation checks (2026-10-12; no implementation changes):
make verify-issue-1360: 82 tests passed; optional funded-account mainnet simulation and signed-wallet checks unavailable.make verify-issue-1328: 103 tests passed; optional funded-account mainnet simulation/signing unverified.make verify-issue-1222: nine groups passed, including 83 gas/network-fee/inventory tests on first/retest. This verifies existing assumptions, not their production adequacy.make verify-issue-1264: four groups passed; 123 source tests passed on first/retest. The runner's filteredSwapPage.test.tsx -t #1264invocation matched no tests (25 skipped per run); original included-transaction acceptance was not exercised.make verify-issue-1452: overall FAIL, retained. The library passed 774 tests on first/retest (one ignored); frontend passed 471 tests on first/retest; types/format/crosslinks passed. Disposable socket checks could not run without dedicated QA credentials and the runner counted those as failures. Controlled browser first passed, retest failed the 500 ms bound: Swap maxima approximately 1524 ms desktop / 1046 ms phone, with zero quote-triggered provider calls. This is not a gas-execution receipt and not deployment acceptance.make verify-issue-1257: overall FAIL, retained. Targeted Rust scale tests passed. A frontend mainnet-identity fixture failed under this checkout's LocalTerra token configuration; a canonical-identity retest of the affected registry/default suites passed all 39 tests. Historical source-grep and old top-five-solver documentation assertions also failed and remain unresolved; do not classify them as a reproduced gas failure.make verify-issue-1473: overall FAIL (12 passed groups, five failed, two explicit skips), retained. The library passed 774 tests on first/retest (one ignored). Frontend had 425 passed/two mainnet-default fixture failures per run under LocalTerra configuration; the isolated canonical-identity retest passed 39 tests as above. Disposable socket credentials were unavailable. The complete controlled desktop/phone browser matrix recorded 4250 cases, 3948 useful-output samples and 3 failures; useful p50/p95/p99/max approximately 89.8/148.6/166.1/3564.6 ms against 750 ms, zero provider requests. It is controlled fixture evidence, not deployed or funded gas acceptance.Implementation verification must rerun
make verify-issue-1360,make verify-issue-1328,make verify-issue-1264,make verify-issue-1222,make verify-issue-1452,make verify-issue-1473, and applicable tax/net-floor/launch-guard checks (1381,1398,1390), alongside the new actual-entry/funded matrix. Keep unrelated pre-existing failures visible and update stale assertions only with equivalent functional protection coverage.Unavailable workflow holds/device/signing/deployment capabilities do not block filing or a reviewable implementation. Record explicit SKIP reasons and keep corresponding acceptance unchecked; executed failures remain FAIL. Production completion requires exact artifact provenance and funded/wallet receipts, not passing helper tests alone.
Published implementation and evidence (2026-10-12)
Implementation PR #1481 is deployed at
0395459971312c31f87d502ef7822733a7250238; evidence/QA #1482 publishes bounded live outcomes and retained failures. Current results and agent checklist distinguish completed subsets from incomplete whole criteria.All whole criteria remain incomplete despite passing source, funded plain-core and live-quote subsets. Physical/atomic-wallet, reported native/USTR/hook/book gas and production contract provenance remain incomplete. This issue remains open.
Implementation #1481 and evidence/QA #1482 are merged. Backend/frontend/root assets are separately attested at
0395459971312c31f87d502ef7822733a7250238; evidence maind65228c2keeps identical application inputs.Reviewed local budgets use generic 800k+2.4M/hop legacy and 800k+1.8M/hop funding-v1, applicable work overhead and a 15M final cap. Fee display, Max/native reserve and signing share the plan; queued Swap submissions recheck cached principal+fee coverage. Exact requested/signed fee and original expiry guards remain. Owned first/retest each delivered 24 settlements plus 48 intentional floor rejections, with independently calculated net, decoded fees, rollback and ≥20% measured core gas headroom. Mixed 6/18/9-decimal 1%/5%/30% and tax/invoice subsets passed. Final source entrypoint passed 351 frontend tests per round; hosted implementation CI422 passed all required steps.
Live browser shards completed 840 unique cases, zero failures and 558 useful quotes (max467.3 ms against750 ms). Earlier browser timing/wall-cap, one unproved API validation and cold883.045 ms failures remain FAIL. Live quotes do not certify funded production gas or physical wallet behavior.
All whole acceptance criteria remain incomplete: original reported wallet/amount details, native/USTR/wrapper/tax/hook/book worst-case calibrated settlement, atomic WalletConnect/signed-device inspection and deployed contract provenance. Results, checklist/skip policy, and OB1480 instructions record those limits. This issue remains open.
Physical mobile fee approval is pending in the PM inbox, task
f2041acd-86a0-4a86-9b90-469196638b90, linked through PM #143. Its one action compares fee approval and cancels without signing; it is not funded/device acceptance.PlasticDigits referenced this issue2026-10-15 05:32:59 +00:00
Closed at the user's request as part of consolidating issues #1449–#1500.
Offline gas budgets, fee readiness, Max and signing consistency fixes are implemented. Physical wallet review and broad verification-only acceptance are not carried forward; actual remaining native/protected-wrapper work is tracked by #1504.
Replacement: #1504
Wallet/device chores and verification-only holds are intentionally excluded. Historical failed receipts remain unchanged; this closure does not claim every old acceptance checkbox passed.