mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core/vm: implement eip 7883 (modexp repricing)
This commit is contained in:
parent
5e98c97abb
commit
beef56ed02
2 changed files with 20 additions and 10 deletions
|
|
@ -66,7 +66,7 @@ var PrecompiledContractsByzantium = PrecompiledContracts{
|
||||||
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
||||||
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
||||||
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
||||||
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false, eip7823: false},
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false, eip7823: false, eip7883: false},
|
||||||
common.BytesToAddress([]byte{0x6}): &bn256AddByzantium{},
|
common.BytesToAddress([]byte{0x6}): &bn256AddByzantium{},
|
||||||
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulByzantium{},
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulByzantium{},
|
||||||
common.BytesToAddress([]byte{0x8}): &bn256PairingByzantium{},
|
common.BytesToAddress([]byte{0x8}): &bn256PairingByzantium{},
|
||||||
|
|
@ -79,7 +79,7 @@ var PrecompiledContractsIstanbul = PrecompiledContracts{
|
||||||
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
||||||
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
||||||
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
||||||
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false, eip7823: false},
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false, eip7823: false, eip7883: false},
|
||||||
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
|
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
|
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
|
||||||
|
|
@ -93,7 +93,7 @@ var PrecompiledContractsBerlin = PrecompiledContracts{
|
||||||
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
||||||
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
||||||
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
||||||
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true, eip7823: false},
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true, eip7823: false, eip7883: false},
|
||||||
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
|
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
|
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
|
||||||
|
|
@ -107,7 +107,7 @@ var PrecompiledContractsCancun = PrecompiledContracts{
|
||||||
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
common.BytesToAddress([]byte{0x2}): &sha256hash{},
|
||||||
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
|
||||||
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
common.BytesToAddress([]byte{0x4}): &dataCopy{},
|
||||||
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true, eip7823: false},
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true, eip7823: false, eip7883: false},
|
||||||
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
|
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
|
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
|
||||||
|
|
@ -122,7 +122,7 @@ var PrecompiledContractsPrague = PrecompiledContracts{
|
||||||
common.BytesToAddress([]byte{0x02}): &sha256hash{},
|
common.BytesToAddress([]byte{0x02}): &sha256hash{},
|
||||||
common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
|
common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
|
||||||
common.BytesToAddress([]byte{0x04}): &dataCopy{},
|
common.BytesToAddress([]byte{0x04}): &dataCopy{},
|
||||||
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true, eip7823: false},
|
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true, eip7823: false, eip7883: false},
|
||||||
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
|
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
|
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
|
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
|
||||||
|
|
@ -148,7 +148,7 @@ var PrecompiledContractsOsaka = PrecompiledContracts{
|
||||||
common.BytesToAddress([]byte{0x02}): &sha256hash{},
|
common.BytesToAddress([]byte{0x02}): &sha256hash{},
|
||||||
common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
|
common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
|
||||||
common.BytesToAddress([]byte{0x04}): &dataCopy{},
|
common.BytesToAddress([]byte{0x04}): &dataCopy{},
|
||||||
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true, eip7823: true},
|
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true, eip7823: true, eip7883: true},
|
||||||
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
|
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
|
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
|
||||||
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
|
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
|
||||||
|
|
@ -342,6 +342,7 @@ func (c *dataCopy) Run(in []byte) ([]byte, error) {
|
||||||
type bigModExp struct {
|
type bigModExp struct {
|
||||||
eip2565 bool
|
eip2565 bool
|
||||||
eip7823 bool
|
eip7823 bool
|
||||||
|
eip7883 bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -427,6 +428,7 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
|
||||||
} else {
|
} else {
|
||||||
gas.Set(modLen)
|
gas.Set(modLen)
|
||||||
}
|
}
|
||||||
|
maxLen := new(big.Int).Set(gas)
|
||||||
if c.eip2565 {
|
if c.eip2565 {
|
||||||
// EIP-2565 has three changes
|
// EIP-2565 has three changes
|
||||||
// 1. Different multComplexity (inlined here)
|
// 1. Different multComplexity (inlined here)
|
||||||
|
|
@ -440,6 +442,14 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
|
||||||
gas.Rsh(gas, 3)
|
gas.Rsh(gas, 3)
|
||||||
gas.Mul(gas, gas)
|
gas.Mul(gas, gas)
|
||||||
|
|
||||||
|
var minPrice uint64 = 200
|
||||||
|
if c.eip7883 {
|
||||||
|
minPrice = 500
|
||||||
|
if maxLen.Cmp(big32) > 0 {
|
||||||
|
gas.Mul(gas, big.NewInt(2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if adjExpLen.Cmp(big1) > 0 {
|
if adjExpLen.Cmp(big1) > 0 {
|
||||||
gas.Mul(gas, adjExpLen)
|
gas.Mul(gas, adjExpLen)
|
||||||
}
|
}
|
||||||
|
|
@ -448,9 +458,9 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
|
||||||
if gas.BitLen() > 64 {
|
if gas.BitLen() > 64 {
|
||||||
return math.MaxUint64
|
return math.MaxUint64
|
||||||
}
|
}
|
||||||
// 3. Minimum price of 200 gas
|
|
||||||
if gas.Uint64() < 200 {
|
if gas.Uint64() < minPrice {
|
||||||
return 200
|
return minPrice
|
||||||
}
|
}
|
||||||
return gas.Uint64()
|
return gas.Uint64()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 81862e4848585a438d64f911a19b3825f0f4cd95
|
Subproject commit faf33b471465d3c6cdc3d04fbd690895f78d33f2
|
||||||
Loading…
Reference in a new issue