diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 46a10723e66..b6cb0acb88e 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -171,23 +171,24 @@ var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{ } var PrecompiledContractsOsaka = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{0x01}): &ecrecover{}, - common.BytesToAddress([]byte{0x02}): &sha256hash{}, - common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, - common.BytesToAddress([]byte{0x04}): &dataCopy{}, - common.BytesToAddress([]byte{0x05}): &bigModExp{osaka: true}, - common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{0x09}): &blake2F{}, - common.BytesToAddress([]byte{0x0a}): &pointEvaluation{}, - common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{}, - common.BytesToAddress([]byte{0x0c}): &bls12381G1MultiExp{}, - common.BytesToAddress([]byte{0x0d}): &bls12381G2Add{}, - common.BytesToAddress([]byte{0x0e}): &bls12381G2MultiExp{}, - common.BytesToAddress([]byte{0x0f}): &bls12381Pairing{}, - common.BytesToAddress([]byte{0x10}): &bls12381MapFpToG1{}, - common.BytesToAddress([]byte{0x11}): &bls12381MapFp2ToG2{}, + common.BytesToAddress([]byte{0x01}): &ecrecover{}, + common.BytesToAddress([]byte{0x02}): &sha256hash{}, + common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, + common.BytesToAddress([]byte{0x04}): &dataCopy{}, + common.BytesToAddress([]byte{0x05}): &bigModExp{osaka: true}, + common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{0x09}): &blake2F{}, + common.BytesToAddress([]byte{0x0a}): &pointEvaluation{}, + common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{}, + common.BytesToAddress([]byte{0x0c}): &bls12381G1MultiExp{}, + common.BytesToAddress([]byte{0x0d}): &bls12381G2Add{}, + common.BytesToAddress([]byte{0x0e}): &bls12381G2MultiExp{}, + common.BytesToAddress([]byte{0x0f}): &bls12381Pairing{}, + common.BytesToAddress([]byte{0x10}): &bls12381MapFpToG1{}, + common.BytesToAddress([]byte{0x11}): &bls12381MapFp2ToG2{}, + common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, } var ( @@ -427,21 +428,19 @@ func modExpMultComplexityEip2565(x *big.Int) *big.Int { // // def mult_complexity(x): // -// words = math.ceil(x / 8) -// multiplication_complexity = 0 -// if x <= 32: multiplication_complexity = words**2 -// elif x > 32: multiplication_complexity = 2 * words**2 -// return multiplication_complexity +// max_length = max(base_length, modulus_length) +// words = math.ceil(max_length / 8) +// multiplication_complexity = 16 +// if max_length > 32: multiplication_complexity = 2 * words**2 +// return multiplication_complexity // // where is x is max(length_of_MODULUS, length_of_BASE) func modExpMultComplexityEip7883(x *big.Int) *big.Int { - lessOrEq32 := x.Cmp(big32) <= 0 - x = modExpMultComplexityEip2565(x) - if lessOrEq32 { - return x - } else { + if x.Cmp(big32) > 0 { + x = modExpMultComplexityEip2565(x) return x.Lsh(x, 1) // ×2 } + return x.SetUint64(16) } // RequiredGas returns the gas required to execute the pre-compiled contract. @@ -485,10 +484,10 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { adjExpLen = math.BigMax(adjExpLen, big1) // Calculate the gas cost of the operation - gas := new(big.Int).Set(math.BigMax(modLen, baseLen)) + gas := new(big.Int).Set(math.BigMax(modLen, baseLen)) // max_length if c.osaka { // EIP-7883: ModExp Gas Cost Increase - gas = modExpMultComplexityEip7883(gas) + gas = modExpMultComplexityEip7883(gas /*max_length */) gas.Mul(gas, adjExpLen) gas.Div(gas, big3)