From 4f2d98408195b2083e348d39061855dc3adc75d1 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 25 Jul 2018 11:05:27 -0400 Subject: [PATCH] fix using only_owner --- lib/modules/ens/contracts/ENSRegistry.sol | 2 +- lib/modules/ens/contracts/FIFSRegistrar.sol | 12 ++---------- lib/modules/ens/contracts/Resolver.sol | 15 ++++----------- lib/modules/ens/index.js | 9 +++++---- lib/utils/utils.js | 6 ++++++ 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/lib/modules/ens/contracts/ENSRegistry.sol b/lib/modules/ens/contracts/ENSRegistry.sol index 712350858..37917c81f 100644 --- a/lib/modules/ens/contracts/ENSRegistry.sol +++ b/lib/modules/ens/contracts/ENSRegistry.sol @@ -54,7 +54,7 @@ contract ENSRegistry is ENS { * @param node The node to update. * @param resolver The address of the resolver. */ - function setResolver(bytes32 node, address resolver) public { + function setResolver(bytes32 node, address resolver) public only_owner(node, 0x0) { NewResolver(node, resolver); records[node].resolver = resolver; } diff --git a/lib/modules/ens/contracts/FIFSRegistrar.sol b/lib/modules/ens/contracts/FIFSRegistrar.sol index ce9d7d2f1..d1d4924ad 100644 --- a/lib/modules/ens/contracts/FIFSRegistrar.sol +++ b/lib/modules/ens/contracts/FIFSRegistrar.sol @@ -9,7 +9,6 @@ import './Resolver.sol'; contract FIFSRegistrar { ENS ens; bytes32 rootNode; - Resolver resolver; modifier only_owner(bytes32 subnode) { bytes32 node = sha3(rootNode, subnode); @@ -23,10 +22,9 @@ contract FIFSRegistrar { * @param ensAddr The address of the ENS registry. * @param node The node that this registrar administers. */ - function FIFSRegistrar(ENS ensAddr, bytes32 node, Resolver resolverAddr) public { + function FIFSRegistrar(ENS ensAddr, bytes32 node) public { ens = ensAddr; rootNode = node; - resolver = resolverAddr; } /** @@ -34,13 +32,7 @@ contract FIFSRegistrar { * @param subnode The hash of the label to register. * @param owner The address of the new owner. */ - function register(bytes32 subnode, address owner, address nodeAddress) public only_owner(subnode) { - bytes32 subdomainHash = sha3(rootNode, subnode); + function register(bytes32 subnode, address owner) public only_owner(subnode) { ens.setSubnodeOwner(rootNode, subnode, owner); - ens.setResolver(subdomainHash, resolver); //default resolver - bool resolveAccount = nodeAddress != address(0); - if (resolveAccount) { - resolver.setAddr(subdomainHash, nodeAddress); - } } } diff --git a/lib/modules/ens/contracts/Resolver.sol b/lib/modules/ens/contracts/Resolver.sol index 59162b422..1d339cbd8 100644 --- a/lib/modules/ens/contracts/Resolver.sol +++ b/lib/modules/ens/contracts/Resolver.sol @@ -33,7 +33,8 @@ contract Resolver { mapping (bytes32 => Record) records; modifier only_owner(bytes32 node) { - require(ens.owner(node) == msg.sender); + address currentOwner = ens.owner(node); + require(currentOwner == 0 || currentOwner == msg.sender); _; } @@ -51,11 +52,7 @@ contract Resolver { * @param node The node to update. * @param addr The address to set. */ -// function setAddr(bytes32 node, address addr) public only_owner(node) { -// records[node].addr = addr; -// emit AddrChanged(node, addr); -// } - function setAddr(bytes32 node, address addr) public { + function setAddr(bytes32 node, address addr) public only_owner(node) { records[node].addr = addr; emit AddrChanged(node, addr); } @@ -79,11 +76,7 @@ contract Resolver { * @param node The node to update. * @param name The name to set. */ -// function setName(bytes32 node, string name) public only_owner(node) { -// records[node].name = name; -// emit NameChanged(node, name); -// } - function setName(bytes32 node, string name) public { + function setName(bytes32 node, string name) public only_owner(node) { records[node].name = name; emit NameChanged(node, name); } diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 45efc8c61..38579f887 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -11,6 +11,7 @@ class ENS { this.registration = this.namesConfig.register; this.embark = embark; + // TODO add checks to see if config is ok this.addENSToEmbarkJS(); this.configureContracts(); this.registerEvents(); @@ -38,6 +39,7 @@ class ENS { ], (err, results) => { // result[0] => ENSRegistry; result[1] => FIFSRegistrar; result[2] => FIFSRegistrar let config = { + registration: self.registration, registryAbi: results[0].abiDefinition, registryAddress: results[0].deployedAddress, registrarAbi: results[1].abiDefinition, @@ -62,8 +64,7 @@ class ENS { {abi: config.registrarAbi, address: config.registrarAddress}, (registrar) => { async.each(Object.keys(self.registration.domains), (subDomainName, eachCb) => { - const toSend = registrar.methods.register(utils.sha3(subDomainName), - defaultAccount, self.registration.domains[subDomainName]); + const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount); toSend.estimateGas().then(gasEstimated => { return toSend.send({gas: gasEstimated + 1000, from: defaultAccount}).then(transaction => { @@ -127,11 +128,11 @@ class ENS { }, "FIFSRegistrar": { "deploy": true, - "args": ["$ENSRegistry", rootNode, "$Resolver"], + "args": ["$ENSRegistry", rootNode], "onDeploy": [ `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => { ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send(); - var reverseNode = web3.utils.sha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse'); + var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse'); ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send(); Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send(); Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send(); diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 793b9e6ff..b84cbdf64 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -270,6 +270,11 @@ function sha3(arg) { return Web3.utils.sha3(arg); } +function soliditySha3(arg) { + const Web3 = require('web3'); + return Web3.utils.soliditySha3(arg); +} + function normalizeInput(input) { let args = Object.values(input); if (args.length === 0) { @@ -405,6 +410,7 @@ module.exports = { getExternalContractUrl, toChecksumAddress, sha3, + soliditySha3, normalizeInput, buildUrl, buildUrlFromConfig,