Repository navigation
Conversation
Two fund-safety defects in the trade executor: 1. Order amounts are multiplied as plain int64. A sell order with TotalBoardlot*AmountPerBoardlot wrapping past int64 freezes only the wrapped remainder, and a buy-limit order whose PricePerBoardlot*TotalBoardlot wraps can later pay the taker seller the wrapped value in tradeSellMarket while the buyer receives the full token amount. A malicious buyer can therefore take a seller's tokens for a tiny wrapped payment. 2. checkPrice/notSameAsset were called with PriceExec in the symbol argument, so the same-asset order check and price-pair validation were ineffective. - Add isMulOverflow and check every order/payment/token multiplication involved in tradeSell, tradeBuyLimit, tradeBuy and tradeSellMarket. - Pass PriceSymbol into checkPrice/notSameAsset after the new fork. - Behavior is gated behind ForkTradeFixOverflow (default height 0).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
trade 执行器的订单/成交金额全部直接用 int64 乘法,超出 int64 时静默回绕:
tradeSell的TotalBoardlot*AmountPerBoardlot、tradeBuyLimit的PricePerBoardlot*TotalBoardlot回绕后只冻结零头;tradeSellMarket的成交付款BoardlotCnt*PricePerBoardlot同样回绕。攻击者挂一个PricePerBoardlot=2^32、TotalBoardlot=2^32+1的买单,只冻结 2^32(约 42.95 枚);卖方卖出全部 boardlot 时付款回绕成 2^32 通过检查,买方却按AmountPerBoardlot拿走大量 token;checkPrice/notSameAsset调用时把PriceExec当成 symbol 传入,导致“资产 == 计价资产”的畸形订单绕过校验。修复
isMulOverflow,在tradeSell、tradeBuyLimit、tradeBuy、tradeSellMarket的挂单冻结、成交付款、token 数量计算处做溢出检测。checkPrice/notSameAsset分叉后改传PriceSymbol。ForkTradeFixOverflow控制(默认高度 0)。trade_fix_overflow_test.go回归用例(溢出卖单/买单拒绝、价符参数校验)。验证
go build ./plugin/dapp/trade/...通过go test ./plugin/dapp/trade/executor/ -count=1通过