Skip to content

Commit

Permalink
Merge pull request #7 from Consensys/feat/limit-to-id-resolution
Browse files Browse the repository at this point in the history
feat: only accept numbers as the label for resolution + new deployments
  • Loading branch information
Julink-eth authored Sep 2, 2024
2 parents bcc44c7 + b2db86e commit 1595d5e
Show file tree
Hide file tree
Showing 20 changed files with 194,116 additions and 1,319,765 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For example for `efrogs.eth`, the DNS encoded name is `0x066566726f6773036574680
2 - Get the target NFT contract you want to use to resolve the subdomains depending on the NFT's owner addresses.
For example: [0x194395587d7b169e63eaf251e86b1892fa8f1960](https://lineascan.build/address/0x194395587d7b169e63eaf251e86b1892fa8f1960)

3 - Go to the [NFT resolver contract](https://etherscan.io/address/0xe34e08c30ba5577da7b65a79dc9741bbc59e4dfa#writeContract)
3 - Go to the [NFT resolver contract](https://etherscan.io/address/0xed24dDCB660c83803126DAAbFAfCE3b114936C58#writeContract)

4 - Click on `Connect to Web3`with the wallet that owns the chosen ENS name (Example `efrogs.eth`)

Expand All @@ -33,7 +33,7 @@ target: [NFT contrac address on Linea] (Example `0x194395587d7b169e63eaf251e86b1

11 - Click on `Custom Resolver`

12 - Add the NFT Resolver's address: `0xe34e08c30bA5577Da7B65a79dC9741BBc59E4Dfa`
12 - Add the NFT Resolver's address: `0xed24dDCB660c83803126DAAbFAfCE3b114936C58`

13 - Click on `Update`, `Open Wallet`and approve the transaction.

Expand Down
36 changes: 36 additions & 0 deletions contracts/LabelUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,40 @@ library LabelUtils {
require(hasNumber, "No numeric suffix found");
return num;
}

/**
* Check if the bytes param is a number or not
* @param input bytes to check
* @return true if number, false otherwise
*/
function isNumber(bytes memory input) public pure returns (bool) {
for (uint i = 0; i < input.length; i++) {
// Check if each byte is within the ASCII range for '0' to '9'
if (input[i] < 0x30 || input[i] > 0x39) {
return false;
}
}
return true;
}

/**
* Counts the number of labels in the DNS encoded input given
* @param input the DNS encoded input to count from
* @return number labels found
*/
function countLabels(bytes memory input) public pure returns (uint) {
uint count = 0;
uint i = 0;

while (i < input.length) {
uint labelLength = uint(uint8(input[i]));
if (labelLength == 0) {
break; // End of the DNS name
}
count++;
i += labelLength + 1;
}

return count;
}
}
5 changes: 5 additions & 0 deletions contracts/NFTResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ contract NFTResolver is
return _resolve(name, data);
}

// Only accept 1 level subdomain
require(LabelUtils.countLabels(name) <= 3, "Too many subdomain levels");

(, address target) = _getTarget(name, 0);

bytes4 selector = bytes4(data);
Expand All @@ -181,6 +184,8 @@ contract NFTResolver is
*/
function extractNFTId(bytes calldata name) public pure returns (uint256) {
bytes memory firstLabel = LabelUtils.extractFirstLabel(name);
// Only accept numbers as the label
require(LabelUtils.isNumber(firstLabel), "Label is not a number");
return LabelUtils.extractNumericSuffix(firstLabel);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../build-info/b2e8ce1ffa5fe8a5a8091ecc939c1bee.json"
"buildInfo": "../build-info/b81f40333ccc4acb691c7be2c38e0dd4.json"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../build-info/b2e8ce1ffa5fe8a5a8091ecc939c1bee.json"
"buildInfo": "../build-info/b81f40333ccc4acb691c7be2c38e0dd4.json"
}

Large diffs are not rendered by default.

659,863 changes: 0 additions & 659,863 deletions ignition/deployments/chain-1/build-info/b2e8ce1ffa5fe8a5a8091ecc939c1bee.json

This file was deleted.

96,947 changes: 96,947 additions & 0 deletions ignition/deployments/chain-1/build-info/b81f40333ccc4acb691c7be2c38e0dd4.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ignition/deployments/chain-1/deployed_addresses.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"NFTResolverModule#LabelUtils": "0xee6224339D9De75f1C4b45d70512789e0Da88dc4",
"NFTResolverModule#NFTResolver": "0xe34e08c30bA5577Da7B65a79dC9741BBc59E4Dfa"
"NFTResolverModule#LabelUtils": "0xC5E62F762a0844af52A7E126E111F2aA0087f3b1",
"NFTResolverModule#NFTResolver": "0xed24dDCB660c83803126DAAbFAfCE3b114936C58"
}
18 changes: 9 additions & 9 deletions ignition/deployments/chain-1/journal.jsonl

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../build-info/b2e8ce1ffa5fe8a5a8091ecc939c1bee.json"
"buildInfo": "../build-info/b81f40333ccc4acb691c7be2c38e0dd4.json"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../build-info/b2e8ce1ffa5fe8a5a8091ecc939c1bee.json"
"buildInfo": "../build-info/b81f40333ccc4acb691c7be2c38e0dd4.json"
}

Large diffs are not rendered by default.

659,863 changes: 0 additions & 659,863 deletions ignition/deployments/chain-11155111/build-info/b2e8ce1ffa5fe8a5a8091ecc939c1bee.json

This file was deleted.

Loading

0 comments on commit 1595d5e

Please sign in to comment.