diff --git a/XDCx/order_processor.go b/XDCx/order_processor.go index ed76da04e754..b84bc156f3de 100644 --- a/XDCx/order_processor.go +++ b/XDCx/order_processor.go @@ -379,7 +379,7 @@ func (XDCx *XDCX) getTradeQuantity(quotePrice *big.Int, coinbase common.Address, quotePrice = quoteTokenDecimal } if takerOrder.ExchangeAddress == makerOrder.ExchangeAddress { - if err := tradingstate.CheckRelayerFee(takerOrder.ExchangeAddress, new(big.Int).Mul(common.RelayerFee, big.NewInt(2)), statedb); err != nil { + if err := tradingstate.CheckRelayerFee(takerOrder.ExchangeAddress, new(big.Int).Lsh(common.RelayerFee, 1), statedb); err != nil { log.Debug("Reject order Taker Exchnage = Maker Exchange , relayer not enough fee ", "err", err) return tradingstate.Zero, false, nil, nil } diff --git a/XDCx/tradingstate/settle_balance_test.go b/XDCx/tradingstate/settle_balance_test.go index d340226fc756..13339e2d5137 100644 --- a/XDCx/tradingstate/settle_balance_test.go +++ b/XDCx/tradingstate/settle_balance_test.go @@ -78,7 +78,7 @@ func TestGetSettleBalance(t *testing.T) { makerFeeRate: big.NewInt(10), // feeRate 0.1% baseTokenDecimal: common.BasePrice, quoteTokenDecimal: common.BasePrice, - quantityToTrade: new(big.Int).Mul(big.NewInt(2), common.BasePrice), + quantityToTrade: new(big.Int).Lsh(common.BasePrice, 1), }, nil, true, @@ -112,7 +112,7 @@ func TestGetSettleBalance(t *testing.T) { makerFeeRate: big.NewInt(10), // feeRate 0.1% baseTokenDecimal: common.BasePrice, quoteTokenDecimal: common.BasePrice, - quantityToTrade: new(big.Int).Mul(big.NewInt(2), common.BasePrice), + quantityToTrade: new(big.Int).Lsh(common.BasePrice, 1), }, nil, true, @@ -185,7 +185,7 @@ func TestGetSettleBalance(t *testing.T) { makerFeeRate: big.NewInt(10), // feeRate 0.1% baseTokenDecimal: common.BasePrice, quoteTokenDecimal: common.BasePrice, - quantityToTrade: new(big.Int).Mul(big.NewInt(2), common.BasePrice), + quantityToTrade: new(big.Int).Lsh(common.BasePrice, 1), }, nil, true, @@ -219,7 +219,7 @@ func TestGetSettleBalance(t *testing.T) { makerFeeRate: big.NewInt(10), // feeRate 0.1% baseTokenDecimal: common.BasePrice, quoteTokenDecimal: common.BasePrice, - quantityToTrade: new(big.Int).Mul(big.NewInt(2), common.BasePrice), + quantityToTrade: new(big.Int).Lsh(common.BasePrice, 1), }, nil, true, diff --git a/XDCxlending/lendingstate/settle_balance.go b/XDCxlending/lendingstate/settle_balance.go index d2aa62ab9a57..589a4b46337e 100644 --- a/XDCxlending/lendingstate/settle_balance.go +++ b/XDCxlending/lendingstate/settle_balance.go @@ -235,7 +235,7 @@ func CalculateInterestRate(finalizeTime, liquidationTime, term uint64, apr uint6 // the time interval which borrower have to pay interest // (T + T1) / 2 timeToPayInterest := new(big.Int).Add(new(big.Int).SetUint64(term), new(big.Int).SetUint64(borrowingTime)) - timeToPayInterest = new(big.Int).Div(timeToPayInterest, new(big.Int).SetUint64(2)) + timeToPayInterest = new(big.Int).Rsh(timeToPayInterest, 1) interestRate := new(big.Int).SetUint64(apr) interestRate = new(big.Int).Mul(interestRate, timeToPayInterest) diff --git a/XDCxlending/order_processor.go b/XDCxlending/order_processor.go index 0693527dc7ae..53ca4afbac77 100644 --- a/XDCxlending/order_processor.go +++ b/XDCxlending/order_processor.go @@ -450,7 +450,7 @@ func (l *Lending) getLendQuantity( return lendingstate.Zero, lendingstate.Zero, false, nil, fmt.Errorf("fail to get tokenDecimal: Token: %v . Err: %v", collateralToken, err) } if takerOrder.Relayer == makerOrder.Relayer { - if err := lendingstate.CheckRelayerFee(takerOrder.Relayer, new(big.Int).Mul(common.RelayerLendingFee, big.NewInt(2)), statedb); err != nil { + if err := lendingstate.CheckRelayerFee(takerOrder.Relayer, new(big.Int).Lsh(common.RelayerLendingFee, 1), statedb); err != nil { log.Debug("Reject order Taker Exchnage = Maker Exchange , relayer not enough fee ", "err", err) return lendingstate.Zero, lendingstate.Zero, false, nil, nil } diff --git a/XDCxlending/order_processor_test.go b/XDCxlending/order_processor_test.go index c5aecb0d8c9f..0dafecdf90e7 100644 --- a/XDCxlending/order_processor_test.go +++ b/XDCxlending/order_processor_test.go @@ -400,11 +400,11 @@ func TestGetLendQuantity(t *testing.T) { common.BasePrice, depositRate, common.BasePrice, - new(big.Int).Div(collateralLocked, big.NewInt(2)), // 1/2 + new(big.Int).Rsh(collateralLocked, 1), // 1/2 lendQuantity, lendQuantity, }, - new(big.Int).Div(lendQuantity, big.NewInt(2)), + new(big.Int).Rsh(lendQuantity, 1), false, }, { @@ -414,7 +414,7 @@ func TestGetLendQuantity(t *testing.T) { common.BasePrice, depositRate, common.BasePrice, - new(big.Int).Div(collateralLocked, big.NewInt(2)), + new(big.Int).Rsh(collateralLocked, 1), common.Big0, lendQuantity, }, @@ -429,10 +429,10 @@ func TestGetLendQuantity(t *testing.T) { depositRate, common.BasePrice, collateralLocked, - new(big.Int).Div(lendQuantity, big.NewInt(2)), + new(big.Int).Rsh(lendQuantity, 1), lendQuantity, }, - new(big.Int).Div(lendQuantity, big.NewInt(2)), + new(big.Int).Rsh(lendQuantity, 1), true, }, { @@ -457,7 +457,7 @@ func TestGetLendQuantity(t *testing.T) { common.BasePrice, depositRate, common.BasePrice, - new(big.Int).Div(collateralLocked, big.NewInt(2)), + new(big.Int).Rsh(collateralLocked, 1), common.Big0, lendQuantity, }, @@ -471,11 +471,11 @@ func TestGetLendQuantity(t *testing.T) { common.BasePrice, depositRate, common.BasePrice, - new(big.Int).Div(lendQuantity, big.NewInt(2)), // 1/2 + new(big.Int).Rsh(lendQuantity, 1), // 1/2 collateralLocked, lendQuantity, }, - new(big.Int).Div(lendQuantity, big.NewInt(2)), + new(big.Int).Rsh(lendQuantity, 1), false, }, { @@ -486,7 +486,7 @@ func TestGetLendQuantity(t *testing.T) { depositRate, common.BasePrice, common.Big0, - new(big.Int).Div(collateralLocked, big.NewInt(2)), + new(big.Int).Rsh(collateralLocked, 1), lendQuantity, }, common.Big0, @@ -514,10 +514,10 @@ func TestGetLendQuantity(t *testing.T) { depositRate, common.BasePrice, collateralLocked, - new(big.Int).Div(collateralLocked, big.NewInt(2)), + new(big.Int).Rsh(collateralLocked, 1), lendQuantity, }, - new(big.Int).Div(lendQuantity, big.NewInt(2)), + new(big.Int).Rsh(lendQuantity, 1), true, }, { diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 82809f2bb313..6517df302aa6 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -465,10 +465,10 @@ func accumulateRewards(config *params.ChainConfig, stateDB vm.StateDB, header *t r.Add(uncle.Number, big8) r.Sub(r, header.Number) r.Mul(r, blockReward) - r.Div(r, big8) + r.Rsh(r, 3) stateDB.AddBalance(uncle.Coinbase, r, tracing.BalanceIncreaseRewardMineUncle) - r.Div(blockReward, big32) + r.Rsh(blockReward, 5) reward.Add(reward, r) } stateDB.AddBalance(header.Coinbase, reward, tracing.BalanceIncreaseRewardMineBlock) diff --git a/contracts/trc21issuer/simulation/test/main.go b/contracts/trc21issuer/simulation/test/main.go index 3db25c4ca3c7..2c83fd9c6052 100644 --- a/contracts/trc21issuer/simulation/test/main.go +++ b/contracts/trc21issuer/simulation/test/main.go @@ -30,7 +30,7 @@ func airDropTokenToAccountNoXDC() { mainAccount.Nonce = big.NewInt(int64(nonce)) mainAccount.Value = big.NewInt(0) // in wei mainAccount.GasLimit = uint64(4000000) // in units - mainAccount.GasPrice = big.NewInt(0).Mul(common.TRC21GasPrice, big.NewInt(2)) + mainAccount.GasPrice = big.NewInt(0).Lsh(common.TRC21GasPrice, 1) trc21Instance, _ := trc21issuer.NewTRC21(mainAccount, trc21TokenAddr, client) trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(mainAccount, common.TRC21IssuerSMC, client) // air drop token @@ -76,7 +76,7 @@ func testTransferTRC21TokenWithAccountNoXDC() { airDropAccount.Nonce = big.NewInt(int64(nonce)) airDropAccount.Value = big.NewInt(0) // in wei airDropAccount.GasLimit = uint64(4000000) // in units - airDropAccount.GasPrice = big.NewInt(0).Mul(common.TRC21GasPrice, big.NewInt(2)) + airDropAccount.GasPrice = big.NewInt(0).Lsh(common.TRC21GasPrice, 1) trc21Instance, _ := trc21issuer.NewTRC21(airDropAccount, trc21TokenAddr, client) trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client) @@ -139,7 +139,7 @@ func testTransferTrc21Fail() { airDropAccount.Nonce = big.NewInt(int64(nonce)) airDropAccount.Value = big.NewInt(0) // in wei airDropAccount.GasLimit = uint64(4000000) // in units - airDropAccount.GasPrice = big.NewInt(0).Mul(common.TRC21GasPrice, big.NewInt(2)) + airDropAccount.GasPrice = big.NewInt(0).Lsh(common.TRC21GasPrice, 1) trc21Instance, _ := trc21issuer.NewTRC21(airDropAccount, trc21TokenAddr, client) trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client) balanceIssuerFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr) diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index e5debd6692a6..4049ff6df485 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -2634,7 +2634,7 @@ func TestSetCodeTransactions(t *testing.T) { minGasPrice := new(big.Int).Set(common.MinGasPrice) minGasFee := uint256.MustFromBig(minGasPrice) - doubleGasFee := new(uint256.Int).Mul(new(uint256.Int).Set(minGasFee), uint256.NewInt(2)) + doubleGasFee := new(uint256.Int).Lsh(new(uint256.Int).Set(minGasFee), 1) tripleGasFee := new(uint256.Int).Mul(new(uint256.Int).Set(minGasFee), uint256.NewInt(3)) legacyReplacePrice := new(big.Int).Mul(minGasPrice, big.NewInt(10)) diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 1b35765c4703..1024e5cd5e8c 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -412,7 +412,7 @@ func NewEIP155Signer(chainId *big.Int) EIP155Signer { } return EIP155Signer{ chainId: chainId, - chainIdMul: new(big.Int).Mul(chainId, big.NewInt(2)), + chainIdMul: new(big.Int).Lsh(chainId, 1), } } @@ -589,8 +589,8 @@ func deriveChainId(v *big.Int) *big.Int { } return new(big.Int).SetUint64((v - 35) / 2) } - v = new(big.Int).Sub(v, big.NewInt(35)) - return v.Div(v, big.NewInt(2)) + v.Sub(v, big.NewInt(35)) + return v.Rsh(v, 1) } func CacheSigner(signer Signer, tx *Transaction) { diff --git a/core/vm/contracts.go b/core/vm/contracts.go index a3c647ea355e..b7a52c134371 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -296,10 +296,7 @@ var ( big0 = big.NewInt(0) big1 = big.NewInt(1) big3 = big.NewInt(3) - big4 = big.NewInt(4) big7 = big.NewInt(7) - big8 = big.NewInt(8) - big16 = big.NewInt(16) big20 = big.NewInt(20) big32 = big.NewInt(32) big64 = big.NewInt(64) @@ -326,13 +323,13 @@ func modexpMultComplexity(x *big.Int) *big.Int { case x.Cmp(big1024) <= 0: // (x ** 2 // 4 ) + ( 96 * x - 3072) x = new(big.Int).Add( - new(big.Int).Div(new(big.Int).Mul(x, x), big4), + new(big.Int).Rsh(new(big.Int).Mul(x, x), 2), new(big.Int).Sub(new(big.Int).Mul(big96, x), big3072), ) default: // (x ** 2 // 16) + (480 * x - 199680) x = new(big.Int).Add( - new(big.Int).Div(new(big.Int).Mul(x, x), big16), + new(big.Int).Rsh(new(big.Int).Mul(x, x), 4), new(big.Int).Sub(new(big.Int).Mul(big480, x), big199680), ) } @@ -370,7 +367,7 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { adjExpLen := new(big.Int) if expLen.Cmp(big32) > 0 { adjExpLen.Sub(expLen, big32) - adjExpLen.Mul(big8, adjExpLen) + adjExpLen.Lsh(adjExpLen, 3) } adjExpLen.Add(adjExpLen, big.NewInt(int64(msb))) // Calculate the gas cost of the operation @@ -389,8 +386,8 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { // ceiling(x/8)^2 // // where is x is max(length_of_MODULUS, length_of_BASE) - gas = gas.Add(gas, big7) - gas = gas.Div(gas, big8) + gas.Add(gas, big7) + gas.Rsh(gas, 3) gas.Mul(gas, gas) if adjExpLen.Cmp(big1) > 0 { diff --git a/core/vm/privacy/ringct.go b/core/vm/privacy/ringct.go index bdf73511e80c..173139802b80 100644 --- a/core/vm/privacy/ringct.go +++ b/core/vm/privacy/ringct.go @@ -89,7 +89,7 @@ func DeserializeCompressed(curve elliptic.Curve, b []byte) *ecdsa.PublicKey { // but this was replaced by the algorithms referenced in // https://bitcointalk.org/index.php?topic=162805.msg1712294#msg1712294 PPlus1Div4 := new(big.Int).Add(curve.Params().P, big.NewInt(1)) - PPlus1Div4 = PPlus1Div4.Div(PPlus1Div4, big.NewInt(4)) + PPlus1Div4.Rsh(PPlus1Div4, 2) y := new(big.Int).Exp(x3, PPlus1Div4, curve.Params().P) ybit := b[0]%2 == 1 if ybit != isOdd(y) { diff --git a/crypto/crypto.go b/crypto/crypto.go index c68b69ee7c02..dd262b4add91 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -47,7 +47,7 @@ const DigestLength = 32 var ( secp256k1N = S256().Params().N - secp256k1halfN = new(big.Int).Div(secp256k1N, big.NewInt(2)) + secp256k1halfN = new(big.Int).Rsh(secp256k1N, 1) ) var errInvalidPubkey = errors.New("invalid secp256k1 public key") diff --git a/crypto/secp256k1/curve.go b/crypto/secp256k1/curve.go index ebc45b735751..b9d0bee847d1 100644 --- a/crypto/secp256k1/curve.go +++ b/crypto/secp256k1/curve.go @@ -205,13 +205,13 @@ func (bitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, d.Mul(d, d) //(X1+B)² d.Sub(d, a) //(X1+B)²-A d.Sub(d, c) //(X1+B)²-A-C - d.Mul(d, big.NewInt(2)) //2*((X1+B)²-A-C) + d.Lsh(d, 1) //2*((X1+B)²-A-C) e := new(big.Int).Mul(big.NewInt(3), a) //3*A f := new(big.Int).Mul(e, e) //E² - x3 := new(big.Int).Mul(big.NewInt(2), d) //2*D - x3.Sub(f, x3) //F-2*D + x3 := new(big.Int).Lsh(d, 1) //2*D + x3.Sub(f, x3) //F-2*D x3.Mod(x3, bitCurve.P) y3 := new(big.Int).Sub(d, x3) //D-X3 @@ -220,7 +220,7 @@ func (bitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, y3.Mod(y3, bitCurve.P) z3 := new(big.Int).Mul(y, z) //Y1*Z1 - z3.Mul(big.NewInt(2), z3) //3*Y1*Z1 + z3.Lsh(z3, 1) //3*Y1*Z1 z3.Mod(z3, bitCurve.P) return x3, y3, z3 diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index 0f63c6e5b16d..3ecca17dafe6 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -202,7 +202,7 @@ func (oracle *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error) { // - All the transactions included are sent by the miner itself. // In these cases, use half of the latest calculated price for samping. if len(res.values) == 0 { - res.values = []*big.Int{new(big.Int).Div(lastPrice, common.Big2)} + res.values = []*big.Int{new(big.Int).Rsh(lastPrice, 1)} } // Besides, in order to collect enough data for sampling, if nothing // meaningful returned, try to query more blocks. But the maximum diff --git a/eth/util/util.go b/eth/util/util.go index 89138993ee8e..6833b4ad8e9e 100644 --- a/eth/util/util.go +++ b/eth/util/util.go @@ -12,10 +12,10 @@ func RewardInflation(chain consensus.ChainReader, chainReward *big.Int, number u } if blockPerYear*2 <= number && number < blockPerYear*5 { - chainReward.Div(chainReward, new(big.Int).SetUint64(2)) + chainReward.Rsh(chainReward, 1) } if blockPerYear*5 <= number { - chainReward.Div(chainReward, new(big.Int).SetUint64(4)) + chainReward.Rsh(chainReward, 2) } return chainReward diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 9f0fbc1ae7bf..807b1602a03d 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -2593,7 +2593,7 @@ func (api *BlockChainAPI) GetStakerROI() float64 { totalCap.Add(totalCap, cap) } - holderReward := new(big.Int).Div(masternodeReward, new(big.Int).SetUint64(2)) + holderReward := new(big.Int).Rsh(masternodeReward, 1) EpochPerYear := 365 * 86400 / api.b.GetEpochDuration().Uint64() voterRewardAYear := new(big.Int).Mul(holderReward, new(big.Int).SetUint64(EpochPerYear)) return 100.0 / float64(totalCap.Div(totalCap, voterRewardAYear).Uint64()) @@ -2627,7 +2627,7 @@ func (api *BlockChainAPI) GetStakerROIMasternode(masternode common.Address) floa } // holder reward = 50% total reward of a masternode - holderReward := new(big.Int).Div(masternodeReward, new(big.Int).SetUint64(2)) + holderReward := new(big.Int).Rsh(masternodeReward, 1) EpochPerYear := 365 * 86400 / api.b.GetEpochDuration().Uint64() voterRewardAYear := new(big.Int).Mul(holderReward, new(big.Int).SetUint64(EpochPerYear)) diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 9c5520bcff11..8b0b1c11f45d 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -222,7 +222,7 @@ func (args *TransactionArgs) setLondonFeeDefaults(ctx context.Context, head *typ // fee is rising. val := new(big.Int).Add( args.MaxPriorityFeePerGas.ToInt(), - new(big.Int).Mul(head.BaseFee, big.NewInt(2)), + new(big.Int).Lsh(head.BaseFee, 1), ) args.MaxFeePerGas = (*hexutil.Big)(val) } diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index ac065bc7a621..55f37aff6abe 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -59,7 +59,7 @@ func TestSetFeeDefaults(t *testing.T) { b = newBackendMock() zero = (*hexutil.Big)(big.NewInt(0)) fortytwo = (*hexutil.Big)(big.NewInt(42)) - maxFee = (*hexutil.Big)(new(big.Int).Add(new(big.Int).Mul(b.current.BaseFee, big.NewInt(2)), fortytwo.ToInt())) + maxFee = (*hexutil.Big)(new(big.Int).Add(new(big.Int).Lsh(b.current.BaseFee, 1), fortytwo.ToInt())) al = &types.AccessList{types.AccessTuple{Address: common.Address{0xaa}, StorageKeys: []common.Hash{{0x01}}}} ) diff --git a/tests/fuzzers/bn256/bn256_fuzz.go b/tests/fuzzers/bn256/bn256_fuzz.go index dac80f6b1334..3de4ad4781f2 100644 --- a/tests/fuzzers/bn256/bn256_fuzz.go +++ b/tests/fuzzers/bn256/bn256_fuzz.go @@ -227,7 +227,7 @@ func normalizeGTToGnark(cloudflareOrGoogleGT []byte) *gnark.GT { u_3 := new(big.Int).Mul(big.NewInt(3), u) // 3*u inner := u_6_exp2.Add(u_6_exp2, u_3) // 6*u^2 + 3*u inner.Add(inner, big.NewInt(1)) // 6*u^2 + 3*u + 1 - u_2 := new(big.Int).Mul(big.NewInt(2), u) // 2*u + u_2 := new(big.Int).Lsh(u, 1) // 2*u s := u_2.Mul(u_2, inner) // 2*u(6*u^2 + 3*u + 1) // Scale the Cloudflare/Google GT element by `s`