diff --git a/core/vm/contracts.go b/core/vm/contracts.go index d6a2c6a2622..f7be0d794bf 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -342,12 +342,8 @@ type bigModExp struct { var ( big1 = big.NewInt(1) - big2 = big.NewInt(2) 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) @@ -374,13 +370,13 @@ func modExpMultComplexityEip198(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), ) } @@ -397,7 +393,7 @@ func modExpMultComplexityEip198(x *big.Int) *big.Int { // where is x is max(length_of_MODULUS, length_of_BASE) func modExpMultComplexityEip2565(x *big.Int) *big.Int { x.Add(x, big7) - x.Div(x, big8) + x.Rsh(x, 3) // ÷8 return x.Mul(x, x) } @@ -418,7 +414,7 @@ func modExpMultComplexityEip7883(x *big.Int) *big.Int { if lessOrEq32 { return x } else { - return x.Mul(x, big2) + return x.Lsh(x, 1) // ×2 } } @@ -454,9 +450,9 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { if expLen.Cmp(big32) > 0 { adjExpLen.Sub(expLen, big32) if c.eip7883 { - adjExpLen.Mul(big16, adjExpLen) + adjExpLen.Lsh(adjExpLen, 4) // ×16 } else { - adjExpLen.Mul(big8, adjExpLen) + adjExpLen.Lsh(adjExpLen, 3) // ×8 } } adjExpLen.Add(adjExpLen, big.NewInt(int64(msb))) diff --git a/erigon-lib/types/transaction_signing.go b/erigon-lib/types/transaction_signing.go index 5a512475940..7be2dd6bc4c 100644 --- a/erigon-lib/types/transaction_signing.go +++ b/erigon-lib/types/transaction_signing.go @@ -56,7 +56,7 @@ func MakeSigner(config *chain.Config, blockNumber uint64, blockTime uint64) *Sig signer.blob = true signer.setCode = true signer.chainID.Set(&chainId) - signer.chainIDMul.Mul(&chainId, u256.Num2) + signer.chainIDMul.Lsh(&chainId, 1) // ×2 case config.IsCancun(blockTime): // All transaction types are still supported signer.protected = true @@ -64,22 +64,22 @@ func MakeSigner(config *chain.Config, blockNumber uint64, blockTime uint64) *Sig signer.dynamicFee = true signer.blob = true signer.chainID.Set(&chainId) - signer.chainIDMul.Mul(&chainId, u256.Num2) + signer.chainIDMul.Lsh(&chainId, 1) // ×2 case config.IsLondon(blockNumber): signer.protected = true signer.accessList = true signer.dynamicFee = true signer.chainID.Set(&chainId) - signer.chainIDMul.Mul(&chainId, u256.Num2) + signer.chainIDMul.Lsh(&chainId, 1) // ×2 case config.IsBerlin(blockNumber): signer.protected = true signer.accessList = true signer.chainID.Set(&chainId) - signer.chainIDMul.Mul(&chainId, u256.Num2) + signer.chainIDMul.Lsh(&chainId, 1) // ×2 case config.IsSpuriousDragon(blockNumber): signer.protected = true signer.chainID.Set(&chainId) - signer.chainIDMul.Mul(&chainId, u256.Num2) + signer.chainIDMul.Lsh(&chainId, 1) // ×2 case config.IsHomestead(blockNumber): default: // Only allow malleable transactions in Frontier @@ -110,7 +110,7 @@ func LatestSigner(config *chain.Config) *Signer { panic("chainID higher than 2^256-1") } signer.chainID.Set(chainId) - signer.chainIDMul.Mul(chainId, u256.Num2) + signer.chainIDMul.Lsh(chainId, 1) // ×2 if config.ChainID != nil { if config.CancunTime != nil { signer.blob = true @@ -149,7 +149,7 @@ func LatestSignerForChainID(chainID *big.Int) *Signer { panic("chainID higher than 2^256-1") } signer.chainID.Set(chainId) - signer.chainIDMul.Mul(chainId, u256.Num2) + signer.chainIDMul.Lsh(chainId, 1) // ×2 signer.protected = true signer.accessList = true signer.dynamicFee = true @@ -397,5 +397,5 @@ func DeriveChainId(v *uint256.Int) *uint256.Int { return new(uint256.Int).SetUint64((v - 35) / 2) } r := new(uint256.Int).Sub(v, u256.Num35) - return r.Div(r, u256.Num2) + return r.Rsh(r, 1) // ÷2 } diff --git a/execution/consensus/ethash/consensus.go b/execution/consensus/ethash/consensus.go index a212662291b..46d7a357303 100644 --- a/execution/consensus/ethash/consensus.go +++ b/execution/consensus/ethash/consensus.go @@ -658,10 +658,10 @@ func AccumulateRewards(config *chain.Config, header *types.Header, uncles []*typ r.Add(uncleNum, u256.Num8) r.Sub(r, headerNum) r.Mul(r, blockReward) - r.Div(r, u256.Num8) + r.Rsh(r, 3) // ÷8 uncleRewards = append(uncleRewards, *r) - r.Div(blockReward, u256.Num32) + r.Rsh(blockReward, 5) // ÷32 reward.Add(reward, r) } return *reward, uncleRewards diff --git a/txnprovider/shutter/internal/crypto/encryption.go b/txnprovider/shutter/internal/crypto/encryption.go index d6624516e09..7fa4fbcdbee 100644 --- a/txnprovider/shutter/internal/crypto/encryption.go +++ b/txnprovider/shutter/internal/crypto/encryption.go @@ -96,7 +96,6 @@ func fp12Exp(base *blst.Fp12, exp *big.Int) *blst.Fp12 { result := &resultValue zero := big.NewInt(0) - two := big.NewInt(2) baseCopyValue := blst.Fp12One() baseCopy := &baseCopyValue @@ -108,7 +107,7 @@ func fp12Exp(base *blst.Fp12, exp *big.Int) *blst.Fp12 { result.MulAssign(baseCopy) } baseCopy.MulAssign(baseCopy) - expCopy.Div(expCopy, two) + expCopy.Rsh(expCopy, 1) // ÷2 } return result