Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion XDCx/order_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions XDCx/tradingstate/settle_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion XDCxlending/lendingstate/settle_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion XDCxlending/order_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
22 changes: 11 additions & 11 deletions XDCxlending/order_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand All @@ -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,
},
Expand All @@ -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,
},
{
Expand All @@ -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,
},
Expand All @@ -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,
},
{
Expand All @@ -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,
Expand Down Expand Up @@ -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,
},
{
Expand Down
4 changes: 2 additions & 2 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions contracts/trc21issuer/simulation/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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)
Comment on lines +592 to +593
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name is inconsistent with the function signature. At line 592, v is being modified (using Sub which modifies the receiver), but this shadows the parameter v from line 584. The original code created a new big.Int with v = new(big.Int).Sub(v, big.NewInt(35)), but the updated code modifies the parameter directly with v.Sub(v, big.NewInt(35)). This changes the behavior by mutating the input parameter, which could cause unexpected side effects if the caller retains a reference to the parameter.

Suggested change
v.Sub(v, big.NewInt(35))
return v.Rsh(v, 1)
vCopy := new(big.Int).Sub(v, big.NewInt(35))
return vCopy.Rsh(vCopy, 1)

Copilot uses AI. Check for mistakes.
}

func CacheSigner(signer Signer, tx *Transaction) {
Expand Down
13 changes: 5 additions & 8 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
)
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/vm/privacy/ringct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions crypto/secp256k1/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is incorrect. The code performs a left shift by 1, which multiplies by 2, not 3. The comment should say "2Y1Z1" instead of "3Y1Z1". Note that this appears to be a pre-existing issue (the original code also multiplied by 2), so it's not introduced by this PR, but it would be good to fix it.

Suggested change
z3.Lsh(z3, 1) //3*Y1*Z1
z3.Lsh(z3, 1) //2*Y1*Z1

Copilot uses AI. Check for mistakes.
z3.Mod(z3, bitCurve.P)

return x3, y3, z3
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions eth/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}}
)

Expand Down
2 changes: 1 addition & 1 deletion tests/fuzzers/bn256/bn256_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Loading