Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ package utils
import (
"crypto/ecdsa"
"fmt"
"github.com/c2h5oh/datasize"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/urfave/cli/v2"
"math/big"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/c2h5oh/datasize"
"github.com/erigontech/erigon-lib/chain/networkid"
"github.com/erigontech/erigon-lib/chain/networkname"
"github.com/erigontech/erigon-lib/chain/snapcfg"
Expand Down Expand Up @@ -66,6 +63,9 @@ import (
"github.com/erigontech/erigon/turbo/logging"
"github.com/erigontech/erigon/txnprovider/shutter"
"github.com/erigontech/erigon/txnprovider/txpool/txpoolcfg"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/urfave/cli/v2"
)

// These are all the command line flags we support.
Expand Down
32 changes: 32 additions & 0 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"errors"
"math/big"

"github.com/cloudflare/circl/sign/bls"
"github.com/consensys/gnark-crypto/ecc"
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
Expand Down Expand Up @@ -101,6 +102,9 @@ var PrecompiledContractsBerlin = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
libcommon.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
libcommon.BytesToAddress([]byte{9}): &blake2F{},

// primev pre-compiles start at 0xf addresses
libcommon.BytesToAddress([]byte{0xf0}): &bls12381SignatureVerification{},
}

var PrecompiledContractsCancun = map[libcommon.Address]PrecompiledContract{
Expand Down Expand Up @@ -1173,3 +1177,31 @@ func (c *p256Verify) Run(input []byte) ([]byte, error) {
return nil, nil
}
}

// bls12381SignatureVerification implements BLS signature verification precompile.Add commentMore actions
type bls12381SignatureVerification struct{}

// RequiredGas returns the gas required to execute the pre-compiled contract.
func (c *bls12381SignatureVerification) RequiredGas(input []byte) uint64 {
return params.BlsSignVerifyGas
}

func (c *bls12381SignatureVerification) Run(input []byte) ([]byte, error) {
// Input format:
// - pubkey (48 bytes) - G1 point
// - message (32 bytes) - Hash of the message
// - signature (96 bytes) - G2 point
if len(input) != 176 {
return nil, errBLS12381InvalidInputLength
}

var pubKey bls.PublicKey[bls.G1]
if err := pubKey.UnmarshalBinary(input[:48]); err != nil {
return nil, err
}

if !bls.Verify(&pubKey, input[48:80], input[80:]) {
return nil, nil
}
return input[:48], nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ require (
github.com/RoaringBitmap/roaring v1.9.4 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20221111143132-9aa5d42120bc // indirect
github.com/elastic/go-freelru v0.13.0 // indirect
github.com/erigontech/speedtest v0.0.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX
github.com/cilium/ebpf v0.11.0 h1:V8gS/bTCCjX9uUnkUFUpPsksM8n1lXBAvHcpiFk1X2Y=
github.com/cilium/ebpf v0.11.0/go.mod h1:WE7CZAnqOL2RouJ4f1uyNhqr2P4CCvXFIqdRDUgWsVs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down
17 changes: 9 additions & 8 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ const (
Bn256PairingPerPointGasByzantium uint64 = 80000 // Byzantium per-point price for an elliptic curve pairing check
Bn256PairingPerPointGasIstanbul uint64 = 34000 // Per-point price for an elliptic curve pairing check

Bls12381G1AddGas uint64 = 375 // Price for BLS12-381 elliptic curve G1 point addition
Bls12381G1MulGas uint64 = 12000 // Price for BLS12-381 elliptic curve G1 point scalar multiplication
Bls12381G2AddGas uint64 = 600 // Price for BLS12-381 elliptic curve G2 point addition
Bls12381G2MulGas uint64 = 22500 // Price for BLS12-381 elliptic curve G2 point scalar multiplication
Bls12381PairingBaseGas uint64 = 37700 // Base gas price for BLS12-381 elliptic curve pairing check
Bls12381PairingPerPairGas uint64 = 32600 // Per-point pair gas price for BLS12-381 elliptic curve pairing check
Bls12381MapFpToG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation
Bls12381MapFp2ToG2Gas uint64 = 23800 // Gas price for BLS12-381 mapping field element to G2 operation
Bls12381G1AddGas uint64 = 375 // Price for BLS12-381 elliptic curve G1 point addition
Bls12381G1MulGas uint64 = 12000 // Price for BLS12-381 elliptic curve G1 point scalar multiplication
Bls12381G2AddGas uint64 = 600 // Price for BLS12-381 elliptic curve G2 point addition
Bls12381G2MulGas uint64 = 22500 // Price for BLS12-381 elliptic curve G2 point scalar multiplication
Bls12381PairingBaseGas uint64 = 37700 // Base gas price for BLS12-381 elliptic curve pairing check
Bls12381PairingPerPairGas uint64 = 32600 // Per-point pair gas price for BLS12-381 elliptic curve pairing check
Bls12381MapFpToG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation
Bls12381MapFp2ToG2Gas uint64 = 23800 // Gas price for BLS12-381 mapping field element to G2 operation
BlsSignVerifyGas uint64 = 150000 // Gas price for BLS12-381 signature verification

// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
// up to half the consumed gas could be refunded.
Expand Down