diff --git a/XDCx/XDCx.go b/XDCx/XDCx.go index 478366738c1f..e410fb31e538 100644 --- a/XDCx/XDCx.go +++ b/XDCx/XDCx.go @@ -372,7 +372,7 @@ func (XDCx *XDCX) SyncDataToSDKNode(takerOrderInTx *tradingstate.OrderItem, txHa tradeRecord := &tradingstate.Trade{} quantity := tradingstate.ToBigInt(trade[tradingstate.TradeQuantity]) price := tradingstate.ToBigInt(trade[tradingstate.TradePrice]) - if price.Cmp(big.NewInt(0)) <= 0 || quantity.Cmp(big.NewInt(0)) <= 0 { + if price.Sign() <= 0 || quantity.Sign() <= 0 { return fmt.Errorf("trade misses important information. tradedPrice %v, tradedQuantity %v", price, quantity) } tradeRecord.Amount = quantity diff --git a/XDCx/tradingstate/orderitem.go b/XDCx/tradingstate/orderitem.go index c6422865b4ad..4d1bb25a019e 100644 --- a/XDCx/tradingstate/orderitem.go +++ b/XDCx/tradingstate/orderitem.go @@ -288,7 +288,7 @@ func (o *OrderItem) encodedSide() *big.Int { // verifyPrice make sure price is a positive number func (o *OrderItem) verifyPrice() error { - if o.Price == nil || o.Price.Cmp(big.NewInt(0)) <= 0 { + if o.Price == nil || o.Price.Sign() <= 0 { log.Debug("Invalid price", "price", o.Price.String()) return ErrInvalidPrice } @@ -297,7 +297,7 @@ func (o *OrderItem) verifyPrice() error { // verifyQuantity make sure quantity is a positive number func (o *OrderItem) verifyQuantity() error { - if o.Quantity == nil || o.Quantity.Cmp(big.NewInt(0)) <= 0 { + if o.Quantity == nil || o.Quantity.Sign() <= 0 { log.Debug("Invalid quantity", "quantity", o.Quantity.String()) return ErrInvalidQuantity } diff --git a/XDCx/tradingstate/settle_balance.go b/XDCx/tradingstate/settle_balance.go index 771da0c29b26..80dd97b855ec 100644 --- a/XDCx/tradingstate/settle_balance.go +++ b/XDCx/tradingstate/settle_balance.go @@ -52,7 +52,7 @@ func GetSettleBalance(quotePrice *big.Int, takerSide string, takerFeeRate *big.I log.Debug("quantity trade too small", "quoteTokenQuantity", quoteTokenQuantity, "makerFee", makerFee, "defaultFee", defaultFee) return result, ErrQuantityTradeTooSmall } - if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Cmp(common.Big0) > 0 { + if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Sign() > 0 { // defaultFeeInXDC defaultFeeInXDC := new(big.Int).Mul(defaultFee, quotePrice) defaultFeeInXDC = new(big.Int).Div(defaultFeeInXDC, quoteTokenDecimal) @@ -108,7 +108,7 @@ func GetSettleBalance(quotePrice *big.Int, takerSide string, takerFeeRate *big.I log.Debug("quantity trade too small", "quoteTokenQuantity", quoteTokenQuantity, "takerFee", takerFee) return result, ErrQuantityTradeTooSmall } - if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Cmp(common.Big0) > 0 { + if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Sign() > 0 { // defaultFeeInXDC defaultFeeInXDC := new(big.Int).Mul(defaultFee, quotePrice) defaultFeeInXDC = new(big.Int).Div(defaultFeeInXDC, quoteTokenDecimal) diff --git a/XDCxlending/lendingstate/settle_balance.go b/XDCxlending/lendingstate/settle_balance.go index 93ee96d9366b..b3e70a56dc58 100644 --- a/XDCxlending/lendingstate/settle_balance.go +++ b/XDCxlending/lendingstate/settle_balance.go @@ -72,7 +72,7 @@ func GetSettleBalance(isXDCXLendingFork bool, log.Debug("quantity lending too small", "quantityToLend", quantityToLend, "takerFee", takerFee) return result, ErrQuantityTradeTooSmall } - if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Cmp(common.Big0) > 0 { + if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 { exTakerReceivedFee := new(big.Int).Mul(takerFee, lendTokenXDCPrice) exTakerReceivedFee = new(big.Int).Div(exTakerReceivedFee, lendTokenDecimal) @@ -122,7 +122,7 @@ func GetSettleBalance(isXDCXLendingFork bool, log.Debug("quantity lending too small", "quantityToLend", quantityToLend, "makerFee", makerFee) return result, ErrQuantityTradeTooSmall } - if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Cmp(common.Big0) > 0 { + if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 { exMakerReceivedFee := new(big.Int).Mul(makerFee, lendTokenXDCPrice) exMakerReceivedFee = new(big.Int).Div(exMakerReceivedFee, lendTokenDecimal) @@ -172,7 +172,7 @@ func GetSettleBalance(isXDCXLendingFork bool, log.Debug("quantity lending too small", "quantityToLend", quantityToLend, "borrowFee", borrowFee) return result, ErrQuantityTradeTooSmall } - if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Cmp(common.Big0) > 0 { + if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 { // exReceivedFee: the fee amount which borrowingRelayer will receive exReceivedFee := new(big.Int).Mul(borrowFee, lendTokenXDCPrice) exReceivedFee = new(big.Int).Div(exReceivedFee, lendTokenDecimal) diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index f710f8bb14b7..8543efd081fe 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -336,7 +336,7 @@ func TestStatedbUtils(t *testing.T) { if cap.Cmp(cap_statedb) != 0 { t.Fatalf("cap not equal, statedb utils is wrong") } - if cap.Cmp(big.NewInt(0)) == 0 { + if cap.Sign() == 0 { t.Fatalf("cap should not be zero") } owner, err := validator.GetCandidateOwner(it) @@ -368,7 +368,7 @@ func TestStatedbUtils(t *testing.T) { if cap.Cmp(cap_statedb) != 0 { t.Fatalf("cap not equal, statedb utils is wrong") } - if cap.Cmp(big.NewInt(0)) == 0 { + if cap.Sign() == 0 { t.Fatalf("cap should not be zero") } } diff --git a/core/txpool/order_pool.go b/core/txpool/order_pool.go index 3f3cd315711d..b548f5087b9e 100644 --- a/core/txpool/order_pool.go +++ b/core/txpool/order_pool.go @@ -443,11 +443,11 @@ func (pool *OrderPool) validateOrder(tx *types.OrderTransaction) error { cloneXDCXStateDb := pool.currentOrderState.Copy() if !tx.IsCancelledOrder() { - if quantity == nil || quantity.Cmp(big.NewInt(0)) <= 0 { + if quantity == nil || quantity.Sign() <= 0 { return ErrInvalidOrderQuantity } if orderType != OrderTypeMarket { - if price == nil || price.Cmp(big.NewInt(0)) <= 0 { + if price == nil || price.Sign() <= 0 { return ErrInvalidOrderPrice } } diff --git a/core/vm/privacy/bulletproof.go b/core/vm/privacy/bulletproof.go index 4c1972ffbc57..2de8f4e1e38c 100644 --- a/core/vm/privacy/bulletproof.go +++ b/core/vm/privacy/bulletproof.go @@ -755,7 +755,7 @@ func (ipp *InnerProdArg) Serialize() []byte { spa = serializePointArray(ipp.R, false) proof = append(proof, spa[:]...) - if ipp.A.Cmp(big.NewInt(0)) < 0 { + if ipp.A.Sign() < 0 { ipp.A.Mod(ipp.A, EC.N) } sp := PadTo32Bytes(ipp.A.Bytes()) @@ -833,7 +833,7 @@ func (mrp *MultiRangeProof) Serialize() []byte { sp = PadTo32Bytes(mrp.Tau.Bytes()) proof = append(proof, sp[:]...) - if mrp.Th.Cmp(big.NewInt(0)) < 0 { + if mrp.Th.Sign() < 0 { mrp.Th.Mod(mrp.Th, EC.N) } sp = PadTo32Bytes(mrp.Th.Bytes()) @@ -975,7 +975,7 @@ func MRPProve(values []*big.Int) (MultiRangeProof, error) { for j := range values { v := values[j] - if v.Cmp(big.NewInt(0)) == -1 { + if v.Sign() == -1 { return MultiRangeProof{}, errors.New("value is below range! Not proving") }