Skip to content

Commit 6a7f64e

Browse files
authored
core/vm: use go-bigmodexpfix for modexp (ethereum#32576)
This changes the modexp precompile to use a fork of math/big with some patches by @GottfriedHerold to improve worst-case performance.
1 parent 03b77d1 commit 6a7f64e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

core/vm/contracts.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381"
3131
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
3232
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
33+
patched_big "github.com/ethereum/go-bigmodexpfix/src/math/big"
3334
"github.com/ethereum/go-ethereum/common"
3435
"github.com/ethereum/go-ethereum/common/bitutil"
3536
"github.com/ethereum/go-ethereum/core/tracing"
@@ -631,9 +632,9 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
631632
}
632633
// Retrieve the operands and execute the exponentiation
633634
var (
634-
base = new(big.Int).SetBytes(getData(input, 0, baseLen))
635-
exp = new(big.Int).SetBytes(getData(input, baseLen, expLen))
636-
mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
635+
base = new(patched_big.Int).SetBytes(getData(input, 0, baseLen))
636+
exp = new(patched_big.Int).SetBytes(getData(input, baseLen, expLen))
637+
mod = new(patched_big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
637638
v []byte
638639
)
639640
switch {

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0
2424
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3
2525
github.com/ethereum/c-kzg-4844/v2 v2.1.0
26+
github.com/ethereum/go-bigmodexpfix v0.0.0-20250911101455-f9e208c548ab
2627
github.com/ethereum/go-verkle v0.2.2
2728
github.com/fatih/color v1.16.0
2829
github.com/ferranbt/fastssz v0.1.4
@@ -67,7 +68,7 @@ require (
6768
golang.org/x/crypto v0.36.0
6869
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
6970
golang.org/x/sync v0.12.0
70-
golang.org/x/sys v0.31.0
71+
golang.org/x/sys v0.36.0
7172
golang.org/x/text v0.23.0
7273
golang.org/x/time v0.9.0
7374
golang.org/x/tools v0.29.0

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ github.com/emicklei/dot v1.6.2 h1:08GN+DD79cy/tzN6uLCT84+2Wk9u+wvqP+Hkx/dIR8A=
114114
github.com/emicklei/dot v1.6.2/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
115115
github.com/ethereum/c-kzg-4844/v2 v2.1.0 h1:gQropX9YFBhl3g4HYhwE70zq3IHFRgbbNPw0Shwzf5w=
116116
github.com/ethereum/c-kzg-4844/v2 v2.1.0/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E=
117+
github.com/ethereum/go-bigmodexpfix v0.0.0-20250911101455-f9e208c548ab h1:rvv6MJhy07IMfEKuARQ9TKojGqLVNxQajaXEp/BoqSk=
118+
github.com/ethereum/go-bigmodexpfix v0.0.0-20250911101455-f9e208c548ab/go.mod h1:IuLm4IsPipXKF7CW5Lzf68PIbZ5yl7FFd74l/E0o9A8=
117119
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
118120
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
119121
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
@@ -449,8 +451,8 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
449451
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
450452
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
451453
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
452-
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
453-
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
454+
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
455+
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
454456
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
455457
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
456458
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

0 commit comments

Comments
 (0)