From f1059f9165b06d63343068bc7531a157251a5057 Mon Sep 17 00:00:00 2001 From: nisdas Date: Fri, 27 Mar 2020 10:01:04 +0800 Subject: [PATCH 1/3] fix mock rpc --- eth1/deposits.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/eth1/deposits.go b/eth1/deposits.go index d602298..f969a7a 100644 --- a/eth1/deposits.go +++ b/eth1/deposits.go @@ -11,7 +11,8 @@ var ( MaxEffectiveBalance = uint64(32 * 1e9) blsWithdrawalPrefixByte = byte(0) domainDeposit = [4]byte{3, 0, 0, 0} - genesisForkVersion = []byte{0, 0, 0, 0} + genesisForkVersion = [4]byte{0, 0, 0, 0} + zerohash = [32]byte{} depositContractTreeDepth = uint64(32) depositEventSignature = []byte("DepositEvent(bytes,bytes,bytes,bytes,bytes)") ) @@ -26,6 +27,11 @@ type DepositData struct { Signature []byte `json:"signature,omitempty" ssz-size:"96"` } +type ForkData struct { + CurrentVersion [4]byte + GenesisValidatorsRoot [32]byte +} + // CreateDepositData takes in raw private key bytes and a deposit amount and generates // the proper DepositData Eth2 struct type. This involves BLS signing the deposit, // generating hashed withdrawal credentials, and including the public key from the validator's @@ -50,8 +56,11 @@ func CreateDepositData(validatorKey []byte, withdrawalKey []byte, amountInGwei u return nil, err } - domain := bls.Domain(domainDeposit[:], genesisForkVersion) - di.Signature = sk1.Sign(sr[:], domain).Marshal() + d, err := domain() + if err != nil { + return nil, err + } + di.Signature = sk1.Sign(sr[:], d).Marshal() return di, nil } @@ -66,3 +75,17 @@ func withdrawalCredentialsHash(withdrawalKey *bls.SecretKey) []byte { h := hashutil.HashKeccak256(withdrawalKey.PublicKey().Marshal()) return append([]byte{blsWithdrawalPrefixByte}, h[0:]...)[:32] } + +func domain() ([]byte, error) { + root, err := ssz.HashTreeRoot(&ForkData{ + CurrentVersion: genesisForkVersion, + GenesisValidatorsRoot: zerohash, + }) + if err != nil { + return []byte{}, err + } + b := []byte{} + b = append(b, domainDeposit[:4]...) + b = append(b, root[:28]...) + return b, nil +} From 1f17555993f082868b785b840e388814f8f1b1c3 Mon Sep 17 00:00:00 2001 From: nisdas Date: Fri, 27 Mar 2020 10:36:34 +0800 Subject: [PATCH 2/3] fix everything --- WORKSPACE | 70 ++++++++++++++++++++++++++++++++++++++++-------- eth1/deposits.go | 26 +++++++++++++----- 2 files changed, 78 insertions(+), 18 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 960ab0e..4d3a2f0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,21 +3,27 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") http_archive( name = "io_bazel_rules_go", - sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d", - url = "https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", + sha256 = "e6a6c016b0663e06fa5fccf1cd8152eab8aa8180c583ec20c872f4f9953a7ac5", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.22.1/rules_go-v0.22.1.tar.gz", + "https://github.com/bazelbuild/rules_go/releases/download/v0.22.1/rules_go-v0.22.1.tar.gz", + ], ) http_archive( name = "bazel_gazelle", - sha256 = "3c681998538231a2d24d0c07ed5a7658cb72bfb5fd4bf9911157c0e9ac6a2687", - urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.17.0/bazel-gazelle-0.17.0.tar.gz"], + sha256 = "d8c45ee70ec39a57e7a05e5027c32b1576cc7f16d9dd37135b0eddde45cf1b10", + urls = [ + "https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.20.0/bazel-gazelle-v0.20.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.20.0/bazel-gazelle-v0.20.0.tar.gz", + ], ) http_archive( name = "com_github_atlassian_bazel_tools", - sha256 = "6b438f4d8c698f69ed4473cba12da3c3a7febf90ce8e3c383533d5a64d8c8f19", - strip_prefix = "bazel-tools-6fbc36c639a8f376182bb0057dd557eb2440d4ed", - urls = ["https://github.com/atlassian/bazel-tools/archive/6fbc36c639a8f376182bb0057dd557eb2440d4ed.tar.gz"], + sha256 = "60821f298a7399450b51b9020394904bbad477c18718d2ad6c789f231e5b8b45", + strip_prefix = "bazel-tools-a2138311856f55add11cd7009a5abc8d4fd6f163", + urls = ["https://github.com/atlassian/bazel-tools/archive/a2138311856f55add11cd7009a5abc8d4fd6f163.tar.gz"], ) http_archive( @@ -34,6 +40,17 @@ http_archive( url = "https://github.com/kubernetes/repo-infra/archive/1b2ddaf3fb8775a5d0f4e28085cf846f915977a8.tar.gz", ) +http_archive( + name = "herumi_bls_eth_go_binary", + strip_prefix = "bls-eth-go-binary-da18d415993a059052dfed16711f2b3bd03c34b8", + urls = [ + "https://github.com/herumi/bls-eth-go-binary/archive/da18d415993a059052dfed16711f2b3bd03c34b8.tar.gz", + ], + sha256 = "69080ca634f8aaeb0950e19db218811f4bb920a054232e147669ea574ba11ef0", + build_file = "@com_github_prysmaticlabs_prysm//third_party/herumi:bls_eth_go_binary.BUILD", + +) + load( "@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories", @@ -114,7 +131,7 @@ go_repository( go_repository( name = "com_github_prysmaticlabs_prysm", - commit = "5e939378d0c83c074bfed6ecaba5b505074a7a01", + commit = "ec2a100ba992c1a61d66c605c867d0da9777d741", importpath = "github.com/prysmaticlabs/prysm", ) @@ -125,9 +142,28 @@ go_repository( ) go_repository( - name = "com_github_karlseguin_ccache", - commit = "ec06cd93a07565b373789b0078ba88fe697fddd9", - importpath = "github.com/karlseguin/ccache", + name = "com_github_dgraph_io_ristretto", + commit = "99d1bbbf28e64530eb246be0568fc7709a35ebdd", # v0.0.1 + importpath = "github.com/dgraph-io/ristretto", +) + +go_repository( + name = "com_github_minio_highwayhash", + importpath = "github.com/minio/highwayhash", + commit = "02ca4b43caa3297fbb615700d8800acc7933be98", +) + +go_repository( + name = "in_gopkg_urfave_cli_v2", + importpath = "gopkg.in/urfave/cli.v2", + sum = "h1:OvXt/p4cdwNl+mwcWMq/AxaKFkhdxcjx+tx+qf4EOvY=", + version = "v2.0.0-20190806201727-b62605953717", +) + +go_repository( + name = "com_github_cespare_xxhash", + commit = "d7df74196a9e781ede915320c11c378c1b2f3a1f", + importpath = "github.com/cespare/xxhash", ) go_repository( @@ -136,6 +172,18 @@ go_repository( importpath = "github.com/prysmaticlabs/go-bitfield", ) +go_repository( + name = "org_golang_x_net", + commit = "da137c7871d730100384dbcf36e6f8fa493aef5b", + importpath = "golang.org/x/net", +) + +go_repository( + name = "org_golang_x_sys", + commit = "fae7ac547cb717d141c433a2a173315e216b64c4", + importpath = "golang.org/x/sys", +) + go_repository( name = "com_github_pborman_uuid", commit = "8b1b92947f46224e3b97bb1a3a5b0382be00d31e", # v1.2.0 diff --git a/eth1/deposits.go b/eth1/deposits.go index f969a7a..2f8021d 100644 --- a/eth1/deposits.go +++ b/eth1/deposits.go @@ -32,6 +32,11 @@ type ForkData struct { GenesisValidatorsRoot [32]byte } +type SigningRoot struct { + ObjectRoot [32]byte + Domain [32]byte +} + // CreateDepositData takes in raw private key bytes and a deposit amount and generates // the proper DepositData Eth2 struct type. This involves BLS signing the deposit, // generating hashed withdrawal credentials, and including the public key from the validator's @@ -55,12 +60,19 @@ func CreateDepositData(validatorKey []byte, withdrawalKey []byte, amountInGwei u if err != nil { return nil, err } - d, err := domain() if err != nil { return nil, err } - di.Signature = sk1.Sign(sr[:], d).Marshal() + rt, err := ssz.HashTreeRoot(&SigningRoot{ + ObjectRoot: sr, + Domain: d, + }) + if err != nil { + return nil, err + } + + di.Signature = sk1.Sign(rt[:]).Marshal() return di, nil } @@ -76,16 +88,16 @@ func withdrawalCredentialsHash(withdrawalKey *bls.SecretKey) []byte { return append([]byte{blsWithdrawalPrefixByte}, h[0:]...)[:32] } -func domain() ([]byte, error) { +func domain() ([32]byte, error) { root, err := ssz.HashTreeRoot(&ForkData{ CurrentVersion: genesisForkVersion, GenesisValidatorsRoot: zerohash, }) if err != nil { - return []byte{}, err + return [32]byte{}, err } - b := []byte{} - b = append(b, domainDeposit[:4]...) - b = append(b, root[:28]...) + b := [32]byte{} + copy(b[:], domainDeposit[:4]) + copy(b[4:], root[:28]) return b, nil } From 4fc6670e89dceb6c76231316b0f3c6effb39c8a6 Mon Sep 17 00:00:00 2001 From: nisdas Date: Fri, 27 Mar 2020 11:17:11 +0800 Subject: [PATCH 3/3] add protobuf dep --- WORKSPACE | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/WORKSPACE b/WORKSPACE index 4d3a2f0..c31317a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -72,6 +72,15 @@ load("@com_github_atlassian_bazel_tools//gometalinter:deps.bzl", "gometalinter_d gometalinter_dependencies() +git_repository( + name = "com_google_protobuf", + commit = "4cf5bfee9546101d98754d23ff378ff718ba8438", + remote = "https://github.com/protocolbuffers/protobuf", + shallow_since = "1558721209 -0700", +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + load( "@io_bazel_rules_docker//go:image.bzl", _go_image_repos = "repositories",