mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
feat: introduces BLS signature verification precompile (#52)
* feat: adds BLS precompile * feat: activates cancun upgrade
This commit is contained in:
parent
5219dc39b6
commit
a9bcf58160
5 changed files with 41 additions and 1 deletions
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/cloudflare/circl/sign/bls"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
@ -105,6 +106,9 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{
|
||||||
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
|
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
|
||||||
common.BytesToAddress([]byte{9}): &blake2F{},
|
common.BytesToAddress([]byte{9}): &blake2F{},
|
||||||
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
|
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
|
||||||
|
|
||||||
|
// primev pre-compiles start at 0xf addresses
|
||||||
|
common.BytesToAddress([]byte{0xf0}): &bls12381SignatureVerification{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
|
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
|
||||||
|
|
@ -653,6 +657,34 @@ var (
|
||||||
errBLS12381G2PointSubgroup = errors.New("g2 point is not on correct subgroup")
|
errBLS12381G2PointSubgroup = errors.New("g2 point is not on correct subgroup")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// bls12381SignatureVerification implements BLS signature verification precompile.
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// bls12381G1Add implements EIP-2537 G1Add precompile.
|
// bls12381G1Add implements EIP-2537 G1Add precompile.
|
||||||
type bls12381G1Add struct{}
|
type bls12381G1Add struct{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
"muirGlacierBlock": 0,
|
"muirGlacierBlock": 0,
|
||||||
"berlinBlock": 0,
|
"berlinBlock": 0,
|
||||||
"londonBlock": 0,
|
"londonBlock": 0,
|
||||||
|
"cancunTime": 0,
|
||||||
"arrowGlacierBlock": 0,
|
"arrowGlacierBlock": 0,
|
||||||
"grayGlacierBlock": 0,
|
"grayGlacierBlock": 0,
|
||||||
"clique": {
|
"clique": {
|
||||||
|
|
|
||||||
5
go.mod
5
go.mod
|
|
@ -1,6 +1,8 @@
|
||||||
module github.com/ethereum/go-ethereum
|
module github.com/ethereum/go-ethereum
|
||||||
|
|
||||||
go 1.20
|
go 1.22.0
|
||||||
|
|
||||||
|
toolchain go1.23.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
|
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
|
||||||
|
|
@ -91,6 +93,7 @@ require (
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/bits-and-blooms/bitset v1.10.0 // indirect
|
github.com/bits-and-blooms/bitset v1.10.0 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
|
github.com/cloudflare/circl v1.5.0 // indirect
|
||||||
github.com/cockroachdb/errors v1.8.1 // indirect
|
github.com/cockroachdb/errors v1.8.1 // indirect
|
||||||
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
|
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
|
||||||
github.com/cockroachdb/redact v1.0.8 // indirect
|
github.com/cockroachdb/redact v1.0.8 // indirect
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -116,6 +116,8 @@ github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86c
|
||||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||||
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
|
github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys=
|
||||||
|
github.com/cloudflare/circl v1.5.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||||
github.com/cloudflare/cloudflare-go v0.79.0 h1:ErwCYDjFCYppDJlDJ/5WhsSmzegAUe2+K9qgFyQDg3M=
|
github.com/cloudflare/cloudflare-go v0.79.0 h1:ErwCYDjFCYppDJlDJ/5WhsSmzegAUe2+K9qgFyQDg3M=
|
||||||
github.com/cloudflare/cloudflare-go v0.79.0/go.mod h1:gkHQf9xEubaQPEuerBuoinR9P8bf8a05Lq0X6WKy1Oc=
|
github.com/cloudflare/cloudflare-go v0.79.0/go.mod h1:gkHQf9xEubaQPEuerBuoinR9P8bf8a05Lq0X6WKy1Oc=
|
||||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,8 @@ const (
|
||||||
Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation
|
Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation
|
||||||
Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation
|
Bls12381MapG2Gas uint64 = 110000 // 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,
|
// 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. Redefined as 1/5th in EIP-3529
|
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529
|
||||||
RefundQuotient uint64 = 2
|
RefundQuotient uint64 = 2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue