Bug: Multi-hop swap gas limit too tight — 2-hop exceeds 1,200,000 #39
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#39
Loading…
Add table
Add a link
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?
Steps:\n1. Swap OPAL → ONYX → CORAL (2-hop via router)\n2. Amount: 10 OPAL, slippage 5%\n\nExpected: Tx succeeds within gas limit\nGot: out of gas; gasWanted: 1200000, gasUsed: 1227713\n\nCurrent: SWAP_GAS_PER_HOP = 600k, so 2-hop = 1,200,000. Actual usage is 1,227,713 — exceeds by ~28k.\n\nSuggested fix: Add 10% buffer to gas calculation, e.g. (hops * 600k * 1.1) or bump SWAP_GAS_PER_HOP to 650k.
mentioned in commit
7c1e63e88bFix pushed in commit
7c1e63e.Added a
SWAP_GAS_BUFFER = 1.1constant and applied it to multi-hop gas calculations so the gas limit is nowMath.round(SWAP_GAS_PER_HOP × hops × 1.1).Before → After for the reported 2-hop case:
Changes:
frontend-dapp/src/utils/constants.ts— newSWAP_GAS_BUFFERconstantfrontend-dapp/src/services/terraclassic/transactions.ts— buffer applied to both direct and send-wrappedexecute_swap_operations@Brouie Please verify ix.
mentioned in issue #18
Verified #38 fix — custom slippage now passed to router correctly. However #39 still fails: TOPAZ->ONYX->CORAL 2-hop swap gives gasWanted: 1,320,000 vs gasUsed: 1,320,097. The 1.1x buffer (SWAP_GAS_BUFFER in constants.ts) is too tight — off by 97 gas. Suggest bumping to 1.15 or 1.2.
mentioned in commit
d3da36159eFollow-up pushed in
d3da361(still leaving this open until verified on-chain).Change:
execute_swap_operationsgas is nowmax(buffered base + (hops × padding), hops × min per hop):SWAP_GAS_BUFFER(1.1) unchanged on the(SWAP_GAS_PER_HOP × hops)termSWAP_MULTIHOP_GAS_PADDING_PER_HOP= 50,000 extra per hop (covers the ~97 gas miss on 1.32M with margin)EXECUTE_SWAP_OPS_MIN_GAS_PER_HOP= 661,000 floor per hop so totals never sit just above bare600k × hops × 1.1Example 2-hop: ~1,420,000 gas wanted (was 1,320,000 after first fix).
@Brouie please re-run the TOPAZ → ONYX → CORAL (or similar) 2-hop on your env and confirm the tx no longer runs out of gas; then we can close #39.
Verified — TOPAZ->ONYX->CORAL 2-hop swap succeeds. Gas no longer runs out. Closing.