Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #47 from prysmaticlabs/fixDomain
Browse files Browse the repository at this point in the history
Update Mock RPC
  • Loading branch information
rauljordan authored Mar 27, 2020
2 parents 8652fbd + 4fc6670 commit 609dda3
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 14 deletions.
79 changes: 68 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -55,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",
Expand Down Expand Up @@ -114,7 +140,7 @@ go_repository(

go_repository(
name = "com_github_prysmaticlabs_prysm",
commit = "5e939378d0c83c074bfed6ecaba5b505074a7a01",
commit = "ec2a100ba992c1a61d66c605c867d0da9777d741",
importpath = "github.com/prysmaticlabs/prysm",
)

Expand All @@ -125,9 +151,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(
Expand All @@ -136,6 +181,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
Expand Down
41 changes: 38 additions & 3 deletions eth1/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
)
Expand All @@ -26,6 +27,16 @@ type DepositData struct {
Signature []byte `json:"signature,omitempty" ssz-size:"96"`
}

type ForkData struct {
CurrentVersion [4]byte
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
Expand All @@ -49,9 +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
}
rt, err := ssz.HashTreeRoot(&SigningRoot{
ObjectRoot: sr,
Domain: d,
})
if err != nil {
return nil, err
}

domain := bls.Domain(domainDeposit[:], genesisForkVersion)
di.Signature = sk1.Sign(sr[:], domain).Marshal()
di.Signature = sk1.Sign(rt[:]).Marshal()
return di, nil
}

Expand All @@ -66,3 +87,17 @@ func withdrawalCredentialsHash(withdrawalKey *bls.SecretKey) []byte {
h := hashutil.HashKeccak256(withdrawalKey.PublicKey().Marshal())
return append([]byte{blsWithdrawalPrefixByte}, h[0:]...)[:32]
}

func domain() ([32]byte, error) {
root, err := ssz.HashTreeRoot(&ForkData{
CurrentVersion: genesisForkVersion,
GenesisValidatorsRoot: zerohash,
})
if err != nil {
return [32]byte{}, err
}
b := [32]byte{}
copy(b[:], domainDeposit[:4])
copy(b[4:], root[:28])
return b, nil
}

0 comments on commit 609dda3

Please sign in to comment.