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
16 changes: 6 additions & 10 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
)
}
Expand All @@ -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)
}

Expand All @@ -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
}
}

Expand Down Expand Up @@ -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)))
Expand Down
16 changes: 8 additions & 8 deletions erigon-lib/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@ 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
signer.accessList = true
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions execution/consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions txnprovider/shutter/internal/crypto/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading