Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
contract/ens: use new ens contract address 0x00000000000C2E074eC69A0d…
Browse files Browse the repository at this point in the history
…Fb2997BA6C7d2e1e (#2091)

use new contract addresses due to a resolver security vulnerability discovered on the ENS contract code
  • Loading branch information
janos authored Feb 7, 2020
1 parent 7f513a6 commit d13fcbe
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 44 deletions.
2 changes: 1 addition & 1 deletion api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewConfig() *Config {
SwapLogPath: "",
HiveParams: network.NewHiveParams(),
Pss: pss.NewParams(),
EnsRoot: ens.TestNetAddress,
EnsRoot: ens.Address,
EnsAPIs: nil,
RnsAPI: "",
Path: node.DefaultDataDir(),
Expand Down
3 changes: 1 addition & 2 deletions contracts/ens/ens.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import (
)

var (
MainNetAddress = common.HexToAddress("0x314159265dD8dbb310642f98f50C066173C1259b")
TestNetAddress = common.HexToAddress("0x112234455c3a32fd11230c42e7bccd4a84e02010")
Address = common.HexToAddress("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e")
contentHash_Interface_Id [4]byte
)

Expand Down
42 changes: 1 addition & 41 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ package swarm

import (
"bytes"
"context"
"crypto/ecdsa"
"errors"
"fmt"
"io"
"math/big"
"net"
"net/http"
"path/filepath"
Expand All @@ -37,7 +35,6 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethersphere/swarm/api"
httpapi "github.com/ethersphere/swarm/api/http"
Expand Down Expand Up @@ -338,12 +335,7 @@ func newEnsClient(endpoint string, addr common.Address, config *api.Config, priv
if addr != (common.Address{}) {
ensRoot = addr
} else {
a, err := detectEnsAddr(client)
if err == nil {
ensRoot = a
} else {
log.Warn(fmt.Sprintf("could not determine ENS contract address, using default %s", ensRoot), "err", err)
}
ensRoot = ens.Address
}
transactOpts := bind.NewKeyedTransactor(privkey)
dns, err := ens.NewENS(transactOpts, ensRoot, ethClient)
Expand All @@ -357,38 +349,6 @@ func newEnsClient(endpoint string, addr common.Address, config *api.Config, priv
}, err
}

// detectEnsAddr determines the ENS contract address by getting both the
// version and genesis hash using the client and matching them to either
// mainnet or testnet addresses
func detectEnsAddr(client *rpc.Client) (common.Address, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

var version string
if err := client.CallContext(ctx, &version, "net_version"); err != nil {
return common.Address{}, err
}

block, err := ethclient.NewClient(client).BlockByNumber(ctx, big.NewInt(0))
if err != nil {
return common.Address{}, err
}

switch {

case version == "1" && block.Hash() == params.MainnetGenesisHash:
log.Info("using Mainnet ENS contract address", "addr", ens.MainNetAddress)
return ens.MainNetAddress, nil

case version == "3" && block.Hash() == params.TestnetGenesisHash:
log.Info("using Testnet ENS contract address", "addr", ens.TestNetAddress)
return ens.TestNetAddress, nil

default:
return common.Address{}, fmt.Errorf("unknown version and genesis hash: %s %s", version, block.Hash())
}
}

/*
Start is called when the stack is started
* starts the network kademlia hive peer management
Expand Down

0 comments on commit d13fcbe

Please sign in to comment.