diff --git a/core/vm/contracts.go b/core/vm/contracts.go index d80497d784..826b225f1a 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -66,7 +66,7 @@ var PrecompiledContractsByzantium = PrecompiledContracts{ common.BytesToAddress([]byte{0x2}): &sha256hash{}, common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, 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{0x7}): &bn256ScalarMulByzantium{}, common.BytesToAddress([]byte{0x8}): &bn256PairingByzantium{}, @@ -79,7 +79,7 @@ var PrecompiledContractsIstanbul = PrecompiledContracts{ common.BytesToAddress([]byte{0x2}): &sha256hash{}, common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, 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{0x7}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, @@ -93,7 +93,7 @@ var PrecompiledContractsBerlin = PrecompiledContracts{ common.BytesToAddress([]byte{0x2}): &sha256hash{}, common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, 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{0x7}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, @@ -107,7 +107,7 @@ var PrecompiledContractsCancun = PrecompiledContracts{ common.BytesToAddress([]byte{0x2}): &sha256hash{}, common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, 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{0x7}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, @@ -122,7 +122,7 @@ var PrecompiledContractsPrague = PrecompiledContracts{ common.BytesToAddress([]byte{0x02}): &sha256hash{}, common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, 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{0x07}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, @@ -148,7 +148,7 @@ var PrecompiledContractsOsaka = PrecompiledContracts{ common.BytesToAddress([]byte{0x02}): &sha256hash{}, common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, 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{0x07}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, @@ -342,6 +342,7 @@ func (c *dataCopy) Run(in []byte) ([]byte, error) { type bigModExp struct { eip2565 bool eip7823 bool + eip7883 bool } var ( @@ -427,6 +428,7 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { } else { gas.Set(modLen) } + maxLen := new(big.Int).Set(gas) if c.eip2565 { // EIP-2565 has three changes // 1. Different multComplexity (inlined here) @@ -440,6 +442,14 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { gas.Rsh(gas, 3) 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 { gas.Mul(gas, adjExpLen) } @@ -448,9 +458,9 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { if gas.BitLen() > 64 { return math.MaxUint64 } - // 3. Minimum price of 200 gas - if gas.Uint64() < 200 { - return 200 + + if gas.Uint64() < minPrice { + return minPrice } return gas.Uint64() } diff --git a/tests/testdata b/tests/testdata index 81862e4848..faf33b4714 160000 --- a/tests/testdata +++ b/tests/testdata @@ -1 +1 @@ -Subproject commit 81862e4848585a438d64f911a19b3825f0f4cd95 +Subproject commit faf33b471465d3c6cdc3d04fbd690895f78d33f2