From e8d13ca9fb66f5b4e9b1acebd704407d880f2a79 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Thu, 10 Apr 2025 22:15:26 +0800 Subject: [PATCH] core/vm: implement eip 7883 (modexp repricing) --- core/vm/contracts.go | 16 +++++++++++++--- tests/testdata | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 784b410802..f2ceec2394 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -317,6 +317,7 @@ func (c *dataCopy) Run(in []byte) ([]byte, error) { // bigModExp implements a native big integer exponential modular operation. type bigModExp struct { eip2565 bool + eip7883 bool } var ( @@ -402,6 +403,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) @@ -415,6 +417,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) } @@ -423,9 +433,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