Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgradeable L2 Resolver #98

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
11eda3e
First pass at upgradeable L2 Resolver with EIP-7201 namespaced storage
stevieraykatz Oct 17, 2024
83dbacb
Move UpgradeableL2Resolver to dir
stevieraykatz Oct 17, 2024
f1e9a73
Migrate L2 Resolver tests to upgradeable
stevieraykatz Oct 24, 2024
fb6f8b9
ABI Resolver tests
stevieraykatz Nov 14, 2024
362ad95
Cleanup tests, add user-owned/managed node for resolver profile tests
stevieraykatz Nov 14, 2024
5a55934
Fix pragmas
stevieraykatz Nov 14, 2024
9f1cf35
lint
stevieraykatz Nov 14, 2024
359b3fb
Finish Addr Resolver + unit tests
stevieraykatz Nov 14, 2024
845f497
Add contenthash tests, natspec, add auth check to existing unit tests
stevieraykatz Nov 14, 2024
eb8760a
fix testfile name
stevieraykatz Nov 14, 2024
953172f
Cleanup DNSResolver, start tests for it
stevieraykatz Nov 15, 2024
4b12718
Cleanup natspec in InterfaceResolver, add unit tests
stevieraykatz Nov 15, 2024
8928c15
lint
stevieraykatz Nov 15, 2024
d9ce766
Name Resolver natspec and unit tests
stevieraykatz Nov 15, 2024
d54b4b4
Pubkey Resolver natspec and test
stevieraykatz Nov 15, 2024
09a52e9
Text resolver natspec and tests
stevieraykatz Nov 15, 2024
f344d26
lint
stevieraykatz Nov 15, 2024
21ceab2
Cleanup to UpgradeableL2Resolver natspec
stevieraykatz Nov 15, 2024
65c58a8
Finish DNS record tests
stevieraykatz Nov 15, 2024
90710d0
feat: add `notProxyAdmin` modifier for fuzz tests
abdulla-cb Nov 25, 2024
feb5e22
feat: add view methods for registrarController and reverseRegistrar
abdulla-cb Nov 25, 2024
00e3514
test: add additional cases
abdulla-cb Nov 26, 2024
d2c06eb
test: add tests for versionable resolver
abdulla-cb Nov 26, 2024
ff94866
test: setAddr reverts if invalid
abdulla-cb Nov 27, 2024
64ad9e1
test: add DNS records test
abdulla-cb Nov 27, 2024
c5145ae
chore: fix typo
abdulla-cb Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pubkey Resolver natspec and test
  • Loading branch information
stevieraykatz committed Nov 15, 2024
commit d54b4b473dcece360a25fc5353e3f89ce4647677
38 changes: 25 additions & 13 deletions src/L2/resolver/PubkeyResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,61 @@ import {IPubkeyResolver} from "ens-contracts/resolvers/profiles/IPubkeyResolver.

import {ResolverBase} from "./ResolverBase.sol";

