core/vm: remove cache, update gnark

This commit is contained in:
MariusVanDerWijden 2025-06-13 14:47:28 +02:00
parent dc17a38a5d
commit b1495ab367
4 changed files with 36 additions and 26 deletions

View file

@ -29,6 +29,7 @@ import (
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
"github.com/consensys/gnark-crypto/ecc/bn254"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/crypto"
@ -506,17 +507,18 @@ func newTwistPoint(blob []byte) (*bn256.G2, error) {
// runBn256Add implements the Bn256Add precompile, referenced by both
// Byzantium and Istanbul operations.
func runBn256Add(input []byte) ([]byte, error) {
x, err := newCurvePoint(getData(input, 0, 64))
x := &bn254.G1Affine{}
_, err := x.SetBytes(getData(input, 0, 64))
if err != nil {
return nil, err
}
y, err := newCurvePoint(getData(input, 64, 64))
y := &bn254.G1Affine{}
_, err = y.SetBytes(getData(input, 64, 64))
if err != nil {
return nil, err
}
res := new(bn256.G1)
res.Add(x, y)
return res.Marshal(), nil
x = x.Add(x, y)
return x.Marshal(), nil
}
// bn256AddIstanbul implements a native elliptic curve point addition conforming to

View file

@ -17,23 +17,29 @@ func init() {
}
func addCache(precompile common.Address, input, output []byte) {
mu.Lock()
defer mu.Unlock()
cache, ok := caches[precompile]
if !ok {
cache = lru.NewCache[string, []byte](128)
caches[precompile] = cache
}
cache.Add(string(input), output)
/*
mu.Lock()
defer mu.Unlock()
cache, ok := caches[precompile]
if !ok {
cache = lru.NewCache[string, []byte](128)
caches[precompile] = cache
}
cache.Add(string(input), output)
*/
}
func getCache(precompile common.Address, input []byte) ([]byte, bool) {
mu.RLock()
defer mu.RUnlock()
cache, ok := caches[precompile]
if !ok {
caches[precompile] = lru.NewCache[string, []byte](128)
return nil, false
}
return cache.Get(string(input))
/*
mu.RLock()
defer mu.RUnlock()
cache, ok := caches[precompile]
if !ok {
caches[precompile] = lru.NewCache[string, []byte](128)
return nil, false
}
return cache.Get(string(input))
*/
return nil, false
}

6
go.mod
View file

@ -13,7 +13,7 @@ require (
github.com/cespare/cp v0.1.0
github.com/cloudflare/cloudflare-go v0.114.0
github.com/cockroachdb/pebble v1.1.5
github.com/consensys/gnark-crypto v0.16.0
github.com/consensys/gnark-crypto v0.18.0
github.com/crate-crypto/go-eth-kzg v1.3.0
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a
github.com/davecgh/go-spew v1.1.1
@ -28,6 +28,7 @@ require (
github.com/fjl/gencodec v0.1.0
github.com/fsnotify/fsnotify v1.6.0
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff
github.com/goccy/go-json v0.10.4
github.com/gofrs/flock v0.8.1
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
@ -98,7 +99,7 @@ require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.27 // indirect
github.com/consensys/bavard v0.1.31-0.20250406004941-2db259e4b582 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/deepmap/oapi-codegen v1.6.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
@ -106,7 +107,6 @@ require (
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/goccy/go-json v0.10.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect

6
go.sum
View file

@ -74,10 +74,12 @@ github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwP
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/consensys/bavard v0.1.27 h1:j6hKUrGAy/H+gpNrpLU3I26n1yc+VMGmd6ID5+gAhOs=
github.com/consensys/bavard v0.1.27/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
github.com/consensys/bavard v0.1.31-0.20250406004941-2db259e4b582 h1:dTlIwEdFQmldzFf5F6bbTcYWhvnAgZai2g8eq3Wwxqg=
github.com/consensys/bavard v0.1.31-0.20250406004941-2db259e4b582/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
github.com/consensys/gnark-crypto v0.16.0 h1:8Dl4eYmUWK9WmlP1Bj6je688gBRJCJbT8Mw4KoTAawo=
github.com/consensys/gnark-crypto v0.16.0/go.mod h1:Ke3j06ndtPTVvo++PhGNgvm+lgpLvzbcE2MqljY7diU=
github.com/consensys/gnark-crypto v0.18.0 h1:vIye/FqI50VeAr0B3dx+YjeIvmc3LWz4yEfbWBpTUf0=
github.com/consensys/gnark-crypto v0.18.0/go.mod h1:L3mXGFTe1ZN+RSJ+CLjUt9x7PNdx8ubaYfDROyp2Z8c=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crate-crypto/go-eth-kzg v1.3.0 h1:05GrhASN9kDAidaFJOda6A4BEvgvuXbazXg/0E3OOdI=