Skip to content

Commit

Permalink
fix: namehash from bytesutils
Browse files Browse the repository at this point in the history
  • Loading branch information
pikonha committed Oct 9, 2024
1 parent ad4c037 commit 659db12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
5 changes: 3 additions & 2 deletions packages/client/src/l2.write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const _ = (async () => {
}

const name = normalize('gibi.arb.eth')
const dnsName = toHex(packetToBytes(name))
const node = namehash(name)
const signer = privateKeyToAccount(privateKey as Hex)

Expand All @@ -68,7 +69,7 @@ const _ = (async () => {
address: universalResolver as Hex,
functionName: 'findResolver',
abi: uAbi,
args: [toHex(packetToBytes(name))],
args: [dnsName],
})) as Hash[]

const duration = 31556952000n
Expand Down Expand Up @@ -107,7 +108,7 @@ const _ = (async () => {
functionName: 'register',
abi: l1Abi,
args: [
toHex(name), // name
dnsName, // name
signer.address, // owner
duration,
`0x${'a'.repeat(64)}` as Hex, // secret
Expand Down
26 changes: 1 addition & 25 deletions packages/contracts/src/SubdomainController.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "forge-std/console.sol";

import {INameWrapper} from "@ens-contracts/wrapper/INameWrapper.sol";
import {Resolver} from "@ens-contracts/resolvers/Resolver.sol";
import {BytesUtils} from "@ens-contracts/utils/BytesUtils.sol";
Expand Down Expand Up @@ -43,7 +41,7 @@ contract SubdomainController is OffchainRegister, ENSHelper {
payable
override
{
bytes32 node = _getNode(name);
bytes32 node = name.namehash(0);
string memory label = _getLabel(name);

(, uint256 offset) = name.readLabel(0);
Expand All @@ -64,28 +62,6 @@ contract SubdomainController is OffchainRegister, ENSHelper {
}
}

function _getNode(bytes memory name) private pure returns (bytes32 node) {
return _getNode(name, 0);
}

function _getNode(
bytes memory name,
uint256 offset
)
private
pure
returns (bytes32 node)
{
uint256 len = name.readUint8(offset);
node = bytes32(0);
if (len > 0) {
bytes32 label = name.keccak(offset + 1, len);
bytes32 parentNode = _getNode(name, offset + len + 1);
node = keccak256(abi.encodePacked(parentNode, label));
}
return node;
}

function _getLabel(bytes calldata name)
private
pure
Expand Down

0 comments on commit 659db12

Please sign in to comment.