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

Mainnet-v1.0.0: 0x839B3B540A9572448FD1B2335e0EB09Ac1A02885 #50

Merged
merged 43 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c5d6a7a
README update
sshmatrix Jul 18, 2023
c827465
Purge masterhash()
sshmatrix Jul 18, 2023
cc20ffe
README.md update
sshmatrix Jul 19, 2023
e61e9f7
README.md update: 2
sshmatrix Jul 19, 2023
5e2eae6
Reinstate signedRedirect() & ownerhash[]
sshmatrix Jul 19, 2023
ea7b34f
Merge branch 'main' into sshmatrix
sshmatrix Jul 19, 2023
c03c0b6
some more NatSpec
sshmatrix Jul 19, 2023
755925f
Goerli-v4: 0x4b9A4521442485ad7e1b25295125240b5f3F5aaC
sshmatrix Jul 19, 2023
f3b1404
Remove redundant parts; more natSpec
sshmatrix Jul 19, 2023
66511e0
Merge branch 'main' into sshmatrix
sshmatrix Jul 19, 2023
26387ca
update ownerhash[addr] to accept keccak(addr)
sshmatrix Jul 19, 2023
4c6274f
Merge branch 'main' into sshmatrix
sshmatrix Jul 19, 2023
6d747a2
natSpec for GatewayManager
sshmatrix Jul 19, 2023
6a5526a
Mainnet: 0x57532d78FfBcC6ac5534A9b39899C7eC89082CdA
sshmatrix Jul 23, 2023
da31ea1
Merge branch 'main' into sshmatrix
sshmatrix Jul 23, 2023
e74ded2
Fixes for bugs in v1-beta
sshmatrix Jul 26, 2023
b8cb9f9
Fixes for bugs in v1-beta (#34)
sshmatrix Jul 26, 2023
41d4fc5
Some natSpec and fix for avatar/contenthash
sshmatrix Jul 31, 2023
86227e3
Updated Fixes in v1.0.0-beta (#36)
sshmatrix Jul 31, 2023
6f55ddc
Fix error in test.yml
sshmatrix Aug 1, 2023
e8d969e
Merge branch 'sshmatrix' into play
sshmatrix Aug 1, 2023
125bad4
Fix errors in test.yml (#38)
sshmatrix Aug 1, 2023
971afa6
Review of #40
sshmatrix Aug 14, 2023
8b4df64
Merge Review for #40 from 'play' to 'sshmatrix'
sshmatrix Aug 14, 2023
fdc3718
Merge branch 'main' into sshmatrix
sshmatrix Aug 14, 2023
24e960c
Fix typo-2
sshmatrix Aug 14, 2023
811b755
Merge branch 'main' into sshmatrix
sshmatrix Aug 14, 2023
cf762c6
Re-try merge (#43)
sshmatrix Aug 14, 2023
1d9e3db
Typo-2
sshmatrix Aug 14, 2023
c43c97c
Typo-2.1
sshmatrix Aug 14, 2023
319596d
Typo-2.2
sshmatrix Aug 14, 2023
acc417d
Get ChainID from ENV
sshmatrix Aug 15, 2023
76cfa55
rSync
sshmatrix Aug 15, 2023
a869852
getRecordhash() fix
sshmatrix Aug 15, 2023
00f5a7b
Merge branch 'main' into sshmatrix
sshmatrix Aug 15, 2023
f3a968b
Tests for wrapped names
sshmatrix Aug 15, 2023
a45b145
Testnet Wrapper set
sshmatrix Aug 15, 2023
893c10b
Merge branch 'main' into sshmatrix
sshmatrix Aug 15, 2023
1a13630
Fix stale bytes12(0): 2
sshmatrix Aug 16, 2023
81e4dc3
Goerli-v7: 0x7b1c58d69a62d5f740D8CA069A6D903B6c414fE2
sshmatrix Aug 19, 2023
b9cda60
Mainnet v1.0.0: 0x839B3B540A9572448FD1B2335e0EB09Ac1A02885
sshmatrix Aug 20, 2023
02d1713
Merge branch 'main' into sshmatrix
sshmatrix Aug 21, 2023
12fc7e3
rSync: 2
sshmatrix Aug 21, 2023
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
2 changes: 1 addition & 1 deletion script/verify.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
source .env && forge verify-contract --chain-id 5 --etherscan-api-key $ETHERSCAN_KEY 0xa859E4c7668E13b606B108dcA4fF9E79950d79d2 src/CCIP2ETH.sol:CCIP2ETH
source .env && forge verify-contract --chain-id 1 --etherscan-api-key $ETHERSCAN_KEY 0x9d79FF2EC00b812E32D9768d88782101cB08D875 src/GatewayManager.sol:GatewayManager
17 changes: 6 additions & 11 deletions src/CCIP2ETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ contract CCIP2ETH is iCCIP2ETH {
/// @dev - Constructor
constructor(address _gateway) {
gateway = iGatewayManager(_gateway);
chainID = block.chainid == 1 ? "1" : "5"; // mainnet or goerli
chainID = block.chainid == 1 ? "1" : "5"; // Set ChainID
/// @dev - Sets ENS Mainnet wrapper as Wrapper
isWrapper[0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401] = true;
emit UpdatedWrapper(0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401, true);

/// @dev - Sets ENS TESTNET wrapper contract
/// @TODO - [!!!] REMOVE FOR MAINNET
isWrapper[0x114D4603199df73e7D157787f8778E21fCd13066] = true;
emit UpdatedWrapper(0x114D4603199df73e7D157787f8778E21fCd13066, true);

/// @dev - Set necessary interfaces
supportsInterface[iERC165.supportsInterface.selector] = true;
supportsInterface[iENSIP10.resolve.selector] = true;
Expand All @@ -88,7 +83,7 @@ contract CCIP2ETH is iCCIP2ETH {
* @return _recordhash - IPNS contenthash that is set as recordhash
*/
function getRecordhash(bytes32 _node) external view returns (bytes memory _recordhash) {
_recordhash = recordhash[_node]; // > Fix here
_recordhash = recordhash[_node];
if (_recordhash.length == 0) {
address _owner = ENS.owner(_node);
if (isWrapper[_owner]) {
Expand Down Expand Up @@ -308,8 +303,8 @@ contract CCIP2ETH is iCCIP2ETH {
if (isWrapper[_owner]) {
_owner = iToken(_owner).ownerOf(uint256(_node));
}
/// @dev - Timeout in 4 blocks
if (block.number > _blocknumber + 5) {
/// @dev - Timeout in 6 blocks
if (block.number > _blocknumber + 7) {
revert InvalidRequest("BLOCK_TIMEOUT");
}
/// @dev - Verify checkhash
Expand Down Expand Up @@ -371,7 +366,7 @@ contract CCIP2ETH is iCCIP2ETH {
"Requesting Signature To Install dApp Service\n",
"\nOrigin: ",
_domain, // e.g. ens.domain.eth
"\nDApp: ",
"\nApp: ",
_redirectDomain, // e.g. app.ens.eth
"\nExtradata: 0x",
gateway.bytesToHexString(abi.encodePacked(keccak256(result)), 0),
Expand Down Expand Up @@ -557,7 +552,7 @@ contract CCIP2ETH is iCCIP2ETH {

/// @dev : Management functions

/// @dev : Checks for admin privileges
/// @dev - Checks for admin privileges
modifier OnlyDev() {
if (msg.sender != gateway.owner()) {
revert NotAuthorised("NOT_DEV");
Expand Down
65 changes: 34 additions & 31 deletions src/GatewayManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import "./Interface.sol";
*/
contract GatewayManager is iERC173, iGatewayManager {
/// @dev - Events
event Web3GatewayUpdated(string indexed domain);
event Web3GatewayRemoved(string indexed domain);
event Web3GatewayUpdated(string indexed _domain);
event Web3GatewayRemoved(string indexed _domain);
event Web2GatewayUpdated(string indexed _domain);
event Web2GatewayRemoved(string indexed _domain);
event FuncMapUpdated(bytes4 _func, string _name);
event Web2GatewayUpdated(string indexed domain);
event Web2GatewayRemoved(string indexed domain);
/// @dev - Errors

/// @dev - Errors
error ContenthashNotImplemented(bytes1 _type);
error InvalidRequest(string _message);
error FeatureNotImplemented(bytes4 func);
Expand All @@ -37,9 +37,8 @@ contract GatewayManager is iERC173, iGatewayManager {
string public PrimaryGateway = "ipfs2.eth.limo";
/// @dev - List of secondary gateway domains (default)
string[] public Web3Gateways;
/// @dev - List of web2/L2 service gateway domains (fallback)
/// @dev - List of web2 or L2 service gateway domains (fallback)
string[] public Web2Gateways;

/// @dev - Resolver function bytes4 selector → Off-chain record filename <name>.json
mapping(bytes4 => string) public funcMap;

Expand All @@ -58,7 +57,6 @@ contract GatewayManager is iERC173, iGatewayManager {
emit Web3GatewayUpdated("dweb.link");
Web3Gateways.push("ipfs.io");
emit Web3GatewayUpdated("ipfs.io");

Web2Gateways.push("ccip.namesys.xyz");
emit Web2GatewayUpdated("ccip.namesys.xyz");
}
Expand All @@ -76,9 +74,9 @@ contract GatewayManager is iERC173, iGatewayManager {
view
returns (string[] memory gateways)
{
/// @dev Filter recordhash vs. web2 gateway
/// @dev Filter IPNS versus Web2 gateway
if (_recordhash.length == 0) {
// Default L2/Web2 service fallback
/// Default L2 or web2 Service fallback
uint256 gateLen = Web2Gateways.length;
gateways = new string[](gateLen);
while (gateLen > 0) {
Expand All @@ -87,19 +85,19 @@ contract GatewayManager is iERC173, iGatewayManager {
}
return gateways;
} else if (_recordhash[0] == bytes1("h") && iGatewayManager(this).isWeb2(_recordhash)) {
// Web2 set by owner
/// Trusted web2 gateway set by the owner
gateways = new string[](1);
gateways[0] = string.concat(string(_recordhash), _path, ".json?t={data}");
return gateways;
} else if (_recordhash.length == 32) {
// Short IPNS hash
/// Short IPNS hash set by owner
_recordhash = abi.encodePacked(hex"e5010172002408011220", _recordhash);
}
unchecked {
uint256 gLen = Web3Gateways.length;
uint256 len = (gLen / 2) + 2;
if (len > 3) len = 3;
gateways = new string[](len+1);
gateways = new string[](len + 1);
uint256 i;
if (bytes(PrimaryGateway).length > 0) {
gateways[i++] = string.concat(
Expand Down Expand Up @@ -135,7 +133,7 @@ contract GatewayManager is iERC173, iGatewayManager {
seed = uint256(keccak256(abi.encodePacked(block.number * i, seed)));
gateways[i++] = string.concat("https://", Web3Gateways[seed % gLen], _fullPath);
}
gateways[len] = string.concat("https://", Web2Gateways[0], _fullPath); // fallback,
gateways[len] = string.concat("https://", Web2Gateways[0], _fullPath); // Fallback
}
}

Expand Down Expand Up @@ -304,46 +302,48 @@ contract GatewayManager is iERC173, iGatewayManager {

/**
* @dev Shows list of web3 gateways
* @return List of gateways
* @return - List of web3 gateways
*/
function listWeb3Gateways() external view returns (string[] memory) {
return Web3Gateways;
}

/**
* @dev Add a single gateway
* @param _domain - New gateway domain to add
* @dev Add a single web3 gateway
* @param _domain - New web3 gateway domain to add
*/
function addWeb3Gateway(string calldata _domain) external onlyDev {
Web3Gateways.push(_domain);
emit Web3GatewayUpdated(_domain);
}

/**
* @dev Remove a single gateway
* @dev Remove a single web3 gateway
* @param _index - Gateway index to remove
*/
function removeWeb3Gateway(uint256 _index) external onlyDev {
require(Web3Gateways.length > 1, "Last Gateway");
emit Web3GatewayRemoved(Web3Gateways[_index]);
Web3Gateways[_index] = Web3Gateways[Web3Gateways.length - 1];
if (Web3Gateways.length == 1) {
revert InvalidRequest("LAST_GATEWAY");
}
emit Web3GatewayRemoved(Web3Gateways[_index]); // Emit first
Web3Gateways[_index] = Web3Gateways[Web3Gateways.length - 1]; // Update later
Web3Gateways.pop();
}

/**
* @dev Replace a single gateway
* @dev Replace a single web3 gateway
* @param _index : Gateway index to replace
* @param _domain : New gateway domain.tld
*/
function replaceWeb3Gateway(uint256 _index, string calldata _domain) external onlyDev {
emit Web3GatewayRemoved(Web3Gateways[_index]);
Web3Gateways[_index] = _domain;
emit Web3GatewayRemoved(Web3Gateways[_index]); // Emit first
Web3Gateways[_index] = _domain; // Update later
emit Web3GatewayUpdated(_domain);
}

/**
/**
* @dev Shows list of web2 gateways
* @return List of gateways
* @return - List of web2 gateways
*/
function listWeb2Gateways() external view returns (string[] memory) {
return Web2Gateways;
Expand All @@ -358,24 +358,27 @@ contract GatewayManager is iERC173, iGatewayManager {
emit Web2GatewayUpdated(_domain);
}
/**
* @dev Remove a single gateway
* @dev Remove a single web2 gateway
* @param _index - Gateway index to remove
*/

function removeWeb2Gateway(uint256 _index) external onlyDev {
require(Web2Gateways.length > 1, "Last Gateway");
if (Web2Gateways.length == 1) {
revert InvalidRequest("LAST_GATEWAY");
}
emit Web2GatewayRemoved(Web2Gateways[_index]);
Web2Gateways[_index] = Web2Gateways[Web2Gateways.length - 1];
Web2Gateways.pop();
}

/**
* @dev Replace a single gateway
* @dev Replace a single web2 gateway
* @param _index : Gateway index to replace
* @param _domain : New gateway domain.tld
*/
function replaceWeb2Gateway(uint256 _index, string calldata _domain) external onlyDev {
emit Web2GatewayRemoved(Web2Gateways[_index]);
Web2Gateways[_index] = _domain;
emit Web2GatewayRemoved(Web2Gateways[_index]); // Emit first
Web2Gateways[_index] = _domain; // Update later
emit Web2GatewayUpdated(_domain);
}

Expand Down
7 changes: 3 additions & 4 deletions src/Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,17 @@ interface iGatewayManager is iERC173 {
view
returns (bytes memory result);
function addFuncMap(bytes4 _func, string calldata _name) external;
function formatSubdomain(bytes calldata _recordhash) external pure returns (string memory result);
function isWeb2(bytes calldata _recordhash) external pure returns (bool);

function listWeb2Gateways() external view returns (string[] memory list);
function addWeb2Gateway(string calldata _domain) external;
function removeWeb2Gateway(uint256 _index) external;
function replaceWeb2Gateway(uint256 _index, string calldata _domain) external;

function listWeb3Gateways() external view returns (string[] memory list);
function addWeb3Gateway(string calldata _domain) external;
function removeWeb3Gateway(uint256 _index) external;
function replaceWeb3Gateway(uint256 _index, string calldata _domain) external;
function formatSubdomain(bytes calldata _recordhash) external pure returns (string memory result);
function isWeb2(bytes calldata _recordhash) external pure returns (bool);
//
}

interface iResolver {
Expand Down
2 changes: 0 additions & 2 deletions test/CCIP2ETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface xENS is iENS {
* Note Tests unwrapped/legacy domains
*/
contract CCIP2ETHTestLegacy is Test {
// using Surl for *;
error OffchainLookup(address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData);

address EOA = address(this);
Expand Down Expand Up @@ -500,7 +499,6 @@ contract CCIP2ETHTestLegacy is Test {
* Note Tests wrapped domains
*/
contract CCIP2ETHTestWrapped is Test {
// using Surl for *;
error OffchainLookup(address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData);

address EOA = address(this);
Expand Down
55 changes: 40 additions & 15 deletions test/GatewayManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,21 @@ contract GatewayManagerTest is Test {
assertEq(bStr, gateway.bytesToHexString(bBytes, 0));
}

/// @dev Test web2 gateways
function test6_Web2Gateways() public {
string[] memory gateways = gateway.listWeb2Gateways();
assertEq("ccip.namesys.xyz", gateways[0]);
assertEq(1, gateways.length);

vm.expectRevert("Last Gateway");
vm.expectRevert(abi.encodeWithSelector(GatewayManager.InvalidRequest.selector, "LAST_GATEWAY"));
gateway.removeWeb2Gateway(0);

gateway.addWeb2Gateway("ccip2.namesys.xyz");
gateways = gateway.listWeb2Gateways();
assertEq("ccip.namesys.xyz", gateways[0]);
assertEq("ccip2.namesys.xyz", gateways[1]);
assertEq(2, gateways.length);

gateway.replaceWeb2Gateway(1, "ccipx.namesys.xyz");
gateways = gateway.listWeb2Gateways();
assertEq("ccip.namesys.xyz", gateways[0]);
Expand All @@ -151,26 +152,25 @@ contract GatewayManagerTest is Test {
gateways = gateway.listWeb2Gateways();
assertEq("ccip.namesys.xyz", gateways[0]);
assertEq(1, gateways.length);

}


/// @dev Test web3 gateways
function test7_Web3Gateways() public {
string[] memory gateways = gateway.listWeb3Gateways();
assertEq("dweb.link", gateways[0]);
assertEq("ipfs.io", gateways[1]);
assertEq(2, gateways.length);

gateway.removeWeb3Gateway(0);
vm.expectRevert("Last Gateway");
vm.expectRevert(abi.encodeWithSelector(GatewayManager.InvalidRequest.selector, "LAST_GATEWAY"));
gateway.removeWeb3Gateway(0);

gateway.addWeb3Gateway("dweb.link");
gateways = gateway.listWeb3Gateways();
assertEq("dweb.link", gateways[1]);
assertEq("ipfs.io", gateways[0]);
assertEq(2, gateways.length);

gateway.replaceWeb3Gateway(0, "ipfs.namesys.xyz");
gateways = gateway.listWeb3Gateways();
assertEq("dweb.link", gateways[1]);
Expand All @@ -190,7 +190,8 @@ contract GatewayManagerTest is Test {
assertEq(1, gateways.length);
}

function test8_RandomGateway() public{
/// @dev Test a gateway
function test8_RandomGateway() public {
string memory _path = "/.well-known/eth/freetib/contenthash";
bytes memory _recordhash;
string[] memory gateways = gateway.randomGateways(_recordhash, _path, 0);
Expand All @@ -212,18 +213,42 @@ contract GatewayManagerTest is Test {
_recordhash = hex"3c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c";
gateways = gateway.randomGateways(_recordhash, _path, 0);
assertEq(4, gateways.length);
assertEq(gateways[0], "https://e5010172002408011220.3c5aba6c9b5055a5fa12281c486188ed.8ae2b6ef394b3d981b00d17a4b51735c.ipfs2.eth.limo/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(gateways[1], "https://dweb.link/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(gateways[2], "https://ipfs.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(gateways[3], "https://ccip.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(
gateways[0],
"https://e5010172002408011220.3c5aba6c9b5055a5fa12281c486188ed.8ae2b6ef394b3d981b00d17a4b51735c.ipfs2.eth.limo/.well-known/eth/freetib/contenthash.json?t={data}"
);
assertEq(
gateways[1],
"https://dweb.link/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}"
);
assertEq(
gateways[2],
"https://ipfs.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}"
);
assertEq(
gateways[3],
"https://ccip.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}"
);

_recordhash = hex"e50101720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c";
gateways = gateway.randomGateways(_recordhash, _path, 0);
assertEq(4, gateways.length);
assertEq(gateways[0], "https://e5010172002408011220.3c5aba6c9b5055a5fa12281c486188ed.8ae2b6ef394b3d981b00d17a4b51735c.ipfs2.eth.limo/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(gateways[1], "https://dweb.link/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(gateways[2], "https://ipfs.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(gateways[3], "https://ccip.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}");
assertEq(
gateways[0],
"https://e5010172002408011220.3c5aba6c9b5055a5fa12281c486188ed.8ae2b6ef394b3d981b00d17a4b51735c.ipfs2.eth.limo/.well-known/eth/freetib/contenthash.json?t={data}"
);
assertEq(
gateways[1],
"https://dweb.link/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}"
);
assertEq(
gateways[2],
"https://ipfs.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}"
);
assertEq(
gateways[3],
"https://ccip.namesys.xyz/ipns/f01720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c/.well-known/eth/freetib/contenthash.json?t={data}"
);
}
}

Expand Down