mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-12 19:15:18 +00:00
feat: precompile
This commit is contained in:
parent
e348bd3748
commit
17fa02b554
4
.gitignore
vendored
4
.gitignore
vendored
@ -45,3 +45,7 @@ build/linux
|
||||
go.work
|
||||
go.work.sum
|
||||
.build/0gchaind
|
||||
.build/da
|
||||
|
||||
# runtime
|
||||
run
|
||||
|
18
app/app.go
18
app/app.go
@ -111,6 +111,8 @@ import (
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
dasignersprecompile "github.com/0glabs/0g-chain/precompiles/dasigners"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/bep3"
|
||||
bep3keeper "github.com/0glabs/0g-chain/x/bep3/keeper"
|
||||
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||
@ -124,6 +126,9 @@ import (
|
||||
das "github.com/0glabs/0g-chain/x/das/v1"
|
||||
daskeeper "github.com/0glabs/0g-chain/x/das/v1/keeper"
|
||||
dastypes "github.com/0glabs/0g-chain/x/das/v1/types"
|
||||
dasigners "github.com/0glabs/0g-chain/x/dasigners/v1"
|
||||
dasignerskeeper "github.com/0glabs/0g-chain/x/dasigners/v1/keeper"
|
||||
dasignerstypes "github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
evmutil "github.com/0glabs/0g-chain/x/evmutil"
|
||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
@ -139,6 +144,8 @@ import (
|
||||
validatorvesting "github.com/0glabs/0g-chain/x/validator-vesting"
|
||||
validatorvestingrest "github.com/0glabs/0g-chain/x/validator-vesting/client/rest"
|
||||
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -183,6 +190,7 @@ var (
|
||||
precisebank.AppModuleBasic{},
|
||||
council.AppModuleBasic{},
|
||||
das.AppModuleBasic{},
|
||||
dasigners.AppModuleBasic{},
|
||||
)
|
||||
|
||||
// module account permissions
|
||||
@ -495,7 +503,17 @@ func NewApp(
|
||||
vm.NewEVM,
|
||||
options.EVMTrace,
|
||||
evmSubspace,
|
||||
precompiles,
|
||||
)
|
||||
// dasigners keeper
|
||||
app.dasignersKeeper = dasignerskeeper.NewKeeper(keys[dasignerstypes.StoreKey], appCodec, app.stakingKeeper)
|
||||
// precopmiles
|
||||
precompiles := make(map[common.Address]vm.PrecompiledContract)
|
||||
daSignersPrecompile, err := dasignersprecompile.NewDASignersPrecompile(app.dasignersKeeper)
|
||||
if err != nil {
|
||||
panic("initialize precompile failed")
|
||||
}
|
||||
precompiles[daSignersPrecompile.Address()] = daSignersPrecompile
|
||||
|
||||
app.evmutilKeeper.SetEvmKeeper(app.evmKeeper)
|
||||
|
||||
|
@ -24,6 +24,9 @@ import (
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
db "github.com/tendermint/tm-db"
|
||||
)
|
||||
|
||||
func TestNewApp(t *testing.T) {
|
||||
|
166
crypto/bn254util/bn254util.go
Normal file
166
crypto/bn254util/bn254util.go
Normal file
@ -0,0 +1,166 @@
|
||||
package bn254util
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/consensys/gnark-crypto/ecc/bn254"
|
||||
"github.com/consensys/gnark-crypto/ecc/bn254/fp"
|
||||
"github.com/consensys/gnark-crypto/ecc/bn254/fr"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
const (
|
||||
G1PointSize = 32 * 2
|
||||
G2PointSize = 32 * 2 * 2
|
||||
)
|
||||
|
||||
var (
|
||||
FR_MODULUS, _ = new(big.Int).SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
|
||||
)
|
||||
|
||||
func VerifySig(sig *bn254.G1Affine, pubkey *bn254.G2Affine, msgBytes [32]byte) (bool, error) {
|
||||
|
||||
g2Gen := GetG2Generator()
|
||||
|
||||
msgPoint := MapToCurve(msgBytes)
|
||||
|
||||
var negSig bn254.G1Affine
|
||||
negSig.Neg((*bn254.G1Affine)(sig))
|
||||
|
||||
P := [2]bn254.G1Affine{*msgPoint, negSig}
|
||||
Q := [2]bn254.G2Affine{*pubkey, *g2Gen}
|
||||
|
||||
ok, err := bn254.PairingCheck(P[:], Q[:])
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
return ok, nil
|
||||
|
||||
}
|
||||
|
||||
func MapToCurve(digest [32]byte) *bn254.G1Affine {
|
||||
|
||||
one := new(big.Int).SetUint64(1)
|
||||
three := new(big.Int).SetUint64(3)
|
||||
x := new(big.Int)
|
||||
x.SetBytes(digest[:])
|
||||
for {
|
||||
// y = x^3 + 3
|
||||
xP3 := new(big.Int).Exp(x, big.NewInt(3), fp.Modulus())
|
||||
y := new(big.Int).Add(xP3, three)
|
||||
y.Mod(y, fp.Modulus())
|
||||
|
||||
if y.ModSqrt(y, fp.Modulus()) == nil {
|
||||
x.Add(x, one).Mod(x, fp.Modulus())
|
||||
} else {
|
||||
var fpX, fpY fp.Element
|
||||
fpX.SetBigInt(x)
|
||||
fpY.SetBigInt(y)
|
||||
return &bn254.G1Affine{
|
||||
X: fpX,
|
||||
Y: fpY,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func CheckG1AndG2DiscreteLogEquality(pointG1 *bn254.G1Affine, pointG2 *bn254.G2Affine) (bool, error) {
|
||||
negGenG1 := new(bn254.G1Affine).Neg(GetG1Generator())
|
||||
return bn254.PairingCheck([]bn254.G1Affine{*pointG1, *negGenG1}, []bn254.G2Affine{*GetG2Generator(), *pointG2})
|
||||
}
|
||||
|
||||
func GetG1Generator() *bn254.G1Affine {
|
||||
g1Gen := new(bn254.G1Affine)
|
||||
_, err := g1Gen.X.SetString("1")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
_, err = g1Gen.Y.SetString("2")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return g1Gen
|
||||
}
|
||||
|
||||
func GetG2Generator() *bn254.G2Affine {
|
||||
g2Gen := new(bn254.G2Affine)
|
||||
g2Gen.X.SetString("10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
||||
"11559732032986387107991004021392285783925812861821192530917403151452391805634")
|
||||
g2Gen.Y.SetString("8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
||||
"4082367875863433681332203403145435568316851327593401208105741076214120093531")
|
||||
return g2Gen
|
||||
}
|
||||
|
||||
func MulByGeneratorG1(a *fr.Element) *bn254.G1Affine {
|
||||
g1Gen := GetG1Generator()
|
||||
return new(bn254.G1Affine).ScalarMultiplication(g1Gen, a.BigInt(new(big.Int)))
|
||||
}
|
||||
|
||||
func MulByGeneratorG2(a *fr.Element) *bn254.G2Affine {
|
||||
g2Gen := GetG2Generator()
|
||||
return new(bn254.G2Affine).ScalarMultiplication(g2Gen, a.BigInt(new(big.Int)))
|
||||
}
|
||||
|
||||
func SerializeG1(p *bn254.G1Affine) []byte {
|
||||
b := make([]byte, 0)
|
||||
tmp := p.X.Bytes()
|
||||
for i := 0; i < 32; i++ {
|
||||
b = append(b, tmp[i])
|
||||
}
|
||||
tmp = p.Y.Bytes()
|
||||
for i := 0; i < 32; i++ {
|
||||
b = append(b, tmp[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func DeserializeG1(b []byte) *bn254.G1Affine {
|
||||
p := new(bn254.G1Affine)
|
||||
p.X.SetBytes(b[0:32])
|
||||
p.Y.SetBytes(b[32:64])
|
||||
return p
|
||||
}
|
||||
|
||||
func SerializeG2(p *bn254.G2Affine) []byte {
|
||||
b := make([]byte, 0)
|
||||
tmp := p.X.A0.Bytes()
|
||||
for i := 0; i < 32; i++ {
|
||||
b = append(b, tmp[i])
|
||||
}
|
||||
tmp = p.X.A1.Bytes()
|
||||
for i := 0; i < 32; i++ {
|
||||
b = append(b, tmp[i])
|
||||
}
|
||||
tmp = p.Y.A0.Bytes()
|
||||
for i := 0; i < 32; i++ {
|
||||
b = append(b, tmp[i])
|
||||
}
|
||||
tmp = p.Y.A1.Bytes()
|
||||
for i := 0; i < 32; i++ {
|
||||
b = append(b, tmp[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func DeserializeG2(b []byte) *bn254.G2Affine {
|
||||
p := new(bn254.G2Affine)
|
||||
p.X.A0.SetBytes(b[0:32])
|
||||
p.X.A1.SetBytes(b[32:64])
|
||||
p.Y.A0.SetBytes(b[64:96])
|
||||
p.Y.A1.SetBytes(b[96:128])
|
||||
return p
|
||||
}
|
||||
|
||||
func Gamma(hash *bn254.G1Affine, signature *bn254.G1Affine, pkG1 *bn254.G1Affine, pkG2 *bn254.G2Affine) *big.Int {
|
||||
toHash := make([]byte, 0)
|
||||
toHash = append(toHash, SerializeG1(hash)...)
|
||||
toHash = append(toHash, SerializeG1(signature)...)
|
||||
toHash = append(toHash, SerializeG1(pkG1)...)
|
||||
toHash = append(toHash, SerializeG2(pkG2)...)
|
||||
|
||||
msgHash := crypto.Keccak256(toHash)
|
||||
gamma := new(big.Int)
|
||||
gamma.SetBytes(msgHash)
|
||||
gamma.Mod(gamma, FR_MODULUS)
|
||||
return gamma
|
||||
}
|
13
go.mod
13
go.mod
@ -2,6 +2,8 @@ module github.com/0glabs/0g-chain
|
||||
|
||||
go 1.21
|
||||
|
||||
toolchain go1.21.5
|
||||
|
||||
require (
|
||||
cosmossdk.io/errors v1.0.1
|
||||
cosmossdk.io/log v1.3.1
|
||||
@ -80,6 +82,7 @@ require (
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
|
||||
github.com/confio/ics23/go v0.9.0 // indirect
|
||||
github.com/consensys/bavard v0.1.13 // indirect
|
||||
github.com/cosmos/btcutil v1.0.5 // indirect
|
||||
github.com/cosmos/gogogateway v1.2.0 // indirect
|
||||
github.com/cosmos/ics23/go v0.10.0 // indirect
|
||||
@ -92,6 +95,7 @@ require (
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
|
||||
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
|
||||
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
|
||||
github.com/dgraph-io/badger/v3 v3.2103.2 // indirect
|
||||
github.com/dgraph-io/ristretto v0.1.1 // indirect
|
||||
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
|
||||
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
|
||||
@ -118,8 +122,10 @@ require (
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/btree v1.1.2 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/orderedcode v0.0.1 // indirect
|
||||
github.com/google/flatbuffers v1.12.1 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 // indirect
|
||||
github.com/google/s2a-go v0.1.7 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
|
||||
@ -152,6 +158,7 @@ require (
|
||||
github.com/klauspost/compress v1.17.7 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/klauspost/compress v1.17.0 // indirect
|
||||
github.com/lib/pq v1.10.7 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/manifoldco/promptui v0.9.0 // indirect
|
||||
@ -164,6 +171,7 @@ require (
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/mmcloughlin/addchain v0.4.0 // indirect
|
||||
github.com/mtibben/percent v0.2.1 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
|
||||
@ -221,7 +229,8 @@ require (
|
||||
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
nhooyr.io/websocket v1.8.6 // indirect
|
||||
pgregory.net/rapid v1.1.0 // indirect
|
||||
pgregory.net/rapid v0.5.5 // indirect
|
||||
rsc.io/tmplfunc v0.0.3 // indirect
|
||||
)
|
||||
|
||||
replace (
|
||||
|
44
go.sum
44
go.sum
@ -209,13 +209,15 @@ filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
|
||||
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||
git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw=
|
||||
git.sr.ht/~sircmpwn/go-bare v0.0.0-20210406120253-ab86bc2846d9/go.mod h1:BVJwbDfVjCjoFiKrhkei6NdGcZYpkDkdyCdg1ukytRA=
|
||||
github.com/0glabs/ethermint v0.21.0-0g.v2.0.0 h1:3sfsRkaPaG7v2smfxEJ2TvwPcVMIkG8yRRVR8+tbYkc=
|
||||
github.com/0glabs/ethermint v0.21.0-0g.v2.0.0/go.mod h1:peUmQT71k9BOBgoWoIRWRrM/O01mffVjIH0RLnoaFuI=
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM=
|
||||
@ -295,6 +297,8 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
|
||||
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo=
|
||||
github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
|
||||
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/btcsuite/btcd v0.0.0-20190315201642-aa6e0f35703c/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
|
||||
@ -352,9 +356,6 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
|
||||
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
|
||||
@ -405,8 +406,12 @@ github.com/coniks-sys/coniks-go v0.0.0-20180722014011-11acf4819b71 h1:MFLTqgfJcl
|
||||
github.com/coniks-sys/coniks-go v0.0.0-20180722014011-11acf4819b71/go.mod h1:TrHYHH4Wze7v7Hkwu1MH1W+mCPQKM+gs+PicdEV14o8=
|
||||
github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ=
|
||||
github.com/consensys/bavard v0.1.8-0.20210915155054-088da2f7f54a/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
|
||||
github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
|
||||
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
|
||||
github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q=
|
||||
github.com/consensys/gnark-crypto v0.5.3/go.mod h1:hOdPlWQV1gDLp7faZVeg8Y0iEPFaOUnCc4XeCCk96p0=
|
||||
github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M=
|
||||
github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
|
||||
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
|
||||
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
|
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
@ -437,6 +442,12 @@ github.com/cosmos/ibc-go/v7 v7.4.0 h1:8FqYMptvksgMvlbN4UW9jFxTXzsPyfAzEZurujXac8
|
||||
github.com/cosmos/ibc-go/v7 v7.4.0/go.mod h1:L/KaEhzV5TGUCTfGysVgMBQtl5Dm7hHitfpk+GIeoAo=
|
||||
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
|
||||
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
|
||||
github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g=
|
||||
github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y=
|
||||
github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY=
|
||||
github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
|
||||
github.com/cosmos/ibc-go/v6 v6.1.1 h1:oqqMNyjj6SLQF8rvgCaDGwfdITEIsbhs8F77/8xvRIo=
|
||||
github.com/cosmos/ibc-go/v6 v6.1.1/go.mod h1:NL17FpFAaWjRFVb1T7LUKuOoMSsATPpu+Icc4zL5/Ik=
|
||||
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
|
||||
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
|
||||
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
|
||||
@ -451,6 +462,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0q
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creachadair/taskgroup v0.4.2 h1:jsBLdAJE42asreGss2xZGZ8fJra7WtwnHWeJFxv2Li8=
|
||||
github.com/creachadair/taskgroup v0.4.2/go.mod h1:qiXUOSrbwAY3u0JPGTzObbE3yf9hcXHDKBZ2ZjpCbgM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM=
|
||||
github.com/creachadair/taskgroup v0.3.2/go.mod h1:wieWwecHVzsidg2CsUnFinW1faVN4+kq+TDlRJQ0Wbk=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||
@ -479,6 +494,7 @@ github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdw
|
||||
github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk=
|
||||
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
|
||||
github.com/dgraph-io/ristretto v0.0.3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
|
||||
github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug=
|
||||
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
|
||||
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
|
||||
github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ=
|
||||
@ -720,11 +736,13 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe
|
||||
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 h1:CqYfpuYIjnlNxM3msdyPRKabhXZWbKjf3Q8BWROFBso=
|
||||
github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
|
||||
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
|
||||
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
@ -864,6 +882,8 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
|
||||
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
|
||||
github.com/jhump/protoreflect v1.12.1-0.20220721211354-060cc04fc18b h1:izTof8BKh/nE1wrKOrloNA5q4odOarjf+Xpe+4qow98=
|
||||
github.com/jhump/protoreflect v1.12.1-0.20220721211354-060cc04fc18b/go.mod h1:JytZfP5d0r8pVNLZvai7U/MCuTWITgrI4tTg7puQFKI=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
@ -911,6 +931,8 @@ github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrD
|
||||
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
|
||||
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5 h1:2U0HzY8BJ8hVwDKIzp7y4voR9CX/nvcfymLmg2UiOio=
|
||||
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
|
||||
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
@ -932,6 +954,7 @@ github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758/go.mod h1:B69LE
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg=
|
||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
||||
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
|
||||
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
|
||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||
@ -1003,6 +1026,9 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A=
|
||||
github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4=
|
||||
github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY=
|
||||
github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU=
|
||||
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
@ -1377,6 +1403,9 @@ golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us=
|
||||
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@ -1656,6 +1685,8 @@ golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxb
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@ -2025,6 +2056,7 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
|
||||
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
|
||||
|
6
precompiles/common/errors.go
Normal file
6
precompiles/common/errors.go
Normal file
@ -0,0 +1,6 @@
|
||||
package common
|
||||
|
||||
const (
|
||||
ErrGetStateDB = "get EVM StateDB failed"
|
||||
ErrInvalidNumberOfArgs = "invalid number of arguments; expected %d; got: %d"
|
||||
)
|
363
precompiles/dasigners/IDASigners.abi
Normal file
363
precompiles/dasigners/IDASigners.abi
Normal file
@ -0,0 +1,363 @@
|
||||
[
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "signer",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "X",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "Y",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"indexed": false,
|
||||
"internalType": "struct BN254.G1Point",
|
||||
"name": "pkG1",
|
||||
"type": "tuple"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "X",
|
||||
"type": "uint256[2]"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "Y",
|
||||
"type": "uint256[2]"
|
||||
}
|
||||
],
|
||||
"indexed": false,
|
||||
"internalType": "struct BN254.G2Point",
|
||||
"name": "pkG2",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"name": "NewSigner",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "signer",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "string",
|
||||
"name": "socket",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "SocketUpdated",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "epochNumber",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "epoch",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "signersBitmap",
|
||||
"type": "bytes"
|
||||
}
|
||||
],
|
||||
"name": "getAggPkG1",
|
||||
"outputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "X",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "Y",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G1Point",
|
||||
"name": "aggPkG1",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "getSigner",
|
||||
"outputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "signer",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "socket",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "X",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "Y",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G1Point",
|
||||
"name": "pkG1",
|
||||
"type": "tuple"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "X",
|
||||
"type": "uint256[2]"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "Y",
|
||||
"type": "uint256[2]"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G2Point",
|
||||
"name": "pkG2",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"internalType": "struct IDASigners.SignerDetail",
|
||||
"name": "",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "epoch",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "getSigners",
|
||||
"outputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "signer",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "socket",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "X",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "Y",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G1Point",
|
||||
"name": "pkG1",
|
||||
"type": "tuple"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "X",
|
||||
"type": "uint256[2]"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "Y",
|
||||
"type": "uint256[2]"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G2Point",
|
||||
"name": "pkG2",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"internalType": "struct IDASigners.SignerDetail[]",
|
||||
"name": "details",
|
||||
"type": "tuple[]"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "X",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "Y",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G1Point",
|
||||
"name": "_signature",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"name": "registerNextEpoch",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "signer",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "socket",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "X",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "Y",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G1Point",
|
||||
"name": "pkG1",
|
||||
"type": "tuple"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "X",
|
||||
"type": "uint256[2]"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "Y",
|
||||
"type": "uint256[2]"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G2Point",
|
||||
"name": "pkG2",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"internalType": "struct IDASigners.SignerDetail",
|
||||
"name": "_signer",
|
||||
"type": "tuple"
|
||||
},
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "X",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "Y",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"internalType": "struct BN254.G1Point",
|
||||
"name": "_signature",
|
||||
"type": "tuple"
|
||||
}
|
||||
],
|
||||
"name": "registerSigner",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "socket",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "updateSocket",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
]
|
387
precompiles/dasigners/IDASigners.sol
Normal file
387
precompiles/dasigners/IDASigners.sol
Normal file
@ -0,0 +1,387 @@
|
||||
// Sources flattened with hardhat v2.22.2 https://hardhat.org
|
||||
|
||||
// SPDX-License-Identifier: LGPL-3.0-only AND MIT
|
||||
|
||||
// File contracts/libraries/BN254.sol
|
||||
|
||||
// Original license: SPDX_License_Identifier: MIT
|
||||
// several functions are taken or adapted from https://github.com/HarryR/solcrypto/blob/master/contracts/altbn128.sol (MIT license):
|
||||
// Copyright 2017 Christian Reitwiessner
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
|
||||
// The remainder of the code in this library is written by LayrLabs Inc. and is also under an MIT license
|
||||
|
||||
pragma solidity ^0.8.12;
|
||||
|
||||
/**
|
||||
* @title Library for operations on the BN254 elliptic curve.
|
||||
* @author Layr Labs, Inc.
|
||||
* @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
|
||||
* @notice Contains BN254 parameters, common operations (addition, scalar mul, pairing), and BLS signature functionality.
|
||||
*/
|
||||
library BN254 {
|
||||
// modulus for the underlying field F_p of the elliptic curve
|
||||
uint internal constant FP_MODULUS = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
// modulus for the underlying field F_r of the elliptic curve
|
||||
uint internal constant FR_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
|
||||
struct G1Point {
|
||||
uint X;
|
||||
uint Y;
|
||||
}
|
||||
|
||||
// Encoding of field elements is: X[1] * i + X[0]
|
||||
struct G2Point {
|
||||
uint[2] X;
|
||||
uint[2] Y;
|
||||
}
|
||||
|
||||
function generatorG1() internal pure returns (G1Point memory) {
|
||||
return G1Point(1, 2);
|
||||
}
|
||||
|
||||
// generator of group G2
|
||||
/// @dev Generator point in F_q2 is of the form: (x0 + ix1, y0 + iy1).
|
||||
uint internal constant G2x1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
||||
uint internal constant G2x0 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
||||
uint internal constant G2y1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
||||
uint internal constant G2y0 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
||||
|
||||
/// @notice returns the G2 generator
|
||||
/// @dev mind the ordering of the 1s and 0s!
|
||||
/// this is because of the (unknown to us) convention used in the bn254 pairing precompile contract
|
||||
/// "Elements a * i + b of F_p^2 are encoded as two elements of F_p, (a, b)."
|
||||
/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-197.md#encoding
|
||||
function generatorG2() internal pure returns (G2Point memory) {
|
||||
return G2Point([G2x1, G2x0], [G2y1, G2y0]);
|
||||
}
|
||||
|
||||
// negation of the generator of group G2
|
||||
/// @dev Generator point in F_q2 is of the form: (x0 + ix1, y0 + iy1).
|
||||
uint internal constant nG2x1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
||||
uint internal constant nG2x0 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
||||
uint internal constant nG2y1 = 17805874995975841540914202342111839520379459829704422454583296818431106115052;
|
||||
uint internal constant nG2y0 = 13392588948715843804641432497768002650278120570034223513918757245338268106653;
|
||||
|
||||
function negGeneratorG2() internal pure returns (G2Point memory) {
|
||||
return G2Point([nG2x1, nG2x0], [nG2y1, nG2y0]);
|
||||
}
|
||||
|
||||
bytes32 internal constant powersOfTauMerkleRoot =
|
||||
0x22c998e49752bbb1918ba87d6d59dd0e83620a311ba91dd4b2cc84990b31b56f;
|
||||
|
||||
/**
|
||||
* @param p Some point in G1.
|
||||
* @return The negation of `p`, i.e. p.plus(p.negate()) should be zero.
|
||||
*/
|
||||
function negate(G1Point memory p) internal pure returns (G1Point memory) {
|
||||
// The prime q in the base field F_q for G1
|
||||
if (p.X == 0 && p.Y == 0) {
|
||||
return G1Point(0, 0);
|
||||
} else {
|
||||
return G1Point(p.X, FP_MODULUS - (p.Y % FP_MODULUS));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return r the sum of two points of G1
|
||||
*/
|
||||
function plus(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory r) {
|
||||
uint[4] memory input;
|
||||
input[0] = p1.X;
|
||||
input[1] = p1.Y;
|
||||
input[2] = p2.X;
|
||||
input[3] = p2.Y;
|
||||
bool success;
|
||||
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 6, input, 0x80, r, 0x40)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success
|
||||
case 0 {
|
||||
invalid()
|
||||
}
|
||||
}
|
||||
|
||||
require(success, "ec-add-failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice an optimized ecMul implementation that takes O(log_2(s)) ecAdds
|
||||
* @param p the point to multiply
|
||||
* @param s the scalar to multiply by
|
||||
* @dev this function is only safe to use if the scalar is 9 bits or less
|
||||
*/
|
||||
function scalar_mul_tiny(BN254.G1Point memory p, uint16 s) internal view returns (BN254.G1Point memory) {
|
||||
require(s < 2 ** 9, "scalar-too-large");
|
||||
|
||||
// if s is 1 return p
|
||||
if (s == 1) {
|
||||
return p;
|
||||
}
|
||||
|
||||
// the accumulated product to return
|
||||
BN254.G1Point memory acc = BN254.G1Point(0, 0);
|
||||
// the 2^n*p to add to the accumulated product in each iteration
|
||||
BN254.G1Point memory p2n = p;
|
||||
// value of most significant bit
|
||||
uint16 m = 1;
|
||||
// index of most significant bit
|
||||
uint8 i = 0;
|
||||
|
||||
//loop until we reach the most significant bit
|
||||
while (s >= m) {
|
||||
unchecked {
|
||||
// if the current bit is 1, add the 2^n*p to the accumulated product
|
||||
if ((s >> i) & 1 == 1) {
|
||||
acc = plus(acc, p2n);
|
||||
}
|
||||
// double the 2^n*p for the next iteration
|
||||
p2n = plus(p2n, p2n);
|
||||
|
||||
// increment the index and double the value of the most significant bit
|
||||
m <<= 1;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
// return the accumulated product
|
||||
return acc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return r the product of a point on G1 and a scalar, i.e.
|
||||
* p == p.scalar_mul(1) and p.plus(p) == p.scalar_mul(2) for all
|
||||
* points p.
|
||||
*/
|
||||
function scalar_mul(G1Point memory p, uint s) internal view returns (G1Point memory r) {
|
||||
uint[3] memory input;
|
||||
input[0] = p.X;
|
||||
input[1] = p.Y;
|
||||
input[2] = s;
|
||||
bool success;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 7, input, 0x60, r, 0x40)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success
|
||||
case 0 {
|
||||
invalid()
|
||||
}
|
||||
}
|
||||
require(success, "ec-mul-failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The result of computing the pairing check
|
||||
* e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1
|
||||
* For example,
|
||||
* pairing([P1(), P1().negate()], [P2(), P2()]) should return true.
|
||||
*/
|
||||
function pairing(
|
||||
G1Point memory a1,
|
||||
G2Point memory a2,
|
||||
G1Point memory b1,
|
||||
G2Point memory b2
|
||||
) internal view returns (bool) {
|
||||
G1Point[2] memory p1 = [a1, b1];
|
||||
G2Point[2] memory p2 = [a2, b2];
|
||||
|
||||
uint[12] memory input;
|
||||
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
uint j = i * 6;
|
||||
input[j + 0] = p1[i].X;
|
||||
input[j + 1] = p1[i].Y;
|
||||
input[j + 2] = p2[i].X[0];
|
||||
input[j + 3] = p2[i].X[1];
|
||||
input[j + 4] = p2[i].Y[0];
|
||||
input[j + 5] = p2[i].Y[1];
|
||||
}
|
||||
|
||||
uint[1] memory out;
|
||||
bool success;
|
||||
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 8, input, mul(12, 0x20), out, 0x20)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success
|
||||
case 0 {
|
||||
invalid()
|
||||
}
|
||||
}
|
||||
|
||||
require(success, "pairing-opcode-failed");
|
||||
|
||||
return out[0] != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice This function is functionally the same as pairing(), however it specifies a gas limit
|
||||
* the user can set, as a precompile may use the entire gas budget if it reverts.
|
||||
*/
|
||||
function safePairing(
|
||||
G1Point memory a1,
|
||||
G2Point memory a2,
|
||||
G1Point memory b1,
|
||||
G2Point memory b2,
|
||||
uint pairingGas
|
||||
) internal view returns (bool, bool) {
|
||||
G1Point[2] memory p1 = [a1, b1];
|
||||
G2Point[2] memory p2 = [a2, b2];
|
||||
|
||||
uint[12] memory input;
|
||||
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
uint j = i * 6;
|
||||
input[j + 0] = p1[i].X;
|
||||
input[j + 1] = p1[i].Y;
|
||||
input[j + 2] = p2[i].X[0];
|
||||
input[j + 3] = p2[i].X[1];
|
||||
input[j + 4] = p2[i].Y[0];
|
||||
input[j + 5] = p2[i].Y[1];
|
||||
}
|
||||
|
||||
uint[1] memory out;
|
||||
bool success;
|
||||
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(pairingGas, 8, input, mul(12, 0x20), out, 0x20)
|
||||
}
|
||||
|
||||
//Out is the output of the pairing precompile, either 0 or 1 based on whether the two pairings are equal.
|
||||
//Success is true if the precompile actually goes through (aka all inputs are valid)
|
||||
|
||||
return (success, out[0] != 0);
|
||||
}
|
||||
|
||||
/// @return hashedG1 the keccak256 hash of the G1 Point
|
||||
/// @dev used for BLS signatures
|
||||
function hashG1Point(BN254.G1Point memory pk) internal pure returns (bytes32 hashedG1) {
|
||||
assembly {
|
||||
mstore(0, mload(pk))
|
||||
mstore(0x20, mload(add(0x20, pk)))
|
||||
hashedG1 := keccak256(0, 0x40)
|
||||
}
|
||||
}
|
||||
|
||||
/// @return the keccak256 hash of the G2 Point
|
||||
/// @dev used for BLS signatures
|
||||
function hashG2Point(BN254.G2Point memory pk) internal pure returns (bytes32) {
|
||||
return keccak256(abi.encodePacked(pk.X[0], pk.X[1], pk.Y[0], pk.Y[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice adapted from https://github.com/HarryR/solcrypto/blob/master/contracts/altbn128.sol
|
||||
*/
|
||||
function hashToG1(bytes32 _x) internal view returns (G1Point memory) {
|
||||
uint beta = 0;
|
||||
uint y = 0;
|
||||
|
||||
uint x = uint(_x) % FP_MODULUS;
|
||||
|
||||
while (true) {
|
||||
(beta, y) = findYFromX(x);
|
||||
|
||||
// y^2 == beta
|
||||
if (beta == mulmod(y, y, FP_MODULUS)) {
|
||||
return G1Point(x, y);
|
||||
}
|
||||
|
||||
x = addmod(x, 1, FP_MODULUS);
|
||||
}
|
||||
return G1Point(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given X, find Y
|
||||
*
|
||||
* where y = sqrt(x^3 + b)
|
||||
*
|
||||
* Returns: (x^3 + b), y
|
||||
*/
|
||||
function findYFromX(uint x) internal view returns (uint, uint) {
|
||||
// beta = (x^3 + b) % p
|
||||
uint beta = addmod(mulmod(mulmod(x, x, FP_MODULUS), x, FP_MODULUS), 3, FP_MODULUS);
|
||||
|
||||
// y^2 = x^3 + b
|
||||
// this acts like: y = sqrt(beta) = beta^((p+1) / 4)
|
||||
uint y = expMod(beta, 0xc19139cb84c680a6e14116da060561765e05aa45a1c72a34f082305b61f3f52, FP_MODULUS);
|
||||
|
||||
return (beta, y);
|
||||
}
|
||||
|
||||
function expMod(uint _base, uint _exponent, uint _modulus) internal view returns (uint retval) {
|
||||
bool success;
|
||||
uint[1] memory output;
|
||||
uint[6] memory input;
|
||||
input[0] = 0x20; // baseLen = new(big.Int).SetBytes(getData(input, 0, 32))
|
||||
input[1] = 0x20; // expLen = new(big.Int).SetBytes(getData(input, 32, 32))
|
||||
input[2] = 0x20; // modLen = new(big.Int).SetBytes(getData(input, 64, 32))
|
||||
input[3] = _base;
|
||||
input[4] = _exponent;
|
||||
input[5] = _modulus;
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 5, input, 0xc0, output, 0x20)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success
|
||||
case 0 {
|
||||
invalid()
|
||||
}
|
||||
}
|
||||
require(success, "BN254.expMod: call failure");
|
||||
return output[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// File contracts/interface/IDASigners.sol
|
||||
|
||||
// Original license: SPDX_License_Identifier: LGPL-3.0-only
|
||||
|
||||
pragma solidity >=0.8.0 <0.9.0;
|
||||
|
||||
interface IDASigners {
|
||||
/*=== struct ===*/
|
||||
struct SignerDetail {
|
||||
string socket;
|
||||
BN254.G1Point pkG1;
|
||||
BN254.G2Point pkG2;
|
||||
}
|
||||
|
||||
/*=== event ===*/
|
||||
event NewSigner(address indexed signer, BN254.G1Point pkG1, BN254.G2Point pkG2);
|
||||
event SocketUpdated(address indexed signer, string socket);
|
||||
|
||||
/*=== function ===*/
|
||||
function epochNumber() external view returns (uint);
|
||||
|
||||
function getSigners(uint epoch) external view returns (address[] memory accounts, SignerDetail[] memory details);
|
||||
|
||||
function registerSigner(SignerDetail memory _signer, BN254.G1Point memory _signature) external;
|
||||
|
||||
function checkSignatures(
|
||||
BN254.G1Point memory _hash,
|
||||
uint epoch,
|
||||
bytes memory signerBitmap,
|
||||
BN254.G2Point memory _aggPkG2,
|
||||
BN254.G1Point memory _signature
|
||||
) external view returns (bool);
|
||||
}
|
678
precompiles/dasigners/contract.go
Normal file
678
precompiles/dasigners/contract.go
Normal file
File diff suppressed because one or more lines are too long
108
precompiles/dasigners/dasigners.go
Normal file
108
precompiles/dasigners/dasigners.go
Normal file
@ -0,0 +1,108 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common"
|
||||
dasignerskeeper "github.com/0glabs/0g-chain/x/dasigners/v1/keeper"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/evmos/ethermint/x/evm/statedb"
|
||||
)
|
||||
|
||||
const (
|
||||
PrecompileAddress = "0x0000000000000000000000000000000000001000"
|
||||
RequiredGasBasic uint64 = 100
|
||||
|
||||
DASignersFunctionEpochNumber = "epochNumber"
|
||||
DASignersFunctionGetSigner = "getSigner"
|
||||
DASignersFunctionGetSigners = "getSigners"
|
||||
DASignersFunctionUpdateSocket = "updateSocket"
|
||||
DASignersFunctionRegisterNextEpoch = "registerNextEpoch"
|
||||
DASignersFunctionRegisterSigner = "registerSigner"
|
||||
DASignersFunctionGetAggPkG1 = "getAggPkG1"
|
||||
)
|
||||
|
||||
var _ vm.PrecompiledContract = &DASignersPrecompile{}
|
||||
|
||||
type DASignersPrecompile struct {
|
||||
abi abi.ABI
|
||||
dasignersKeeper dasignerskeeper.Keeper
|
||||
}
|
||||
|
||||
func NewDASignersPrecompile(dasignersKeeper dasignerskeeper.Keeper) (*DASignersPrecompile, error) {
|
||||
abi, err := abi.JSON(strings.NewReader(DASignersABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &DASignersPrecompile{
|
||||
abi: abi,
|
||||
dasignersKeeper: dasignersKeeper,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Address implements vm.PrecompiledContract.
|
||||
func (d *DASignersPrecompile) Address() common.Address {
|
||||
return common.HexToAddress(PrecompileAddress)
|
||||
}
|
||||
|
||||
// RequiredGas implements vm.PrecompiledContract.
|
||||
func (d *DASignersPrecompile) RequiredGas(input []byte) uint64 {
|
||||
return RequiredGasBasic
|
||||
}
|
||||
|
||||
// Run implements vm.PrecompiledContract.
|
||||
func (d *DASignersPrecompile) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) {
|
||||
// parse input
|
||||
if len(contract.Input) < 4 {
|
||||
return nil, vm.ErrExecutionReverted
|
||||
}
|
||||
method, err := d.abi.MethodById(contract.Input[:4])
|
||||
if err != nil {
|
||||
return nil, vm.ErrExecutionReverted
|
||||
}
|
||||
args, err := method.Inputs.Unpack(contract.Input[4:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// get state db and context
|
||||
stateDB, ok := evm.StateDB.(*statedb.StateDB)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrGetStateDB)
|
||||
}
|
||||
ctx := stateDB.GetContext()
|
||||
initialGas := ctx.GasMeter().GasConsumed()
|
||||
|
||||
var bz []byte
|
||||
switch method.Name {
|
||||
// queries
|
||||
case DASignersFunctionEpochNumber:
|
||||
bz, err = d.EpochNumber(ctx, evm, method, args)
|
||||
case DASignersFunctionGetSigner:
|
||||
bz, err = d.GetSigner(ctx, evm, method, args)
|
||||
case DASignersFunctionGetSigners:
|
||||
bz, err = d.GetSigners(ctx, evm, method, args)
|
||||
case DASignersFunctionGetAggPkG1:
|
||||
bz, err = d.GetAggPkG1(ctx, evm, method, args)
|
||||
// txs
|
||||
case DASignersFunctionRegisterSigner:
|
||||
bz, err = d.RegisterSigner(ctx, evm, stateDB, method, args)
|
||||
case DASignersFunctionRegisterNextEpoch:
|
||||
bz, err = d.RegisterNextEpoch(ctx, evm, stateDB, method, args)
|
||||
case DASignersFunctionUpdateSocket:
|
||||
bz, err = d.UpdateSocket(ctx, evm, stateDB, method, args)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cost := ctx.GasMeter().GasConsumed() - initialGas
|
||||
|
||||
if !contract.UseGas(cost) {
|
||||
return nil, vm.ErrOutOfGas
|
||||
}
|
||||
return bz, nil
|
||||
}
|
5
precompiles/dasigners/errors.go
Normal file
5
precompiles/dasigners/errors.go
Normal file
@ -0,0 +1,5 @@
|
||||
package dasigners
|
||||
|
||||
const (
|
||||
ErrInvalidSender = "sender address %s is not the same as signer address %s"
|
||||
)
|
58
precompiles/dasigners/events.go
Normal file
58
precompiles/dasigners/events.go
Normal file
@ -0,0 +1,58 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/evmos/ethermint/x/evm/statedb"
|
||||
)
|
||||
|
||||
const (
|
||||
NewSignerEvent = "NewSigner"
|
||||
SocketUpdatedEvent = "SocketUpdated"
|
||||
)
|
||||
|
||||
func (d *DASignersPrecompile) EmitNewSignerEvent(ctx sdk.Context, stateDB *statedb.StateDB, signer IDASignersSignerDetail) error {
|
||||
event := d.abi.Events[NewSignerEvent]
|
||||
quries := make([]interface{}, 2)
|
||||
quries[0] = event.ID
|
||||
quries[1] = signer.Signer
|
||||
topics, err := abi.MakeTopics(quries)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := event.Inputs.Pack(signer.Signer, signer.PkG1, signer.PkG2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stateDB.AddLog(&types.Log{
|
||||
Address: d.Address(),
|
||||
Topics: topics[0],
|
||||
Data: b,
|
||||
BlockNumber: uint64(ctx.BlockHeight()),
|
||||
})
|
||||
return d.EmitSocketUpdatedEvent(ctx, stateDB, signer.Signer, signer.Socket)
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) EmitSocketUpdatedEvent(ctx sdk.Context, stateDB *statedb.StateDB, signer common.Address, socket string) error {
|
||||
event := d.abi.Events[SocketUpdatedEvent]
|
||||
quries := make([]interface{}, 2)
|
||||
quries[0] = event.ID
|
||||
quries[1] = signer
|
||||
topics, err := abi.MakeTopics(quries)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := event.Inputs.Pack(signer, socket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stateDB.AddLog(&types.Log{
|
||||
Address: d.Address(),
|
||||
Topics: topics[0],
|
||||
Data: b,
|
||||
BlockNumber: uint64(ctx.BlockHeight()),
|
||||
})
|
||||
return nil
|
||||
}
|
57
precompiles/dasigners/query.go
Normal file
57
precompiles/dasigners/query.go
Normal file
@ -0,0 +1,57 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
)
|
||||
|
||||
func (d *DASignersPrecompile) EpochNumber(ctx sdk.Context, _ *vm.EVM, method *abi.Method, _ []interface{}) ([]byte, error) {
|
||||
epochNumber, err := d.dasignersKeeper.GetEpochNumber(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack(big.NewInt(int64(epochNumber)))
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) GetSigner(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
req, err := NewQuerySignerRequest(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := d.dasignersKeeper.Signer(sdk.WrapSDKContext(ctx), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack(NewIDASignersSignerDetail(response.Signer))
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) GetSigners(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
req, err := NewQueryEpochSignerSetRequest(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := d.dasignersKeeper.EpochSignerSet(sdk.WrapSDKContext(ctx), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
signers := make([]IDASignersSignerDetail, 0)
|
||||
for _, signer := range response.Signers {
|
||||
signers = append(signers, NewIDASignersSignerDetail(signer))
|
||||
}
|
||||
return method.Outputs.Pack(signers)
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) GetAggPkG1(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
req, err := NewQueryAggregatePubkeyG1Request(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := d.dasignersKeeper.AggregatePubkeyG1(sdk.WrapSDKContext(ctx), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack(NewBN254G1Point(response.AggregatePubkeyG1))
|
||||
}
|
64
precompiles/dasigners/tx.go
Normal file
64
precompiles/dasigners/tx.go
Normal file
@ -0,0 +1,64 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/evmos/ethermint/x/evm/statedb"
|
||||
)
|
||||
|
||||
func (d *DASignersPrecompile) RegisterSigner(ctx sdk.Context, evm *vm.EVM, stateDB *statedb.StateDB, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
msg, err := NewMsgRegisterSigner(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// validation
|
||||
sender := ToLowerHexWithoutPrefix(evm.Origin)
|
||||
if sender != msg.Signer.Account {
|
||||
return nil, fmt.Errorf(ErrInvalidSender, sender, msg.Signer.Account)
|
||||
}
|
||||
// execute
|
||||
_, err = d.dasignersKeeper.RegisterSigner(sdk.WrapSDKContext(ctx), msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// emit events
|
||||
err = d.EmitNewSignerEvent(ctx, stateDB, args[0].(IDASignersSignerDetail))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack()
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) RegisterNextEpoch(ctx sdk.Context, evm *vm.EVM, stateDB *statedb.StateDB, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
msg, err := NewMsgRegisterNextEpoch(args, ToLowerHexWithoutPrefix(evm.Origin))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// execute
|
||||
_, err = d.dasignersKeeper.RegisterNextEpoch(sdk.WrapSDKContext(ctx), msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack()
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) UpdateSocket(ctx sdk.Context, evm *vm.EVM, stateDB *statedb.StateDB, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
msg, err := NewMsgUpdateSocket(args, ToLowerHexWithoutPrefix(evm.Origin))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// execute
|
||||
_, err = d.dasignersKeeper.UpdateSocket(sdk.WrapSDKContext(ctx), msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// emit events
|
||||
err = d.EmitSocketUpdatedEvent(ctx, stateDB, evm.Origin, args[0].(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack()
|
||||
}
|
130
precompiles/dasigners/types.go
Normal file
130
precompiles/dasigners/types.go
Normal file
@ -0,0 +1,130 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common"
|
||||
dasignerstypes "github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
func NewBN254G1Point(b []byte) BN254G1Point {
|
||||
return BN254G1Point{
|
||||
X: new(big.Int).SetBytes(b[:32]),
|
||||
Y: new(big.Int).SetBytes(b[32:64]),
|
||||
}
|
||||
}
|
||||
|
||||
func (p BN254G1Point) Serialize() []byte {
|
||||
b := make([]byte, 0)
|
||||
b = append(b, common.LeftPadBytes(p.X.Bytes(), 32)...)
|
||||
b = append(b, common.LeftPadBytes(p.Y.Bytes(), 32)...)
|
||||
return b
|
||||
}
|
||||
|
||||
func NewBN254G2Point(b []byte) BN254G2Point {
|
||||
return BN254G2Point{
|
||||
X: [2]*big.Int{
|
||||
new(big.Int).SetBytes(b[:32]),
|
||||
new(big.Int).SetBytes(b[32:64]),
|
||||
},
|
||||
Y: [2]*big.Int{
|
||||
new(big.Int).SetBytes(b[64:96]),
|
||||
new(big.Int).SetBytes(b[96:128]),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (p BN254G2Point) Serialize() []byte {
|
||||
b := make([]byte, 0)
|
||||
b = append(b, common.LeftPadBytes(p.X[0].Bytes(), 32)...)
|
||||
b = append(b, common.LeftPadBytes(p.X[1].Bytes(), 32)...)
|
||||
b = append(b, common.LeftPadBytes(p.Y[0].Bytes(), 32)...)
|
||||
b = append(b, common.LeftPadBytes(p.Y[1].Bytes(), 32)...)
|
||||
return b
|
||||
}
|
||||
|
||||
func NewQuerySignerRequest(args []interface{}) (*dasignerstypes.QuerySignerRequest, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args))
|
||||
}
|
||||
|
||||
return &dasignerstypes.QuerySignerRequest{
|
||||
Account: args[0].(string),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewQueryEpochSignerSetRequest(args []interface{}) (*dasignerstypes.QueryEpochSignerSetRequest, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args))
|
||||
}
|
||||
|
||||
return &dasignerstypes.QueryEpochSignerSetRequest{
|
||||
EpochNumber: args[0].(*big.Int).Uint64(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewQueryAggregatePubkeyG1Request(args []interface{}) (*dasignerstypes.QueryAggregatePubkeyG1Request, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args))
|
||||
}
|
||||
|
||||
return &dasignerstypes.QueryAggregatePubkeyG1Request{
|
||||
EpochNumber: args[0].(*big.Int).Uint64(),
|
||||
SignersBitmap: args[1].([]byte),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewIDASignersSignerDetail(signer *dasignerstypes.Signer) IDASignersSignerDetail {
|
||||
return IDASignersSignerDetail{
|
||||
Signer: common.HexToAddress(signer.Account),
|
||||
Socket: signer.Socket,
|
||||
PkG1: NewBN254G1Point(signer.PubkeyG1),
|
||||
PkG2: NewBN254G2Point(signer.PubkeyG2),
|
||||
}
|
||||
}
|
||||
|
||||
func ToLowerHexWithoutPrefix(addr common.Address) string {
|
||||
return strings.ToLower(addr.Hex()[2:])
|
||||
}
|
||||
|
||||
func NewMsgRegisterSigner(args []interface{}) (*dasignerstypes.MsgRegisterSigner, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args))
|
||||
}
|
||||
|
||||
signer := args[0].(IDASignersSignerDetail)
|
||||
return &dasignerstypes.MsgRegisterSigner{
|
||||
Signer: &dasignerstypes.Signer{
|
||||
Account: ToLowerHexWithoutPrefix(signer.Signer),
|
||||
Socket: signer.Socket,
|
||||
PubkeyG1: signer.PkG1.Serialize(),
|
||||
PubkeyG2: signer.PkG2.Serialize(),
|
||||
},
|
||||
Signature: args[1].(BN254G1Point).Serialize(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewMsgRegisterNextEpoch(args []interface{}, account string) (*dasignerstypes.MsgRegisterNextEpoch, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args))
|
||||
}
|
||||
|
||||
return &dasignerstypes.MsgRegisterNextEpoch{
|
||||
Account: account,
|
||||
Signature: args[0].(BN254G1Point).Serialize(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewMsgUpdateSocket(args []interface{}, account string) (*dasignerstypes.MsgUpdateSocket, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args))
|
||||
}
|
||||
|
||||
return &dasignerstypes.MsgUpdateSocket{
|
||||
Account: account,
|
||||
Socket: args[0].(string),
|
||||
}, nil
|
||||
}
|
@ -28,7 +28,7 @@ message Council {
|
||||
uint64 voting_start_height = 2;
|
||||
uint64 start_height = 3;
|
||||
uint64 end_height = 4;
|
||||
repeated Vote votes = 5 [(gogoproto.nullable) = false];
|
||||
repeated Vote votes = 5 [(gogoproto.nullable) = false];
|
||||
repeated bytes members = 6 [
|
||||
(cosmos_proto.scalar) = "cosmos.AddressBytes",
|
||||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress"
|
||||
|
@ -11,21 +11,21 @@ option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
// Msg defines the council Msg service
|
||||
service Msg {
|
||||
rpc Register(MsgRegister) returns (MsgRegisterResponse);
|
||||
rpc Vote(MsgVote) returns (MsgVoteResponse);
|
||||
rpc Register(MsgRegister) returns (MsgRegisterResponse);
|
||||
rpc Vote(MsgVote) returns (MsgVoteResponse);
|
||||
}
|
||||
|
||||
message MsgRegister {
|
||||
string voter = 1;
|
||||
bytes key = 2;
|
||||
string voter = 1;
|
||||
bytes key = 2;
|
||||
}
|
||||
|
||||
message MsgRegisterResponse {}
|
||||
|
||||
message MsgVote {
|
||||
uint64 council_id = 1 [(gogoproto.customname) = "CouncilID"];
|
||||
string voter = 2;
|
||||
repeated Ballot ballots = 3;
|
||||
uint64 council_id = 1 [(gogoproto.customname) = "CouncilID"];
|
||||
string voter = 2;
|
||||
repeated Ballot ballots = 3;
|
||||
}
|
||||
|
||||
message MsgVoteResponse {}
|
||||
|
25
proto/zgc/dasigners/v1/dasigners.proto
Normal file
25
proto/zgc/dasigners/v1/dasigners.proto
Normal file
@ -0,0 +1,25 @@
|
||||
syntax = "proto3";
|
||||
package zgc.dasigners.v1;
|
||||
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "google/protobuf/duration.proto";
|
||||
|
||||
option go_package = "github.com/0glabs/0g-chain/x/dasigners/v1/types";
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
message Signer {
|
||||
// account defines the hex address of signer without 0x
|
||||
string account = 1;
|
||||
// socket defines the da node socket address
|
||||
string socket = 2;
|
||||
// pubkey_g1 defines the public key on bn254 G1
|
||||
bytes pubkey_g1 = 3;
|
||||
// pubkey_g1 defines the public key on bn254 G2
|
||||
bytes pubkey_g2 = 4;
|
||||
}
|
||||
|
||||
message EpochSignerSet {
|
||||
repeated string signers = 1;
|
||||
}
|
29
proto/zgc/dasigners/v1/genesis.proto
Normal file
29
proto/zgc/dasigners/v1/genesis.proto
Normal file
@ -0,0 +1,29 @@
|
||||
syntax = "proto3";
|
||||
package zgc.dasigners.v1;
|
||||
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "zgc/dasigners/v1/dasigners.proto";
|
||||
|
||||
option go_package = "github.com/0glabs/0g-chain/x/dasigners/v1/types";
|
||||
|
||||
message Params {
|
||||
uint64 quorum_size = 1;
|
||||
string tokens_per_vote = 2;
|
||||
uint64 max_votes = 3;
|
||||
uint64 epoch_blocks = 4;
|
||||
}
|
||||
|
||||
// GenesisState defines the dasigners module's genesis state.
|
||||
message GenesisState {
|
||||
// params defines all the parameters of related to deposit.
|
||||
Params params = 1 [(gogoproto.nullable) = false];
|
||||
// params epoch_number the epoch number
|
||||
uint64 epoch_number = 2;
|
||||
// signers defines all signers information
|
||||
repeated Signer signers = 3;
|
||||
// signers_by_epoch defines chosen signers by epoch
|
||||
repeated EpochSignerSet signers_by_epoch = 4;
|
||||
}
|
59
proto/zgc/dasigners/v1/query.proto
Normal file
59
proto/zgc/dasigners/v1/query.proto
Normal file
@ -0,0 +1,59 @@
|
||||
syntax = "proto3";
|
||||
package zgc.dasigners.v1;
|
||||
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "zgc/dasigners/v1/dasigners.proto";
|
||||
|
||||
option go_package = "github.com/0glabs/0g-chain/x/dasigners/v1/types";
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
// Query defines the gRPC querier service for the dasigners module
|
||||
service Query {
|
||||
rpc EpochNumber(QueryEpochNumberRequest) returns (QueryEpochNumberResponse) {
|
||||
option (google.api.http).get = "/0gchain/dasigners/v1/epoch-number";
|
||||
}
|
||||
rpc EpochSignerSet(QueryEpochSignerSetRequest) returns (QueryEpochSignerSetResponse) {
|
||||
option (google.api.http).get = "/0gchain/dasigners/v1/epoch-signer-set";
|
||||
}
|
||||
rpc AggregatePubkeyG1(QueryAggregatePubkeyG1Request) returns (QueryAggregatePubkeyG1Response) {
|
||||
option (google.api.http).get = "/0gchain/dasigners/v1/aggregate-pubkey-g1";
|
||||
}
|
||||
rpc Signer(QuerySignerRequest) returns (QuerySignerResponse) {
|
||||
option (google.api.http).get = "/0gchain/dasigners/v1/signer";
|
||||
}
|
||||
}
|
||||
|
||||
message QuerySignerRequest {
|
||||
string account = 1;
|
||||
}
|
||||
|
||||
message QuerySignerResponse {
|
||||
Signer signer = 1;
|
||||
}
|
||||
|
||||
message QueryEpochNumberRequest {}
|
||||
|
||||
message QueryEpochNumberResponse {
|
||||
uint64 epoch_number = 1;
|
||||
}
|
||||
|
||||
message QueryEpochSignerSetRequest {
|
||||
uint64 epoch_number = 1;
|
||||
}
|
||||
|
||||
message QueryEpochSignerSetResponse {
|
||||
repeated Signer signers = 1;
|
||||
}
|
||||
|
||||
message QueryAggregatePubkeyG1Request {
|
||||
uint64 epoch_number = 1;
|
||||
bytes signersBitmap = 2;
|
||||
}
|
||||
|
||||
message QueryAggregatePubkeyG1Response {
|
||||
bytes aggregate_pubkey_g1 = 1;
|
||||
}
|
39
proto/zgc/dasigners/v1/tx.proto
Normal file
39
proto/zgc/dasigners/v1/tx.proto
Normal file
@ -0,0 +1,39 @@
|
||||
syntax = "proto3";
|
||||
package zgc.dasigners.v1;
|
||||
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "zgc/das/v1/genesis.proto";
|
||||
import "zgc/dasigners/v1/dasigners.proto";
|
||||
|
||||
option go_package = "github.com/0glabs/0g-chain/x/dasigners/v1/types";
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
// Msg defines the dasigners Msg service
|
||||
service Msg {
|
||||
rpc RegisterSigner(MsgRegisterSigner) returns (MsgRegisterSignerResponse);
|
||||
rpc UpdateSocket(MsgUpdateSocket) returns (MsgUpdateSocketResponse);
|
||||
rpc RegisterNextEpoch(MsgRegisterNextEpoch) returns (MsgRegisterNextEpochResponse);
|
||||
}
|
||||
|
||||
message MsgRegisterSigner {
|
||||
Signer signer = 1;
|
||||
bytes signature = 2;
|
||||
}
|
||||
|
||||
message MsgRegisterSignerResponse {}
|
||||
|
||||
message MsgUpdateSocket {
|
||||
string account = 1;
|
||||
string socket = 2;
|
||||
}
|
||||
|
||||
message MsgUpdateSocketResponse {}
|
||||
|
||||
message MsgRegisterNextEpoch {
|
||||
string account = 1;
|
||||
bytes signature = 2;
|
||||
}
|
||||
|
||||
message MsgRegisterNextEpochResponse {}
|
@ -13,7 +13,7 @@ type KvtoolRunnerConfig struct {
|
||||
ImageTag string
|
||||
IncludeIBC bool
|
||||
|
||||
EnableAutomatedUpgrade bool
|
||||
EnableAutomatedUpgrade bool
|
||||
ZgChainUpgradeName string
|
||||
ZgChainUpgradeHeight int64
|
||||
ZgChainUpgradeBaseImageTag string
|
||||
|
@ -140,8 +140,8 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
evmResChan: evmResChan,
|
||||
|
||||
zgChainSigner: zgChainSigner,
|
||||
sdkReqChan: sdkReqChan,
|
||||
sdkResChan: sdkResChan,
|
||||
sdkReqChan: sdkReqChan,
|
||||
sdkResChan: sdkResChan,
|
||||
|
||||
EvmAuth: evmSigner.Auth,
|
||||
|
||||
|
57
x/dasigners/v1/client/cli/query.go
Normal file
57
x/dasigners/v1/client/cli/query.go
Normal file
@ -0,0 +1,57 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
)
|
||||
|
||||
// GetQueryCmd returns the cli query commands for the inflation module.
|
||||
func GetQueryCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Querying commands for the dasigners module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
GetEpochNumber(),
|
||||
)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func GetEpochNumber() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "epoch-number",
|
||||
Short: "Query current epoch number",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
params := &types.QueryEpochNumberRequest{}
|
||||
res, err := queryClient.EpochNumber(context.Background(), params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintString(fmt.Sprintf("%v\n", res.EpochNumber))
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
22
x/dasigners/v1/client/cli/tx.go
Normal file
22
x/dasigners/v1/client/cli/tx.go
Normal file
@ -0,0 +1,22 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/das/v1/types"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func GetTxCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
cmd.AddCommand()
|
||||
return cmd
|
||||
}
|
50
x/dasigners/v1/genesis.go
Normal file
50
x/dasigners/v1/genesis.go
Normal file
@ -0,0 +1,50 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/keeper"
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
)
|
||||
|
||||
// InitGenesis initializes the store state from a genesis state.
|
||||
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, gs types.GenesisState) {
|
||||
if err := gs.Validate(); err != nil {
|
||||
panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err))
|
||||
}
|
||||
keeper.SetEpochNumber(ctx, gs.EpochNumber)
|
||||
for _, signer := range gs.Signers {
|
||||
if err := keeper.SetSigner(ctx, *signer); err != nil {
|
||||
panic(fmt.Sprintf("failed to write genesis state into store: %s", err))
|
||||
}
|
||||
}
|
||||
for epoch, signers := range gs.SignersByEpoch {
|
||||
keeper.SetEpochSignerSet(ctx, uint64(epoch), *signers)
|
||||
}
|
||||
keeper.SetParams(ctx, gs.Params)
|
||||
}
|
||||
|
||||
// ExportGenesis returns a GenesisState for a given context and keeper.
|
||||
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
|
||||
params := keeper.GetParams(ctx)
|
||||
epochNumber, err := keeper.GetEpochNumber(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
signers := make([]*types.Signer, 0)
|
||||
keeper.IterateSigners(ctx, func(_ int64, signer types.Signer) (stop bool) {
|
||||
signers = append(signers, &signer)
|
||||
return false
|
||||
})
|
||||
epochSignerSets := make([]*types.EpochSignerSet, 0)
|
||||
for i := 0; i < int(epochNumber); i += 1 {
|
||||
epochSignerSet, found := keeper.GetEpochSignerSet(ctx, uint64(i))
|
||||
if !found {
|
||||
panic("historical epoch signer set not found")
|
||||
}
|
||||
epochSignerSets = append(epochSignerSets, &epochSignerSet)
|
||||
}
|
||||
return types.NewGenesisState(params, epochNumber, signers, epochSignerSets)
|
||||
}
|
88
x/dasigners/v1/keeper/abci.go
Normal file
88
x/dasigners/v1/keeper/abci.go
Normal file
@ -0,0 +1,88 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/big"
|
||||
"sort"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
type Ballot struct {
|
||||
account string
|
||||
content []byte
|
||||
}
|
||||
|
||||
func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
||||
epochNumber, err := k.GetEpochNumber(ctx)
|
||||
if err != nil {
|
||||
k.Logger(ctx).Error("[BeginBlock] cannot get epoch number")
|
||||
panic(err)
|
||||
}
|
||||
params := k.GetParams(ctx)
|
||||
expectedEpoch := uint64(ctx.BlockHeight()) / params.EpochBlocks
|
||||
if expectedEpoch == epochNumber {
|
||||
return
|
||||
}
|
||||
if expectedEpoch > epochNumber+1 || expectedEpoch < epochNumber {
|
||||
panic("block height is not continuous")
|
||||
}
|
||||
// new epoch
|
||||
registrations := []Ballot{}
|
||||
k.IterateRegistrations(ctx, expectedEpoch, func(account string, signature []byte) (stop bool) {
|
||||
registrations = append(registrations, Ballot{
|
||||
account: account,
|
||||
content: signature,
|
||||
})
|
||||
return false
|
||||
})
|
||||
ballots := []Ballot{}
|
||||
tokensPerVote, ok := sdk.NewIntFromString(params.TokensPerVote)
|
||||
if !ok {
|
||||
panic("failed to load params tokens_per_vote")
|
||||
}
|
||||
for _, registration := range registrations {
|
||||
// get validator
|
||||
valAddr, err := sdk.ValAddressFromHex(registration.account)
|
||||
if err != nil {
|
||||
k.Logger(ctx).Error("[BeginBlock] invalid account")
|
||||
continue
|
||||
}
|
||||
validator, found := k.stakingKeeper.GetValidator(ctx, valAddr)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
num := validator.Tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000)).Quo(tokensPerVote).Abs().BigInt()
|
||||
if num.Cmp(big.NewInt(int64(params.MaxVotes))) > 0 {
|
||||
num = big.NewInt(int64(params.MaxVotes))
|
||||
}
|
||||
content := registration.content
|
||||
ballotNum := num.Int64()
|
||||
for j := 0; j < int(ballotNum); j += 1 {
|
||||
ballots = append(ballots, Ballot{
|
||||
account: registration.account,
|
||||
content: content,
|
||||
})
|
||||
content = crypto.Keccak256(content)
|
||||
}
|
||||
}
|
||||
sort.Slice(ballots, func(i, j int) bool {
|
||||
return bytes.Compare(ballots[i].content, ballots[j].content) < 0
|
||||
})
|
||||
chosen := make(map[string]struct{})
|
||||
epochSignerSet := types.EpochSignerSet{
|
||||
Signers: make([]string, 0),
|
||||
}
|
||||
for _, ballot := range ballots {
|
||||
if _, ok := chosen[ballot.account]; !ok {
|
||||
chosen[ballot.account] = struct{}{}
|
||||
epochSignerSet.Signers = append(epochSignerSet.Signers, ballot.account)
|
||||
}
|
||||
}
|
||||
// save to store
|
||||
k.SetEpochSignerSet(ctx, expectedEpoch, epochSignerSet)
|
||||
k.SetEpochNumber(ctx, expectedEpoch)
|
||||
}
|
88
x/dasigners/v1/keeper/grpc_query.go
Normal file
88
x/dasigners/v1/keeper/grpc_query.go
Normal file
@ -0,0 +1,88 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/0glabs/0g-chain/crypto/bn254util"
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
"github.com/consensys/gnark-crypto/ecc/bn254"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var _ types.QueryServer = Keeper{}
|
||||
|
||||
func (k Keeper) Signer(
|
||||
c context.Context,
|
||||
req *types.QuerySignerRequest,
|
||||
) (*types.QuerySignerResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
signer, found, err := k.GetSigner(ctx, req.Account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, nil
|
||||
}
|
||||
return &types.QuerySignerResponse{Signer: &signer}, nil
|
||||
}
|
||||
|
||||
func (k Keeper) EpochNumber(
|
||||
c context.Context,
|
||||
_ *types.QueryEpochNumberRequest,
|
||||
) (*types.QueryEpochNumberResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
epochNumber, err := k.GetEpochNumber(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &types.QueryEpochNumberResponse{EpochNumber: epochNumber}, nil
|
||||
}
|
||||
|
||||
func (k Keeper) EpochSignerSet(c context.Context, request *types.QueryEpochSignerSetRequest) (*types.QueryEpochSignerSetResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
epochSignerSet := make([]*types.Signer, 0)
|
||||
signers, found := k.GetEpochSignerSet(ctx, request.EpochNumber)
|
||||
if !found {
|
||||
return &types.QueryEpochSignerSetResponse{Signers: epochSignerSet}, nil
|
||||
}
|
||||
for _, account := range signers.Signers {
|
||||
signer, found, err := k.GetSigner(ctx, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, types.ErrSignerNotFound
|
||||
}
|
||||
epochSignerSet = append(epochSignerSet, &signer)
|
||||
}
|
||||
return &types.QueryEpochSignerSetResponse{Signers: epochSignerSet}, nil
|
||||
}
|
||||
|
||||
func (k Keeper) AggregatePubkeyG1(c context.Context, request *types.QueryAggregatePubkeyG1Request) (*types.QueryAggregatePubkeyG1Response, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
signers, found := k.GetEpochSignerSet(ctx, request.EpochNumber)
|
||||
if !found {
|
||||
return nil, types.ErrEpochSignerSetNotFound
|
||||
}
|
||||
if len(request.SignersBitmap) != (len(signers.Signers)+7)/8 {
|
||||
return nil, types.ErrSignerLengthNotMatch
|
||||
}
|
||||
aggPubkeyG1 := new(bn254.G1Affine)
|
||||
for i, account := range signers.Signers {
|
||||
b := request.SignersBitmap[i/8] & (1 << (i % 8))
|
||||
if b == 0 {
|
||||
continue
|
||||
}
|
||||
signer, found, err := k.GetSigner(ctx, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, types.ErrSignerNotFound
|
||||
}
|
||||
aggPubkeyG1.Add(aggPubkeyG1, bn254util.DeserializeG1(signer.PubkeyG1))
|
||||
}
|
||||
return &types.QueryAggregatePubkeyG1Response{
|
||||
AggregatePubkeyG1: bn254util.SerializeG1(aggPubkeyG1),
|
||||
}, nil
|
||||
}
|
181
x/dasigners/v1/keeper/keeper.go
Normal file
181
x/dasigners/v1/keeper/keeper.go
Normal file
@ -0,0 +1,181 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
)
|
||||
|
||||
type Keeper struct {
|
||||
storeKey storetypes.StoreKey
|
||||
cdc codec.BinaryCodec
|
||||
stakingKeeper types.StakingKeeper
|
||||
}
|
||||
|
||||
// NewKeeper creates a new das Keeper instance
|
||||
func NewKeeper(
|
||||
storeKey storetypes.StoreKey,
|
||||
cdc codec.BinaryCodec,
|
||||
stakingKeeper types.StakingKeeper,
|
||||
) Keeper {
|
||||
return Keeper{
|
||||
storeKey: storeKey,
|
||||
cdc: cdc,
|
||||
stakingKeeper: stakingKeeper,
|
||||
}
|
||||
}
|
||||
|
||||
// Logger returns a module-specific logger.
|
||||
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
||||
return ctx.Logger().With("module", "x/"+types.ModuleName)
|
||||
}
|
||||
|
||||
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(types.ParamsKey)
|
||||
var params types.Params
|
||||
k.cdc.MustUnmarshal(bz, ¶ms)
|
||||
return params
|
||||
}
|
||||
|
||||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := k.cdc.MustMarshal(¶ms)
|
||||
store.Set(types.ParamsKey, bz)
|
||||
}
|
||||
|
||||
func (k Keeper) GetEpochNumber(ctx sdk.Context) (uint64, error) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(types.EpochNumberKey)
|
||||
if bz == nil {
|
||||
return 0, types.ErrEpochNumberNotSet
|
||||
}
|
||||
return sdk.BigEndianToUint64(bz), nil
|
||||
}
|
||||
|
||||
func (k Keeper) SetEpochNumber(ctx sdk.Context, epoch uint64) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
store.Set(types.EpochNumberKey, sdk.Uint64ToBigEndian(epoch))
|
||||
}
|
||||
|
||||
func (k Keeper) GetSigner(ctx sdk.Context, account string) (types.Signer, bool, error) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.SignerKeyPrefix)
|
||||
key, err := types.GetSignerKeyFromAccount(account)
|
||||
if err != nil {
|
||||
return types.Signer{}, false, err
|
||||
}
|
||||
bz := store.Get(key)
|
||||
if bz == nil {
|
||||
return types.Signer{}, false, nil
|
||||
}
|
||||
var signer types.Signer
|
||||
k.cdc.MustUnmarshal(bz, &signer)
|
||||
return signer, true, nil
|
||||
}
|
||||
|
||||
func (k Keeper) SetSigner(ctx sdk.Context, signer types.Signer) error {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.SignerKeyPrefix)
|
||||
bz := k.cdc.MustMarshal(&signer)
|
||||
key, err := types.GetSignerKeyFromAccount(signer.Account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
store.Set(key, bz)
|
||||
|
||||
ctx.EventManager().EmitEvent(
|
||||
sdk.NewEvent(
|
||||
types.EventTypeUpdateSigner,
|
||||
sdk.NewAttribute(types.AttributeKeySigner, signer.Account),
|
||||
sdk.NewAttribute(types.AttributeKeySocket, signer.Socket),
|
||||
sdk.NewAttribute(types.AttributeKeyPublicKeyG1, hex.EncodeToString(signer.PubkeyG1)),
|
||||
sdk.NewAttribute(types.AttributeKeyPublicKeyG2, hex.EncodeToString(signer.PubkeyG2)),
|
||||
),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
// iterate through the signers set and perform the provided function
|
||||
func (k Keeper) IterateSigners(ctx sdk.Context, fn func(index int64, signer types.Signer) (stop bool)) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
||||
iterator := sdk.KVStorePrefixIterator(store, types.SignerKeyPrefix)
|
||||
defer iterator.Close()
|
||||
|
||||
i := int64(0)
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
var signer types.Signer
|
||||
k.cdc.MustUnmarshal(iterator.Value(), &signer)
|
||||
stop := fn(i, signer)
|
||||
|
||||
if stop {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
func (k Keeper) GetEpochSignerSet(ctx sdk.Context, epoch uint64) (types.EpochSignerSet, bool) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.SignerKeyPrefix)
|
||||
bz := store.Get(types.GetEpochSignerSetKeyFromEpoch(epoch))
|
||||
if bz == nil {
|
||||
return types.EpochSignerSet{}, false
|
||||
}
|
||||
var signers types.EpochSignerSet
|
||||
k.cdc.MustUnmarshal(bz, &signers)
|
||||
return signers, true
|
||||
}
|
||||
|
||||
func (k Keeper) SetEpochSignerSet(ctx sdk.Context, epoch uint64, signers types.EpochSignerSet) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.EpochSignerSetKeyPrefix)
|
||||
bz := k.cdc.MustMarshal(&signers)
|
||||
store.Set(types.GetEpochSignerSetKeyFromEpoch(epoch), bz)
|
||||
}
|
||||
|
||||
func (k Keeper) GetRegistration(ctx sdk.Context, epoch uint64, account string) ([]byte, bool, error) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetEpochRegistrationKeyPrefix(epoch))
|
||||
key, err := types.GetRegistrationKey(account)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
signature := store.Get(key)
|
||||
if signature == nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
return signature, true, nil
|
||||
}
|
||||
|
||||
// iterate through the registrations set and perform the provided function
|
||||
func (k Keeper) IterateRegistrations(ctx sdk.Context, epoch uint64, fn func(account string, signature []byte) (stop bool)) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
||||
iterator := sdk.KVStorePrefixIterator(store, types.GetEpochRegistrationKeyPrefix(epoch))
|
||||
defer iterator.Close()
|
||||
|
||||
i := int64(0)
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
stop := fn(hex.EncodeToString(iterator.Key()), iterator.Value())
|
||||
|
||||
if stop {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
func (k Keeper) SetRegistration(ctx sdk.Context, epoch uint64, account string, signature []byte) error {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetEpochRegistrationKeyPrefix(epoch))
|
||||
key, err := types.GetRegistrationKey(account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
store.Set(key, signature)
|
||||
return nil
|
||||
}
|
92
x/dasigners/v1/keeper/msg_server.go
Normal file
92
x/dasigners/v1/keeper/msg_server.go
Normal file
@ -0,0 +1,92 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/0glabs/0g-chain/crypto/bn254util"
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
etherminttypes "github.com/evmos/ethermint/types"
|
||||
)
|
||||
|
||||
var _ types.MsgServer = &Keeper{}
|
||||
|
||||
func (k Keeper) RegisterSigner(goCtx context.Context, msg *types.MsgRegisterSigner) (*types.MsgRegisterSignerResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
// validate sender
|
||||
valAddr, err := sdk.ValAddressFromHex(msg.Signer.Account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, found := k.stakingKeeper.GetValidator(ctx, valAddr)
|
||||
if !found {
|
||||
return nil, stakingtypes.ErrNoValidatorFound
|
||||
}
|
||||
_, found, err = k.GetSigner(ctx, msg.Signer.Account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if found {
|
||||
return nil, types.ErrSignerExists
|
||||
}
|
||||
// validate signature
|
||||
chainID, err := etherminttypes.ParseChainID(ctx.ChainID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash := types.PubkeyRegistrationHash(common.HexToAddress(msg.Signer.Account), chainID)
|
||||
if !msg.Signer.ValidateSignature(hash, bn254util.DeserializeG1(msg.Signature)) {
|
||||
return nil, types.ErrInvalidSignature
|
||||
}
|
||||
// save signer
|
||||
if err := k.SetSigner(ctx, *msg.Signer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &types.MsgRegisterSignerResponse{}, nil
|
||||
}
|
||||
|
||||
func (k Keeper) UpdateSocket(goCtx context.Context, msg *types.MsgUpdateSocket) (*types.MsgUpdateSocketResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
signer, found, err := k.GetSigner(ctx, msg.Account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, types.ErrSignerNotFound
|
||||
}
|
||||
signer.Socket = msg.Socket
|
||||
if err := k.SetSigner(ctx, signer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &types.MsgUpdateSocketResponse{}, nil
|
||||
}
|
||||
|
||||
func (k Keeper) RegisterNextEpoch(goCtx context.Context, msg *types.MsgRegisterNextEpoch) (*types.MsgRegisterNextEpochResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
// get signer
|
||||
signer, found, err := k.GetSigner(ctx, msg.Account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, types.ErrSignerNotFound
|
||||
}
|
||||
// validate signature
|
||||
epochNumber, err := k.GetEpochNumber(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chainID, err := etherminttypes.ParseChainID(ctx.ChainID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash := types.EpochRegistrationHash(common.HexToAddress(msg.Account), epochNumber+1, chainID)
|
||||
if !signer.ValidateSignature(hash, bn254util.DeserializeG1(msg.Signature)) {
|
||||
return nil, types.ErrInvalidSignature
|
||||
}
|
||||
// save registration
|
||||
k.SetRegistration(ctx, epochNumber+1, msg.Account, msg.Signature)
|
||||
return &types.MsgRegisterNextEpochResponse{}, nil
|
||||
}
|
181
x/dasigners/v1/module.go
Normal file
181
x/dasigners/v1/module.go
Normal file
@ -0,0 +1,181 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/client/cli"
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/keeper"
|
||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||
)
|
||||
|
||||
// consensusVersion defines the current x/council module consensus version.
|
||||
const consensusVersion = 1
|
||||
|
||||
// type check to ensure the interface is properly implemented
|
||||
var (
|
||||
_ module.AppModule = AppModule{}
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
)
|
||||
|
||||
// app module Basics object
|
||||
type AppModuleBasic struct{}
|
||||
|
||||
// Name returns the inflation module's name.
|
||||
func (AppModuleBasic) Name() string {
|
||||
return types.ModuleName
|
||||
}
|
||||
|
||||
// RegisterLegacyAminoCodec registers the inflation module's types on the given LegacyAmino codec.
|
||||
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
|
||||
|
||||
// ConsensusVersion returns the consensus state-breaking version for the module.
|
||||
func (AppModuleBasic) ConsensusVersion() uint64 {
|
||||
return consensusVersion
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers interfaces and implementations of the incentives
|
||||
// module.
|
||||
func (AppModuleBasic) RegisterInterfaces(interfaceRegistry codectypes.InterfaceRegistry) {
|
||||
types.RegisterInterfaces(interfaceRegistry)
|
||||
}
|
||||
|
||||
// DefaultGenesis returns default genesis state as raw bytes for the incentives
|
||||
// module.
|
||||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
||||
return cdc.MustMarshalJSON(types.DefaultGenesisState())
|
||||
}
|
||||
|
||||
// ValidateGenesis performs genesis state validation for the inflation module.
|
||||
func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
|
||||
var genesisState types.GenesisState
|
||||
if err := cdc.UnmarshalJSON(bz, &genesisState); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return genesisState.Validate()
|
||||
}
|
||||
|
||||
// RegisterRESTRoutes performs a no-op as the inflation module doesn't expose REST
|
||||
// endpoints
|
||||
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the inflation module.
|
||||
func (b AppModuleBasic) RegisterGRPCGatewayRoutes(c client.Context, serveMux *runtime.ServeMux) {
|
||||
if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(c)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// GetTxCmd returns the root tx command for the inflation module.
|
||||
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.GetTxCmd()
|
||||
}
|
||||
|
||||
// GetQueryCmd returns no root query command for the inflation module.
|
||||
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||
return cli.GetQueryCmd()
|
||||
}
|
||||
|
||||
// ___________________________________________________________________________
|
||||
|
||||
// AppModule implements an application module for the inflation module.
|
||||
type AppModule struct {
|
||||
AppModuleBasic
|
||||
keeper keeper.Keeper
|
||||
sk stakingkeeper.Keeper
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule Object
|
||||
func NewAppModule(
|
||||
k keeper.Keeper,
|
||||
sk stakingkeeper.Keeper,
|
||||
) AppModule {
|
||||
return AppModule{
|
||||
AppModuleBasic: AppModuleBasic{},
|
||||
keeper: k,
|
||||
sk: sk,
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the inflation module's name.
|
||||
func (AppModule) Name() string {
|
||||
return types.ModuleName
|
||||
}
|
||||
|
||||
// Route returns dasigners module's message route.
|
||||
func (am AppModule) Route() sdk.Route { return sdk.Route{} }
|
||||
|
||||
// QuerierRoute returns dasigners module's query routing key.
|
||||
func (AppModule) QuerierRoute() string { return types.QuerierRoute }
|
||||
|
||||
// LegacyQuerierHandler returns dasigners module's Querier.
|
||||
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterInvariants registers the inflation module invariants.
|
||||
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
||||
|
||||
// RegisterServices registers a gRPC query service to respond to the
|
||||
// module-specific gRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
|
||||
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
|
||||
am.keeper.BeginBlock(ctx, req)
|
||||
}
|
||||
|
||||
func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
|
||||
// am.keeper.EndBlock(ctx, req)
|
||||
return []abci.ValidatorUpdate{}
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the inflation module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
var genesisState types.GenesisState
|
||||
|
||||
cdc.MustUnmarshalJSON(data, &genesisState)
|
||||
InitGenesis(ctx, am.keeper, genesisState)
|
||||
return []abci.ValidatorUpdate{}
|
||||
}
|
||||
|
||||
// ExportGenesis returns the exported genesis state as raw bytes for the inflation
|
||||
// module.
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
||||
gs := ExportGenesis(ctx, am.keeper)
|
||||
return cdc.MustMarshalJSON(gs)
|
||||
}
|
||||
|
||||
// ___________________________________________________________________________
|
||||
|
||||
// AppModuleSimulation functions
|
||||
|
||||
// GenerateGenesisState creates a randomized GenState of the inflation module.
|
||||
func (am AppModule) GenerateGenesisState(_ *module.SimulationState) {
|
||||
}
|
||||
|
||||
// RegisterStoreDecoder registers a decoder for inflation module's types.
|
||||
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {
|
||||
}
|
||||
|
||||
// WeightedOperations doesn't return any inflation module operation.
|
||||
func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
|
||||
return []simtypes.WeightedOperation{}
|
||||
}
|
44
x/dasigners/v1/types/codec.go
Normal file
44
x/dasigners/v1/types/codec.go
Normal file
@ -0,0 +1,44 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
)
|
||||
|
||||
var (
|
||||
amino = codec.NewLegacyAmino()
|
||||
// ModuleCdc references the global evm module codec. Note, the codec should
|
||||
// ONLY be used in certain instances of tests and for JSON encoding.
|
||||
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||
|
||||
// AminoCdc is a amino codec created to support amino JSON compatible msgs.
|
||||
AminoCdc = codec.NewAminoCodec(amino)
|
||||
)
|
||||
|
||||
const (
|
||||
// Amino names
|
||||
)
|
||||
|
||||
// NOTE: This is required for the GetSignBytes function
|
||||
func init() {
|
||||
RegisterLegacyAminoCodec(amino)
|
||||
amino.Seal()
|
||||
}
|
||||
|
||||
// RegisterInterfaces register implementations
|
||||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
registry.RegisterImplementations(
|
||||
(*sdk.Msg)(nil),
|
||||
&MsgRegisterSigner{},
|
||||
&MsgUpdateSocket{},
|
||||
&MsgRegisterNextEpoch{},
|
||||
)
|
||||
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
|
||||
// RegisterLegacyAminoCodec required for EIP-712
|
||||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||
}
|
626
x/dasigners/v1/types/dasigners.pb.go
Normal file
626
x/dasigners/v1/types/dasigners.pb.go
Normal file
@ -0,0 +1,626 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: zgc/dasigners/v1/dasigners.proto
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/cosmos/cosmos-proto"
|
||||
_ "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
_ "google.golang.org/protobuf/types/known/durationpb"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type Signer struct {
|
||||
// account defines the hex address of signer without 0x
|
||||
Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
|
||||
// socket defines the da node socket address
|
||||
Socket string `protobuf:"bytes,2,opt,name=socket,proto3" json:"socket,omitempty"`
|
||||
// pubkey_g1 defines the public key on bn254 G1
|
||||
PubkeyG1 []byte `protobuf:"bytes,3,opt,name=pubkey_g1,json=pubkeyG1,proto3" json:"pubkey_g1,omitempty"`
|
||||
// pubkey_g1 defines the public key on bn254 G2
|
||||
PubkeyG2 []byte `protobuf:"bytes,4,opt,name=pubkey_g2,json=pubkeyG2,proto3" json:"pubkey_g2,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Signer) Reset() { *m = Signer{} }
|
||||
func (m *Signer) String() string { return proto.CompactTextString(m) }
|
||||
func (*Signer) ProtoMessage() {}
|
||||
func (*Signer) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_b7328dc8ffac059e, []int{0}
|
||||
}
|
||||
func (m *Signer) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *Signer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_Signer.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *Signer) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Signer.Merge(m, src)
|
||||
}
|
||||
func (m *Signer) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *Signer) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Signer.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Signer proto.InternalMessageInfo
|
||||
|
||||
type EpochSignerSet struct {
|
||||
Signers []string `protobuf:"bytes,1,rep,name=signers,proto3" json:"signers,omitempty"`
|
||||
}
|
||||
|
||||
func (m *EpochSignerSet) Reset() { *m = EpochSignerSet{} }
|
||||
func (m *EpochSignerSet) String() string { return proto.CompactTextString(m) }
|
||||
func (*EpochSignerSet) ProtoMessage() {}
|
||||
func (*EpochSignerSet) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_b7328dc8ffac059e, []int{1}
|
||||
}
|
||||
func (m *EpochSignerSet) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *EpochSignerSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_EpochSignerSet.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *EpochSignerSet) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_EpochSignerSet.Merge(m, src)
|
||||
}
|
||||
func (m *EpochSignerSet) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *EpochSignerSet) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_EpochSignerSet.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_EpochSignerSet proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Signer)(nil), "zgc.dasigners.v1.Signer")
|
||||
proto.RegisterType((*EpochSignerSet)(nil), "zgc.dasigners.v1.EpochSignerSet")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("zgc/dasigners/v1/dasigners.proto", fileDescriptor_b7328dc8ffac059e) }
|
||||
|
||||
var fileDescriptor_b7328dc8ffac059e = []byte{
|
||||
// 287 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0xc1, 0x4a, 0xc3, 0x30,
|
||||
0x1c, 0xc6, 0x1b, 0x27, 0xd3, 0x05, 0x11, 0x29, 0x22, 0xd9, 0x84, 0x50, 0x76, 0x1a, 0x82, 0xcd,
|
||||
0x3a, 0xdf, 0x40, 0x10, 0x4f, 0x5e, 0xb6, 0x9b, 0x97, 0x91, 0x66, 0x31, 0x2d, 0xdb, 0xfa, 0x2f,
|
||||
0x4d, 0x3a, 0xec, 0x9e, 0xc2, 0xc7, 0xda, 0x71, 0x47, 0x8f, 0xda, 0xbe, 0x88, 0xb4, 0xa9, 0xcc,
|
||||
0x79, 0xcb, 0xef, 0xfb, 0x05, 0x3e, 0xfe, 0x1f, 0xf6, 0xb6, 0x4a, 0xb0, 0x05, 0xd7, 0xb1, 0x4a,
|
||||
0x64, 0xa6, 0xd9, 0x26, 0x38, 0x80, 0x9f, 0x66, 0x60, 0xc0, 0xbd, 0xda, 0x2a, 0xe1, 0x1f, 0xc2,
|
||||
0x4d, 0x30, 0xe8, 0x0b, 0xd0, 0x6b, 0xd0, 0xf3, 0xc6, 0x33, 0x0b, 0xf6, 0xf3, 0xe0, 0x5a, 0x81,
|
||||
0x02, 0x9b, 0xd7, 0xaf, 0x36, 0xed, 0x2b, 0x00, 0xb5, 0x92, 0xac, 0xa1, 0x30, 0x7f, 0x63, 0x3c,
|
||||
0x29, 0x5a, 0x45, 0xff, 0xab, 0x45, 0x9e, 0x71, 0x13, 0x43, 0x62, 0xfd, 0xd0, 0xe0, 0xee, 0xac,
|
||||
0x69, 0x76, 0x09, 0x3e, 0xe3, 0x42, 0x40, 0x9e, 0x18, 0x82, 0x3c, 0x34, 0xea, 0x4d, 0x7f, 0xd1,
|
||||
0xbd, 0xc1, 0x5d, 0x0d, 0x62, 0x29, 0x0d, 0x39, 0x69, 0x44, 0x4b, 0xee, 0x2d, 0xee, 0xa5, 0x79,
|
||||
0xb8, 0x94, 0xc5, 0x5c, 0x05, 0xa4, 0xe3, 0xa1, 0xd1, 0xc5, 0xf4, 0xdc, 0x06, 0xcf, 0xc1, 0x5f,
|
||||
0x39, 0x21, 0xa7, 0x47, 0x72, 0x32, 0xbc, 0xc3, 0x97, 0x4f, 0x29, 0x88, 0xc8, 0x56, 0xcf, 0xa4,
|
||||
0xa9, 0xdb, 0xdb, 0x05, 0x08, 0xf2, 0x3a, 0x75, 0x7b, 0x8b, 0x8f, 0x2f, 0xbb, 0x6f, 0xea, 0xec,
|
||||
0x4a, 0x8a, 0xf6, 0x25, 0x45, 0x5f, 0x25, 0x45, 0x1f, 0x15, 0x75, 0xf6, 0x15, 0x75, 0x3e, 0x2b,
|
||||
0xea, 0xbc, 0x32, 0x15, 0x9b, 0x28, 0x0f, 0x7d, 0x01, 0x6b, 0x36, 0x56, 0x2b, 0x1e, 0x6a, 0x36,
|
||||
0x56, 0xf7, 0x22, 0xe2, 0x71, 0xc2, 0xde, 0x8f, 0x87, 0x37, 0x45, 0x2a, 0x75, 0xd8, 0x6d, 0xee,
|
||||
0x7e, 0xf8, 0x09, 0x00, 0x00, 0xff, 0xff, 0x77, 0x51, 0x09, 0xd9, 0x99, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *Signer) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *Signer) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *Signer) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.PubkeyG2) > 0 {
|
||||
i -= len(m.PubkeyG2)
|
||||
copy(dAtA[i:], m.PubkeyG2)
|
||||
i = encodeVarintDasigners(dAtA, i, uint64(len(m.PubkeyG2)))
|
||||
i--
|
||||
dAtA[i] = 0x22
|
||||
}
|
||||
if len(m.PubkeyG1) > 0 {
|
||||
i -= len(m.PubkeyG1)
|
||||
copy(dAtA[i:], m.PubkeyG1)
|
||||
i = encodeVarintDasigners(dAtA, i, uint64(len(m.PubkeyG1)))
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
if len(m.Socket) > 0 {
|
||||
i -= len(m.Socket)
|
||||
copy(dAtA[i:], m.Socket)
|
||||
i = encodeVarintDasigners(dAtA, i, uint64(len(m.Socket)))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(m.Account) > 0 {
|
||||
i -= len(m.Account)
|
||||
copy(dAtA[i:], m.Account)
|
||||
i = encodeVarintDasigners(dAtA, i, uint64(len(m.Account)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *EpochSignerSet) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *EpochSignerSet) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *EpochSignerSet) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Signers) > 0 {
|
||||
for iNdEx := len(m.Signers) - 1; iNdEx >= 0; iNdEx-- {
|
||||
i -= len(m.Signers[iNdEx])
|
||||
copy(dAtA[i:], m.Signers[iNdEx])
|
||||
i = encodeVarintDasigners(dAtA, i, uint64(len(m.Signers[iNdEx])))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintDasigners(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovDasigners(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *Signer) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Account)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovDasigners(uint64(l))
|
||||
}
|
||||
l = len(m.Socket)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovDasigners(uint64(l))
|
||||
}
|
||||
l = len(m.PubkeyG1)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovDasigners(uint64(l))
|
||||
}
|
||||
l = len(m.PubkeyG2)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovDasigners(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *EpochSignerSet) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Signers) > 0 {
|
||||
for _, s := range m.Signers {
|
||||
l = len(s)
|
||||
n += 1 + l + sovDasigners(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovDasigners(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozDasigners(x uint64) (n int) {
|
||||
return sovDasigners(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *Signer) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: Signer: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: Signer: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Account", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Account = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Socket", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Socket = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PubkeyG1", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.PubkeyG1 = append(m.PubkeyG1[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.PubkeyG1 == nil {
|
||||
m.PubkeyG1 = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PubkeyG2", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.PubkeyG2 = append(m.PubkeyG2[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.PubkeyG2 == nil {
|
||||
m.PubkeyG2 = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipDasigners(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *EpochSignerSet) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: EpochSignerSet: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: EpochSignerSet: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Signers", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Signers = append(m.Signers, string(dAtA[iNdEx:postIndex]))
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipDasigners(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthDasigners
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipDasigners(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowDasigners
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthDasigners
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupDasigners
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthDasigners
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthDasigners = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowDasigners = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupDasigners = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
12
x/dasigners/v1/types/errors.go
Normal file
12
x/dasigners/v1/types/errors.go
Normal file
@ -0,0 +1,12 @@
|
||||
package types
|
||||
|
||||
import errorsmod "cosmossdk.io/errors"
|
||||
|
||||
var (
|
||||
ErrSignerExists = errorsmod.Register(ModuleName, 1, "signer exists")
|
||||
ErrEpochNumberNotSet = errorsmod.Register(ModuleName, 2, "epoch number not set")
|
||||
ErrSignerNotFound = errorsmod.Register(ModuleName, 3, "signer not found")
|
||||
ErrInvalidSignature = errorsmod.Register(ModuleName, 4, "invalid signature")
|
||||
ErrEpochSignerSetNotFound = errorsmod.Register(ModuleName, 5, "signer set for epoch not found")
|
||||
ErrSignerLengthNotMatch = errorsmod.Register(ModuleName, 6, "signer set length not match")
|
||||
)
|
11
x/dasigners/v1/types/events.go
Normal file
11
x/dasigners/v1/types/events.go
Normal file
@ -0,0 +1,11 @@
|
||||
package types
|
||||
|
||||
// Module event types
|
||||
const (
|
||||
EventTypeUpdateSigner = "update_signer"
|
||||
|
||||
AttributeKeySigner = "signer"
|
||||
AttributeKeySocket = "socket"
|
||||
AttributeKeyPublicKeyG1 = "pubkey_g1"
|
||||
AttributeKeyPublicKeyG2 = "pubkey_g2"
|
||||
)
|
48
x/dasigners/v1/types/genesis.go
Normal file
48
x/dasigners/v1/types/genesis.go
Normal file
@ -0,0 +1,48 @@
|
||||
package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
// NewGenesisState returns a new genesis state object for the module.
|
||||
func NewGenesisState(params Params, epoch uint64, signers []*Signer, signersByEpoch []*EpochSignerSet) *GenesisState {
|
||||
return &GenesisState{
|
||||
Params: params,
|
||||
EpochNumber: epoch,
|
||||
Signers: signers,
|
||||
SignersByEpoch: signersByEpoch,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultGenesisState returns the default genesis state for the module.
|
||||
func DefaultGenesisState() *GenesisState {
|
||||
return NewGenesisState(Params{
|
||||
QuorumSize: 1024,
|
||||
TokensPerVote: "1000",
|
||||
MaxVotes: 100,
|
||||
EpochBlocks: 5,
|
||||
}, 0, make([]*Signer, 0), make([]*EpochSignerSet, 0))
|
||||
}
|
||||
|
||||
// Validate performs basic validation of genesis data.
|
||||
func (gs GenesisState) Validate() error {
|
||||
registered := make(map[string]struct{})
|
||||
for _, signer := range gs.Signers {
|
||||
if err := signer.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
registered[signer.Account] = struct{}{}
|
||||
}
|
||||
if len(gs.SignersByEpoch) != int(gs.EpochNumber) {
|
||||
return fmt.Errorf("epoch history missing")
|
||||
}
|
||||
for _, signers := range gs.SignersByEpoch {
|
||||
for _, signer := range signers.Signers {
|
||||
if err := ValidateHexAddress(signer); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ok := registered[signer]; !ok {
|
||||
return fmt.Errorf("historical signer detail missing")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
775
x/dasigners/v1/types/genesis.pb.go
Normal file
775
x/dasigners/v1/types/genesis.pb.go
Normal file
@ -0,0 +1,775 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: zgc/dasigners/v1/genesis.proto
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/cosmos/cosmos-proto"
|
||||
_ "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
_ "google.golang.org/protobuf/types/known/timestamppb"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type Params struct {
|
||||
QuorumSize uint64 `protobuf:"varint,1,opt,name=quorum_size,json=quorumSize,proto3" json:"quorum_size,omitempty"`
|
||||
TokensPerVote string `protobuf:"bytes,2,opt,name=tokens_per_vote,json=tokensPerVote,proto3" json:"tokens_per_vote,omitempty"`
|
||||
MaxVotes uint64 `protobuf:"varint,3,opt,name=max_votes,json=maxVotes,proto3" json:"max_votes,omitempty"`
|
||||
EpochBlocks uint64 `protobuf:"varint,4,opt,name=epoch_blocks,json=epochBlocks,proto3" json:"epoch_blocks,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Params) Reset() { *m = Params{} }
|
||||
func (m *Params) String() string { return proto.CompactTextString(m) }
|
||||
func (*Params) ProtoMessage() {}
|
||||
func (*Params) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_896efa766aaca3be, []int{0}
|
||||
}
|
||||
func (m *Params) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_Params.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *Params) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Params.Merge(m, src)
|
||||
}
|
||||
func (m *Params) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *Params) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Params.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Params proto.InternalMessageInfo
|
||||
|
||||
func (m *Params) GetQuorumSize() uint64 {
|
||||
if m != nil {
|
||||
return m.QuorumSize
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Params) GetTokensPerVote() string {
|
||||
if m != nil {
|
||||
return m.TokensPerVote
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Params) GetMaxVotes() uint64 {
|
||||
if m != nil {
|
||||
return m.MaxVotes
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Params) GetEpochBlocks() uint64 {
|
||||
if m != nil {
|
||||
return m.EpochBlocks
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// GenesisState defines the dasigners module's genesis state.
|
||||
type GenesisState struct {
|
||||
// params defines all the parameters of related to deposit.
|
||||
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
|
||||
// params epoch_number the epoch number
|
||||
EpochNumber uint64 `protobuf:"varint,2,opt,name=epoch_number,json=epochNumber,proto3" json:"epoch_number,omitempty"`
|
||||
// signers defines all signers information
|
||||
Signers []*Signer `protobuf:"bytes,3,rep,name=signers,proto3" json:"signers,omitempty"`
|
||||
// signers_by_epoch defines chosen signers by epoch
|
||||
SignersByEpoch []*EpochSignerSet `protobuf:"bytes,4,rep,name=signers_by_epoch,json=signersByEpoch,proto3" json:"signers_by_epoch,omitempty"`
|
||||
}
|
||||
|
||||
func (m *GenesisState) Reset() { *m = GenesisState{} }
|
||||
func (m *GenesisState) String() string { return proto.CompactTextString(m) }
|
||||
func (*GenesisState) ProtoMessage() {}
|
||||
func (*GenesisState) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_896efa766aaca3be, []int{1}
|
||||
}
|
||||
func (m *GenesisState) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *GenesisState) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GenesisState.Merge(m, src)
|
||||
}
|
||||
func (m *GenesisState) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *GenesisState) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GenesisState.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GenesisState proto.InternalMessageInfo
|
||||
|
||||
func (m *GenesisState) GetParams() Params {
|
||||
if m != nil {
|
||||
return m.Params
|
||||
}
|
||||
return Params{}
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetEpochNumber() uint64 {
|
||||
if m != nil {
|
||||
return m.EpochNumber
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetSigners() []*Signer {
|
||||
if m != nil {
|
||||
return m.Signers
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetSignersByEpoch() []*EpochSignerSet {
|
||||
if m != nil {
|
||||
return m.SignersByEpoch
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Params)(nil), "zgc.dasigners.v1.Params")
|
||||
proto.RegisterType((*GenesisState)(nil), "zgc.dasigners.v1.GenesisState")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("zgc/dasigners/v1/genesis.proto", fileDescriptor_896efa766aaca3be) }
|
||||
|
||||
var fileDescriptor_896efa766aaca3be = []byte{
|
||||
// 415 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x6e, 0xd3, 0x30,
|
||||
0x1c, 0xc6, 0x6b, 0x1a, 0x15, 0xe6, 0x0e, 0x98, 0x2c, 0x0e, 0xd9, 0x90, 0xd2, 0xb0, 0x03, 0xda,
|
||||
0x85, 0x78, 0x1b, 0x12, 0x0f, 0x10, 0x09, 0x21, 0x38, 0xa0, 0x29, 0x91, 0x38, 0x70, 0x89, 0x9c,
|
||||
0xf0, 0xc7, 0x8d, 0x56, 0xc7, 0x21, 0x76, 0xaa, 0x26, 0x4f, 0x01, 0x6f, 0xb5, 0xe3, 0x8e, 0x9c,
|
||||
0x10, 0x6a, 0x4f, 0xbc, 0x05, 0xea, 0xdf, 0x19, 0x13, 0xeb, 0x6e, 0x7f, 0x7f, 0xbf, 0xcf, 0x9f,
|
||||
0x3f, 0xdb, 0x34, 0xe8, 0x65, 0xc1, 0xbf, 0x08, 0x53, 0xca, 0x0a, 0x1a, 0xc3, 0x97, 0x67, 0x5c,
|
||||
0x42, 0x05, 0xa6, 0x34, 0x51, 0xdd, 0x68, 0xab, 0xd9, 0x41, 0x2f, 0x8b, 0xe8, 0x1f, 0x8f, 0x96,
|
||||
0x67, 0x47, 0x87, 0x85, 0x36, 0x4a, 0x9b, 0x0c, 0x39, 0x77, 0x0b, 0x67, 0x3e, 0x7a, 0x26, 0xb5,
|
||||
0xd4, 0x4e, 0xdf, 0x4e, 0x83, 0x7a, 0x28, 0xb5, 0x96, 0x0b, 0xe0, 0xb8, 0xca, 0xdb, 0xaf, 0x5c,
|
||||
0x54, 0xdd, 0x80, 0x66, 0x77, 0x91, 0x2d, 0x15, 0x18, 0x2b, 0x54, 0x3d, 0x18, 0xc2, 0x9d, 0x7a,
|
||||
0xb7, 0x5d, 0xd0, 0x71, 0xfc, 0x83, 0xd0, 0xc9, 0x85, 0x68, 0x84, 0x32, 0x6c, 0x46, 0xa7, 0xdf,
|
||||
0x5a, 0xdd, 0xb4, 0x2a, 0x33, 0x65, 0x0f, 0x3e, 0x09, 0xc9, 0x89, 0x97, 0x50, 0x27, 0xa5, 0x65,
|
||||
0x0f, 0xec, 0x25, 0x7d, 0x6a, 0xf5, 0x25, 0x54, 0x26, 0xab, 0xa1, 0xc9, 0x96, 0xda, 0x82, 0xff,
|
||||
0x20, 0x24, 0x27, 0x7b, 0xc9, 0x63, 0x27, 0x5f, 0x40, 0xf3, 0x49, 0x5b, 0x60, 0xcf, 0xe9, 0x9e,
|
||||
0x12, 0x2b, 0x34, 0x18, 0x7f, 0x8c, 0x31, 0x8f, 0x94, 0x58, 0x6d, 0x99, 0x61, 0x2f, 0xe8, 0x3e,
|
||||
0xd4, 0xba, 0x98, 0x67, 0xf9, 0x42, 0x17, 0x97, 0xc6, 0xf7, 0x90, 0x4f, 0x51, 0x8b, 0x51, 0x3a,
|
||||
0xfe, 0x43, 0xe8, 0xfe, 0x3b, 0xf7, 0x8c, 0xa9, 0x15, 0x16, 0xd8, 0x1b, 0x3a, 0xa9, 0xb1, 0x23,
|
||||
0x96, 0x9a, 0x9e, 0xfb, 0xd1, 0xdd, 0x67, 0x8d, 0xdc, 0x1d, 0x62, 0xef, 0xea, 0xd7, 0x6c, 0x94,
|
||||
0x0c, 0xee, 0xdb, 0xb3, 0xaa, 0x56, 0xe5, 0xd0, 0x60, 0xdb, 0x9b, 0xb3, 0x3e, 0xa2, 0xc4, 0xce,
|
||||
0xe9, 0xc3, 0x21, 0xc5, 0x1f, 0x87, 0xe3, 0xfb, 0xb3, 0x53, 0x1c, 0x93, 0x1b, 0x23, 0xfb, 0x40,
|
||||
0x0f, 0x86, 0x31, 0xcb, 0xbb, 0x0c, 0xd3, 0x7c, 0x0f, 0x37, 0x87, 0xbb, 0x9b, 0xdf, 0x6e, 0xb1,
|
||||
0x4b, 0x48, 0xc1, 0x26, 0x4f, 0x06, 0x14, 0x77, 0x08, 0xe2, 0xf7, 0x57, 0xeb, 0x80, 0x5c, 0xaf,
|
||||
0x03, 0xf2, 0x7b, 0x1d, 0x90, 0xef, 0x9b, 0x60, 0x74, 0xbd, 0x09, 0x46, 0x3f, 0x37, 0xc1, 0xe8,
|
||||
0x33, 0x97, 0xa5, 0x9d, 0xb7, 0x79, 0x54, 0x68, 0xc5, 0x4f, 0xe5, 0x42, 0xe4, 0x86, 0x9f, 0xca,
|
||||
0x57, 0xc5, 0x5c, 0x94, 0x15, 0x5f, 0xfd, 0xff, 0xa9, 0xb6, 0xab, 0xc1, 0xe4, 0x13, 0xfc, 0xd1,
|
||||
0xd7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xd0, 0x84, 0xf4, 0xab, 0x94, 0x02, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *Params) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *Params) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.EpochBlocks != 0 {
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(m.EpochBlocks))
|
||||
i--
|
||||
dAtA[i] = 0x20
|
||||
}
|
||||
if m.MaxVotes != 0 {
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(m.MaxVotes))
|
||||
i--
|
||||
dAtA[i] = 0x18
|
||||
}
|
||||
if len(m.TokensPerVote) > 0 {
|
||||
i -= len(m.TokensPerVote)
|
||||
copy(dAtA[i:], m.TokensPerVote)
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.TokensPerVote)))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if m.QuorumSize != 0 {
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(m.QuorumSize))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.SignersByEpoch) > 0 {
|
||||
for iNdEx := len(m.SignersByEpoch) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.SignersByEpoch[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x22
|
||||
}
|
||||
}
|
||||
if len(m.Signers) > 0 {
|
||||
for iNdEx := len(m.Signers) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Signers[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
}
|
||||
if m.EpochNumber != 0 {
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(m.EpochNumber))
|
||||
i--
|
||||
dAtA[i] = 0x10
|
||||
}
|
||||
{
|
||||
size, err := m.Params.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovGenesis(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *Params) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.QuorumSize != 0 {
|
||||
n += 1 + sovGenesis(uint64(m.QuorumSize))
|
||||
}
|
||||
l = len(m.TokensPerVote)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
if m.MaxVotes != 0 {
|
||||
n += 1 + sovGenesis(uint64(m.MaxVotes))
|
||||
}
|
||||
if m.EpochBlocks != 0 {
|
||||
n += 1 + sovGenesis(uint64(m.EpochBlocks))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *GenesisState) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = m.Params.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
if m.EpochNumber != 0 {
|
||||
n += 1 + sovGenesis(uint64(m.EpochNumber))
|
||||
}
|
||||
if len(m.Signers) > 0 {
|
||||
for _, e := range m.Signers {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.SignersByEpoch) > 0 {
|
||||
for _, e := range m.SignersByEpoch {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovGenesis(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozGenesis(x uint64) (n int) {
|
||||
return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *Params) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: Params: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field QuorumSize", wireType)
|
||||
}
|
||||
m.QuorumSize = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.QuorumSize |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field TokensPerVote", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.TokensPerVote = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field MaxVotes", wireType)
|
||||
}
|
||||
m.MaxVotes = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.MaxVotes |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 4:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field EpochBlocks", wireType)
|
||||
}
|
||||
m.EpochBlocks = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.EpochBlocks |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *GenesisState) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: GenesisState: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field EpochNumber", wireType)
|
||||
}
|
||||
m.EpochNumber = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.EpochNumber |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Signers", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Signers = append(m.Signers, &Signer{})
|
||||
if err := m.Signers[len(m.Signers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field SignersByEpoch", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.SignersByEpoch = append(m.SignersByEpoch, &EpochSignerSet{})
|
||||
if err := m.SignersByEpoch[len(m.SignersByEpoch)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipGenesis(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupGenesis
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
43
x/dasigners/v1/types/hash.go
Normal file
43
x/dasigners/v1/types/hash.go
Normal file
@ -0,0 +1,43 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/0glabs/0g-chain/crypto/bn254util"
|
||||
"github.com/consensys/gnark-crypto/ecc/bn254"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func PubkeyRegistrationHash(operatorAddress common.Address, chainId *big.Int) *bn254.G1Affine {
|
||||
toHash := make([]byte, 0)
|
||||
toHash = append(toHash, operatorAddress.Bytes()...)
|
||||
// make sure chainId is 32 bytes
|
||||
toHash = append(toHash, common.LeftPadBytes(chainId.Bytes(), 32)...)
|
||||
toHash = append(toHash, []byte("0G_BN254_Pubkey_Registration")...)
|
||||
|
||||
msgHash := crypto.Keccak256(toHash)
|
||||
// convert to [32]byte
|
||||
var msgHash32 [32]byte
|
||||
copy(msgHash32[:], msgHash)
|
||||
|
||||
// hash to G1
|
||||
return bn254util.MapToCurve(msgHash32)
|
||||
}
|
||||
|
||||
func EpochRegistrationHash(operatorAddress common.Address, epoch uint64, chainId *big.Int) *bn254.G1Affine {
|
||||
toHash := make([]byte, 0)
|
||||
toHash = append(toHash, operatorAddress.Bytes()...)
|
||||
toHash = append(toHash, sdk.Uint64ToBigEndian(epoch)...)
|
||||
toHash = append(toHash, common.LeftPadBytes(chainId.Bytes(), 32)...)
|
||||
|
||||
msgHash := crypto.Keccak256(toHash)
|
||||
// convert to [32]byte
|
||||
var msgHash32 [32]byte
|
||||
copy(msgHash32[:], msgHash)
|
||||
|
||||
// hash to G1
|
||||
return bn254util.MapToCurve(msgHash32)
|
||||
}
|
10
x/dasigners/v1/types/interfaces.go
Normal file
10
x/dasigners/v1/types/interfaces.go
Normal file
@ -0,0 +1,10 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
type StakingKeeper interface {
|
||||
GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool)
|
||||
}
|
45
x/dasigners/v1/types/keys.go
Normal file
45
x/dasigners/v1/types/keys.go
Normal file
@ -0,0 +1,45 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// ModuleName The name that will be used throughout the module
|
||||
ModuleName = "da-signers"
|
||||
|
||||
// StoreKey Top level store key where all module items will be stored
|
||||
StoreKey = ModuleName
|
||||
|
||||
// QuerierRoute Top level query string
|
||||
QuerierRoute = ModuleName
|
||||
)
|
||||
|
||||
var (
|
||||
// prefix
|
||||
SignerKeyPrefix = []byte{0x00}
|
||||
EpochSignerSetKeyPrefix = []byte{0x01}
|
||||
RegistrationKeyPrefix = []byte{0x02}
|
||||
|
||||
// keys
|
||||
ParamsKey = []byte{0x05}
|
||||
EpochNumberKey = []byte{0x06}
|
||||
)
|
||||
|
||||
func GetSignerKeyFromAccount(account string) ([]byte, error) {
|
||||
return hex.DecodeString(account)
|
||||
}
|
||||
|
||||
func GetEpochSignerSetKeyFromEpoch(epoch uint64) []byte {
|
||||
return sdk.Uint64ToBigEndian(epoch)
|
||||
}
|
||||
|
||||
func GetEpochRegistrationKeyPrefix(epoch uint64) []byte {
|
||||
return append(RegistrationKeyPrefix, sdk.Uint64ToBigEndian(epoch)...)
|
||||
}
|
||||
|
||||
func GetRegistrationKey(account string) ([]byte, error) {
|
||||
return hex.DecodeString(account)
|
||||
}
|
96
x/dasigners/v1/types/msg.go
Normal file
96
x/dasigners/v1/types/msg.go
Normal file
@ -0,0 +1,96 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
fmt "fmt"
|
||||
|
||||
"github.com/0glabs/0g-chain/crypto/bn254util"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var _, _, _ sdk.Msg = &MsgRegisterSigner{}, &MsgUpdateSocket{}, &MsgRegisterNextEpoch{}
|
||||
|
||||
// GetSigners returns the expected signers for a MsgRegister message.
|
||||
func (msg *MsgRegisterSigner) GetSigners() []sdk.AccAddress {
|
||||
valAddr, err := sdk.ValAddressFromHex(msg.Signer.Account)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
accAddr, err := sdk.AccAddressFromHexUnsafe(hex.EncodeToString(valAddr.Bytes()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// ValidateBasic does a sanity check of the provided data
|
||||
func (msg *MsgRegisterSigner) ValidateBasic() error {
|
||||
if err := msg.Signer.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(msg.Signature) != bn254util.G1PointSize {
|
||||
return fmt.Errorf("invalid signature")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes implements the LegacyMsg interface.
|
||||
func (msg MsgRegisterSigner) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&msg))
|
||||
}
|
||||
|
||||
// GetSigners returns the expected signers for a MsgVote message.
|
||||
func (msg *MsgUpdateSocket) GetSigners() []sdk.AccAddress {
|
||||
valAddr, err := sdk.ValAddressFromHex(msg.Account)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
accAddr, err := sdk.AccAddressFromHexUnsafe(hex.EncodeToString(valAddr.Bytes()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// ValidateBasic does a sanity check of the provided data
|
||||
func (msg *MsgUpdateSocket) ValidateBasic() error {
|
||||
if err := ValidateHexAddress(msg.Account); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes implements the LegacyMsg interface.
|
||||
func (msg MsgUpdateSocket) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&msg))
|
||||
}
|
||||
|
||||
// GetSigners returns the expected signers for a MsgVote message.
|
||||
func (msg *MsgRegisterNextEpoch) GetSigners() []sdk.AccAddress {
|
||||
valAddr, err := sdk.ValAddressFromHex(msg.Account)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
accAddr, err := sdk.AccAddressFromHexUnsafe(hex.EncodeToString(valAddr.Bytes()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// ValidateBasic does a sanity check of the provided data
|
||||
func (msg *MsgRegisterNextEpoch) ValidateBasic() error {
|
||||
if err := ValidateHexAddress(msg.Account); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(msg.Signature) != bn254util.G1PointSize {
|
||||
return fmt.Errorf("invalid signature")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes implements the LegacyMsg interface.
|
||||
func (msg MsgRegisterNextEpoch) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&msg))
|
||||
}
|
1648
x/dasigners/v1/types/query.pb.go
Normal file
1648
x/dasigners/v1/types/query.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
402
x/dasigners/v1/types/query.pb.gw.go
Normal file
402
x/dasigners/v1/types/query.pb.gw.go
Normal file
@ -0,0 +1,402 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: zgc/dasigners/v1/query.proto
|
||||
|
||||
/*
|
||||
Package types is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/descriptor"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = descriptor.ForMessage
|
||||
var _ = metadata.Join
|
||||
|
||||
func request_Query_EpochNumber_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryEpochNumberRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.EpochNumber(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_EpochNumber_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryEpochNumberRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.EpochNumber(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_EpochSignerSet_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_Query_EpochSignerSet_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryEpochSignerSetRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_EpochSignerSet_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.EpochSignerSet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_EpochSignerSet_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryEpochSignerSetRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_EpochSignerSet_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.EpochSignerSet(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_AggregatePubkeyG1_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_Query_AggregatePubkeyG1_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryAggregatePubkeyG1Request
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AggregatePubkeyG1_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.AggregatePubkeyG1(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_AggregatePubkeyG1_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryAggregatePubkeyG1Request
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AggregatePubkeyG1_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.AggregatePubkeyG1(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_Signer_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_Query_Signer_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QuerySignerRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Signer_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Signer(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Signer_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QuerySignerRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Signer_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Signer(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
|
||||
// UnaryRPC :call QueryServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
|
||||
func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
|
||||
|
||||
mux.Handle("GET", pattern_Query_EpochNumber_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_EpochNumber_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_EpochNumber_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_EpochSignerSet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_EpochSignerSet_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_EpochSignerSet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_AggregatePubkeyG1_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_AggregatePubkeyG1_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_AggregatePubkeyG1_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Signer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Signer_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Signer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.Dial(endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterQueryHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterQueryHandler registers the http handlers for service Query to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn))
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerClient registers the http handlers for service Query
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "QueryClient" to call the correct interceptors.
|
||||
func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
|
||||
|
||||
mux.Handle("GET", pattern_Query_EpochNumber_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_EpochNumber_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_EpochNumber_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_EpochSignerSet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_EpochSignerSet_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_EpochSignerSet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_AggregatePubkeyG1_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_AggregatePubkeyG1_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_AggregatePubkeyG1_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Signer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Signer_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Signer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_Query_EpochNumber_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"0gchain", "dasigners", "v1", "epoch-number"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_EpochSignerSet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"0gchain", "dasigners", "v1", "epoch-signer-set"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_AggregatePubkeyG1_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"0gchain", "dasigners", "v1", "aggregate-pubkey-g1"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Signer_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"0gchain", "dasigners", "v1", "signer"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_Query_EpochNumber_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_EpochSignerSet_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_AggregatePubkeyG1_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Signer_0 = runtime.ForwardResponseMessage
|
||||
)
|
55
x/dasigners/v1/types/signer.go
Normal file
55
x/dasigners/v1/types/signer.go
Normal file
@ -0,0 +1,55 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
fmt "fmt"
|
||||
|
||||
"github.com/0glabs/0g-chain/crypto/bn254util"
|
||||
"github.com/consensys/gnark-crypto/ecc/bn254"
|
||||
)
|
||||
|
||||
func ValidateHexAddress(account string) error {
|
||||
addr, err := hex.DecodeString(account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(addr) != 20 {
|
||||
return fmt.Errorf("invalid address length")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Signer) Validate() error {
|
||||
if len(s.PubkeyG1) != bn254util.G1PointSize {
|
||||
return fmt.Errorf("invalid G1 pubkey length")
|
||||
}
|
||||
if len(s.PubkeyG2) != bn254util.G2PointSize {
|
||||
return fmt.Errorf("invalid G2 pubkey length")
|
||||
}
|
||||
if err := ValidateHexAddress(s.Account); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Signer) ValidateSignature(hash *bn254.G1Affine, signature *bn254.G1Affine) bool {
|
||||
pubkeyG1 := bn254util.DeserializeG1(s.PubkeyG1)
|
||||
pubkeyG2 := bn254util.DeserializeG2(s.PubkeyG2)
|
||||
gamma := bn254util.Gamma(hash, signature, pubkeyG1, pubkeyG2)
|
||||
|
||||
// pairing
|
||||
P := [2]bn254.G1Affine{
|
||||
*new(bn254.G1Affine).Add(signature, new(bn254.G1Affine).ScalarMultiplication(pubkeyG1, gamma)),
|
||||
*new(bn254.G1Affine).Add(hash, new(bn254.G1Affine).ScalarMultiplication(bn254util.GetG1Generator(), gamma)),
|
||||
}
|
||||
Q := [2]bn254.G2Affine{
|
||||
*new(bn254.G2Affine).Neg(bn254util.GetG2Generator()),
|
||||
*pubkeyG2,
|
||||
}
|
||||
|
||||
ok, err := bn254.PairingCheck(P[:], Q[:])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return ok
|
||||
}
|
1312
x/dasigners/v1/types/tx.pb.go
Normal file
1312
x/dasigners/v1/types/tx.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user