dencun-devnet: --trusted-setup-file flag support (#7963)

This commit is contained in:
racytech 2023-08-03 18:36:47 +06:00 committed by GitHub
parent 29935a65f4
commit 2c2ccb6e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 58 deletions

View File

@ -27,18 +27,18 @@ import (
"strings"
"github.com/c2h5oh/datasize"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/urfave/cli/v2"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/cmp"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/common/metrics"
libkzg "github.com/ledgerwatch/erigon-lib/crypto/kzg"
"github.com/ledgerwatch/erigon-lib/direct"
downloadercfg2 "github.com/ledgerwatch/erigon-lib/downloader/downloadercfg"
"github.com/ledgerwatch/erigon-lib/txpool/txpoolcfg"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/urfave/cli/v2"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cmd/downloader/downloadernat"
@ -108,6 +108,10 @@ var (
Name: "override.shanghaiTime",
Usage: "Manually specify Shanghai fork time, overriding the bundled setting",
}
TrustedSetupFile = cli.StringFlag{
Name: "trusted-setup-file",
Usage: "Absolute path to trusted_setup.json file",
}
// Ethash settings
EthashCachesInMemoryFlag = cli.IntFlag{
Name: "ethash.cachesinmem",
@ -1592,6 +1596,10 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
if ctx.IsSet(SentryDropUselessPeers.Name) {
cfg.DropUselessPeers = ctx.Bool(SentryDropUselessPeers.Name)
}
if ctx.IsSet(TrustedSetupFile.Name) {
libkzg.SetTrustedSetupFilePath(ctx.String(TrustedSetupFile.Name))
}
}
// SetDNSDiscoveryDefaults configures DNS discovery with the given URL if

View File

@ -27,6 +27,7 @@ import (
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
libkzg "github.com/ledgerwatch/erigon-lib/crypto/kzg"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/math"
@ -35,7 +36,7 @@ import (
"github.com/ledgerwatch/erigon/crypto/blake2b"
"github.com/ledgerwatch/erigon/crypto/bls12381"
"github.com/ledgerwatch/erigon/crypto/bn256"
"github.com/ledgerwatch/erigon/crypto/kzg"
"github.com/ledgerwatch/erigon/params"
//lint:ignore SA1019 Needed for precompile
@ -1113,7 +1114,7 @@ func (c *pointEvaluation) RequiredGas(input []byte) uint64 {
}
func (c *pointEvaluation) Run(input []byte) ([]byte, error) {
return kzg.PointEvaluationPrecompile(input)
return libkzg.PointEvaluationPrecompile(input)
}
type parentBeaconBlockRoot struct{}

View File

@ -1,65 +1,65 @@
package kzg
import (
"errors"
"fmt"
"math/big"
// import (
// "errors"
// "fmt"
// "math/big"
gokzg4844 "github.com/crate-crypto/go-kzg-4844"
// gokzg4844 "github.com/crate-crypto/go-kzg-4844"
libkzg "github.com/ledgerwatch/erigon-lib/crypto/kzg"
)
// libkzg "github.com/ledgerwatch/erigon-lib/crypto/kzg"
// )
const (
PrecompileInputLength int = 192
)
// const (
// PrecompileInputLength int = 192
// )
var (
errInvalidInputLength = errors.New("invalid input length")
// var (
// errInvalidInputLength = errors.New("invalid input length")
// The value that gets returned when the `verify_kzg_proof“ precompile is called
precompileReturnValue [64]byte
)
// // The value that gets returned when the `verify_kzg_proof“ precompile is called
// precompileReturnValue [64]byte
// )
// InitializeCrypytoCtx initializes the global context object returned via CryptoCtx
func init() {
new(big.Int).SetUint64(gokzg4844.ScalarsPerBlob).FillBytes(precompileReturnValue[:32])
copy(precompileReturnValue[32:], gokzg4844.BlsModulus[:])
}
// // InitializeCrypytoCtx initializes the global context object returned via CryptoCtx
// func init() {
// new(big.Int).SetUint64(gokzg4844.ScalarsPerBlob).FillBytes(precompileReturnValue[:32])
// copy(precompileReturnValue[32:], gokzg4844.BlsModulus[:])
// }
// PointEvaluationPrecompile implements point_evaluation_precompile from EIP-4844
func PointEvaluationPrecompile(input []byte) ([]byte, error) {
if len(input) != PrecompileInputLength {
return nil, errInvalidInputLength
}
// versioned hash: first 32 bytes
var versionedHash [32]byte
copy(versionedHash[:], input[:32])
// // PointEvaluationPrecompile implements point_evaluation_precompile from EIP-4844
// func PointEvaluationPrecompile(input []byte) ([]byte, error) {
// if len(input) != PrecompileInputLength {
// return nil, errInvalidInputLength
// }
// // versioned hash: first 32 bytes
// var versionedHash [32]byte
// copy(versionedHash[:], input[:32])
var x, y [32]byte
// Evaluation point: next 32 bytes
copy(x[:], input[32:64])
// Expected output: next 32 bytes
copy(y[:], input[64:96])
// var x, y [32]byte
// // Evaluation point: next 32 bytes
// copy(x[:], input[32:64])
// // Expected output: next 32 bytes
// copy(y[:], input[64:96])
// input kzg point: next 48 bytes
var dataKZG [48]byte
copy(dataKZG[:], input[96:144])
if libkzg.KZGToVersionedHash(dataKZG) != versionedHash {
return nil, errors.New("mismatched versioned hash")
}
// // input kzg point: next 48 bytes
// var dataKZG [48]byte
// copy(dataKZG[:], input[96:144])
// if libkzg.KZGToVersionedHash(dataKZG) != versionedHash {
// return nil, errors.New("mismatched versioned hash")
// }
// Quotient kzg: next 48 bytes
var quotientKZG [48]byte
copy(quotientKZG[:], input[144:PrecompileInputLength])
// // Quotient kzg: next 48 bytes
// var quotientKZG [48]byte
// copy(quotientKZG[:], input[144:PrecompileInputLength])
cryptoCtx := libkzg.Ctx()
err := cryptoCtx.VerifyKZGProof(dataKZG, x, y, quotientKZG)
if err != nil {
return nil, fmt.Errorf("verify_kzg_proof error: %v", err)
}
// cryptoCtx := libkzg.Ctx()
// err := cryptoCtx.VerifyKZGProof(dataKZG, x, y, quotientKZG)
// if err != nil {
// return nil, fmt.Errorf("verify_kzg_proof error: %v", err)
// }
result := precompileReturnValue // copy the value
// result := precompileReturnValue // copy the value
return result[:], nil
}
// return result[:], nil
// }

4
go.mod
View File

@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.19
require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230801161656-f33b0bc5382c
github.com/ledgerwatch/erigon-lib v0.0.0-20230803063510-d4f8da719e8f
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230622075030-1d69651854c2
github.com/ledgerwatch/log/v3 v3.8.0
github.com/ledgerwatch/secp256k1 v1.0.0
@ -169,6 +169,7 @@ require (
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/ledgerwatch/interfaces v0.0.0-20230731192530-801b5852e33e // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
@ -182,6 +183,7 @@ require (
github.com/lispad/go-generics-tools v1.1.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/matryer/moq v0.3.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect

6
go.sum
View File

@ -501,8 +501,12 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230801161656-f33b0bc5382c h1:n1bMHtplRq5CoiX64kIRWs5WUvyk3fByVDR4yRDwHGk=
github.com/ledgerwatch/erigon-lib v0.0.0-20230801161656-f33b0bc5382c/go.mod h1:v9r+BsZyoO1CFZ7BwTcRpfVNXzJhGA5qokUUxtahxXw=
github.com/ledgerwatch/erigon-lib v0.0.0-20230803063510-d4f8da719e8f h1:oAA0cTo3NHErzFOOe/U/bp+i5erNvnSAkV8HejPLoko=
github.com/ledgerwatch/erigon-lib v0.0.0-20230803063510-d4f8da719e8f/go.mod h1:v9r+BsZyoO1CFZ7BwTcRpfVNXzJhGA5qokUUxtahxXw=
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230622075030-1d69651854c2 h1:Ls2itRGHMOr2PbHRDA4g1HH8HQdwfJhRVfMPEaLQe94=
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230622075030-1d69651854c2/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/interfaces v0.0.0-20230731192530-801b5852e33e h1:a++pG0zOOAOpF/2yRwTwbh7urXLUfO7YZQfb182vjqA=
github.com/ledgerwatch/interfaces v0.0.0-20230731192530-801b5852e33e/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/log/v3 v3.8.0 h1:gCpp7uGtIerEz1jKVPeDnbIopFPud9ZnCpBLlLBGqPU=
github.com/ledgerwatch/log/v3 v3.8.0/go.mod h1:J2Jl6zV/58LeA6LTaVVnCGyf1/cYYSEOOLHY4ZN8S2A=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=
@ -546,6 +550,8 @@ github.com/maticnetwork/crand v1.0.2 h1:Af0tAivC8zrxXDpGWNWVT/0s1fOz8w0eRbahZgUR
github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxpj5ZKxfHjyg=
github.com/maticnetwork/polyproto v0.0.2 h1:cPxuxbIDItdwGnucc3lZB58U8Zfe1mH73PWTGd15554=
github.com/maticnetwork/polyproto v0.0.2/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/matryer/moq v0.3.2 h1:z7oltmpTxiQ9nKNg0Jc7z45TM+eO7OhCVohxRxwaudM=
github.com/matryer/moq v0.3.2/go.mod h1:RJ75ZZZD71hejp39j4crZLsEDszGk6iH4v4YsWFKH4s=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=

View File

@ -158,4 +158,6 @@ var DefaultFlags = []cli.Flag{
&utils.SentinelPortFlag,
&utils.OtsSearchMaxCapFlag,
&utils.TrustedSetupFile,
}