/// @title Pubkey Resolver
///
/// @notice Adaptation of the ENS PubkeyResolver.sol profile contract, with EIP-7201 storage compliance.
/// https://github.com/ensdomains/ens-contracts/blob/staging/contracts/resolvers/profiles/PubkeyResolver.sol
///
/// @author Coinbase (https://github.com/base-org/basenames)
abstract contract PubkeyResolver is IPubkeyResolver, ResolverBase {
/// @notice Tuple containing the x and y coordinates of a public key.
struct PublicKey {
bytes32 x;
bytes32 y;
}

struct PubkeyResolverStorage {
/// @notice Public keys by node and version.
mapping(uint64 version => mapping(bytes32 node => PublicKey pubkey)) versionable_pubkeys;
}

/// @notice EIP-7201 storage location.
// keccak256(abi.encode(uint256(keccak256("pubkey.resolver.storage")) - 1)) & ~bytes32(uint256(0xff));
bytes32 constant PUBKEY_RESOLVER_STORAGE = 0x59a318c6a4da81295c2a32b42a02c3db057bb9422e2eb1f6e516ee3694b1ef00;
Dismissed Show dismissed Hide dismissed

/**
* Sets the SECP256k1 public key associated with an ENS node.
* @param node The ENS node to query
* @param x the X coordinate of the curve point for the public key.
* @param y the Y coordinate of the curve point for the public key.
*/
/// @notice Sets the SECP256k1 public key associated with an ENS node.
///
/// @param node The ENS node to query.
///
/// @param x the X coordinate of the curve point for the public key.
/// @param y the Y coordinate of the curve point for the public key.
function setPubkey(bytes32 node, bytes32 x, bytes32 y) external virtual authorised(node) {
_getPubkeyResolverStorage().versionable_pubkeys[_getResolverBaseStorage().recordVersions[node]][node] =
PublicKey(x, y);
emit PubkeyChanged(node, x, y);
}

/**
* Returns the SECP256k1 public key associated with an ENS node.
* Defined in EIP 619.
* @param node The ENS node to query
* @return x The X coordinate of the curve point for the public key.
* @return y The Y coordinate of the curve point for the public key.
*/
/// @notice Returns the SECP256k1 public key associated with an ENS node.
///
/// @dev See EIP-619.
///
/// @param node The ENS node to query.
///
/// @return x The X coordinate of the curve point for the public key.
/// @return y The Y coordinate of the curve point for the public key.
function pubkey(bytes32 node) external view virtual override returns (bytes32 x, bytes32 y) {
uint64 currentRecordVersion = _getResolverBaseStorage().recordVersions[node];
PubkeyResolverStorage storage $ = _getPubkeyResolverStorage();
return
($.versionable_pubkeys[currentRecordVersion][node].x, $.versionable_pubkeys[currentRecordVersion][node].y);
}

/// @notice ERC-165 compliance.
function supportsInterface(bytes4 interfaceID) public view virtual override returns (bool) {
return interfaceID == type(IPubkeyResolver).interfaceId || super.supportsInterface(interfaceID);
}

/// @notice EIP-7201 storage pointer fetch helper.
function _getPubkeyResolverStorage() internal pure returns (PubkeyResolverStorage storage $) {
assembly {
$.slot := PUBKEY_RESOLVER_STORAGE
Expand Down
4 changes: 2 additions & 2 deletions test/UpgradeableL2Resolver/SetName.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ contract SetName is UpgradeableL2ResolverBase {
vm.prank(notUser);
resolver.setName(node, name);
}

function test_setsTheName() public {
vm.prank(user);
resolver.setName(node, name);
string memory retName = resolver.name(node);
assertEq(keccak256(bytes(name)), keccak256(bytes(retName)));
}
}
}
25 changes: 25 additions & 0 deletions test/UpgradeableL2Resolver/SetPubkey.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {UpgradeableL2ResolverBase} from "./UpgradeableL2ResolverBase.t.sol";
import {ResolverBase} from "src/L2/resolver/ResolverBase.sol";
import {PubkeyResolver} from "src/L2/resolver/PubkeyResolver.sol";

contract SetPubkey is UpgradeableL2ResolverBase {
bytes32 x = 0x65a2fa44daad46eab0278703edb6c4dcf5e30b8a9aec09fdc71a56f52aa392e4;
bytes32 y = 0x4a7a9e4604aa36898209997288e902ac544a555e4b5e0a9efef2b59233f3f437;

function test_reverts_forUnauthorizedUser() public {
vm.expectRevert(abi.encodeWithSelector(ResolverBase.NotAuthorized.selector, node, notUser));
vm.prank(notUser);
resolver.setPubkey(node, x, y);
}

function test_setsThePubkey() public {
vm.prank(user);
resolver.setPubkey(node, x, y);
(bytes32 retX, bytes32 retY) = resolver.pubkey(node);
assertEq(retX, x);
assertEq(retY, y);
}
}
Loading