diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 37b7040..5f7cd12 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -10,9 +10,7 @@ contract CCIP2ETHDeploy is Script { function run() external { vm.startBroadcast(); GatewayManager manager = new GatewayManager(); - //uint256 ChainID = uint256(5); - //require(ChainID == uint256(1), "WARNING: Deploying with Goerli ChainID. Please double check [!]"); // Comment this for Goerli deploy - new CCIP2ETH(address(manager), "5"); + new CCIP2ETH(address(manager)); vm.stopBroadcast(); } } diff --git a/src/CCIP2ETH.sol b/src/CCIP2ETH.sol index be88b00..895def0 100644 --- a/src/CCIP2ETH.sol +++ b/src/CCIP2ETH.sol @@ -60,14 +60,15 @@ contract CCIP2ETH is iCCIP2ETH { mapping(bytes4 => bool) public supportsInterface; /// @dev - Constructor - constructor(address _gateway, string memory _chainID) { + constructor(address _gateway) { gateway = iGatewayManager(_gateway); - chainID = _chainID; + chainID = gateway.uintToString(block.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[0x0000000000000000000000000000000000000000] = true; emit UpdatedWrapper(0x0000000000000000000000000000000000000000, true); @@ -282,44 +283,6 @@ contract CCIP2ETH is iCCIP2ETH { iCCIP2ETH.__callback.selector, // Callback function abi.encode(_node, block.number - 1, _checkhash, _domain, _recType, _path, name, request) ); - if (_signer != iCCIP2ETH(this).getSigner(signRequest, _recordSignature)) { - revert InvalidRequest("BAD_SIGNED_RECORD"); - } - } else if (_type == iCallbackType.signedDAppService.selector) { - if (result[0] == 0x0 || result[result.length - 1] != 0x0) { - revert InvalidRequest("BAD_DAPP_SERVICE_REQUEST"); - } - (bytes4 _req, bytes32 _redirectNamehash, bytes memory _redirectRequest, string memory _redirectDomain) = - iCCIP2ETH(this).redirectService(result, _request); - signRequest = string.concat( - "Requesting Signature To Install DApp Service\n", - "\nOrigin: ", - _domain, // e.g. ens.domain.eth - "\nDApp: ", - _redirectDomain, // e.g. app.ens.eth - "\nExtradata: 0x", - gateway.bytesToHexString(abi.encodePacked(keccak256(result)), 0), - "\nSigned By: eip155:1:", - gateway.toChecksumAddress(_signer) - ); - if (_signer != iCCIP2ETH(this).getSigner(signRequest, _recordSignature)) { - revert InvalidRequest("BAD_DAPP_SIGNATURE"); - } - address _resolver = ENS.resolver(_redirectNamehash); - if (iERC165(_resolver).supportsInterface(iENSIP10.resolve.selector)) { - return iENSIP10(_resolver).resolve(result, _redirectRequest); - } else if (iERC165(_resolver).supportsInterface(_req)) { - bool ok; - (ok, result) = _resolver.staticcall(_redirectRequest); - if (!ok) { - revert InvalidRequest("BAD_RESOLVER"); - } - } else { - revert InvalidRequest("BAD_RESOLVER_FUNCTION"); - } - } else { - /// @dev Future features in __fallback - return gateway.__fallback(response, extradata); } } @@ -576,10 +539,10 @@ contract CCIP2ETH is iCCIP2ETH { } /** - * @dev Sets multiple signer (= manager) as approved to manage records for a node - * @param _node - Namehash of ENS domain - * @param _signer - Address of signer (= manager) - * @param _approval - Status to set + * @dev Sets multiple signers (= managers) as approved to manage records for a node + * @param _node - Namehash[] of ENS domains + * @param _signer - Address[] of signers (= managers) + * @param _approval - Status[] to set */ function multiApprove(bytes32[] calldata _node, address[] calldata _signer, bool[] calldata _approval) external { uint256 len = _node.length; @@ -653,6 +616,13 @@ contract CCIP2ETH is iCCIP2ETH { emit UpdatedWrapper(_addr, _set); } + /** + * @dev - Updates Chain ID in case of a hardfork + */ + function updateChainID() public { + chainID = gateway.uintToString(block.chainid); + } + /** * @dev - Owner of contract */ diff --git a/src/Interface.sol b/src/Interface.sol index 07a5bf2..427b8db 100644 --- a/src/Interface.sol +++ b/src/Interface.sol @@ -21,9 +21,9 @@ interface iENS { } interface iENSIP10 { - function resolve(bytes memory _name, bytes memory _data) external view returns (bytes memory); - error OffchainLookup(address _to, string[] _gateways, bytes _data, bytes4 _callbackFunction, bytes _extradata); + + function resolve(bytes memory _name, bytes memory _data) external view returns (bytes memory); } interface iCCIP2ETH is iENSIP10 { diff --git a/test/CCIP2ETH.t.sol b/test/CCIP2ETH.t.sol index a944192..60b34a6 100644 --- a/test/CCIP2ETH.t.sol +++ b/test/CCIP2ETH.t.sol @@ -33,8 +33,8 @@ contract CCIP2ETHTest is Test { function setUp() public { gateway = new GatewayManager(); - chainID = "5"; - ccip2eth = new CCIP2ETH(address(gateway), chainID); + chainID = gateway.uintToString(block.chainid); + ccip2eth = new CCIP2ETH(address(gateway)); } function testRecordHash() public { @@ -101,7 +101,6 @@ contract CCIP2ETHTest is Test { ) ); ccip2eth.resolve(_encoded, _request); - _subdomains; } /// @dev Test subdomain-level CCIP-Read call @@ -116,7 +115,7 @@ contract CCIP2ETHTest is Test { ENS.setOwner(_namehash, address(this)); bytes memory _recordhash = hex"e50101720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c"; - ccip2eth.setDeepSubRecordhash(_namehash, _subdomains, _recordhash); + ccip2eth.setRecordhash(_namehash, _recordhash); (string memory _path, string memory _domain) = utils.Format(_encoded); bytes memory _request = abi.encodeWithSelector(iResolver.text.selector, _namehash, abi.encode(string("avatar"))); string memory _recType = gateway.funcToJson(_request); @@ -136,7 +135,6 @@ contract CCIP2ETHTest is Test { ) ); ccip2eth.resolve(_encoded, _request); - _subdomains; } /// @dev Test deep CCIP-Read call @@ -182,7 +180,6 @@ contract CCIP2ETHTest is Test { ) ); ccip2eth.resolve(_encoded, _request); - _subdomains; } /// @dev CCIP end-to-end test with on-chain signer @@ -248,7 +245,6 @@ contract CCIP2ETHTest is Test { bytes memory _response = abi.encodeWithSelector(iCallbackType.signedRecord.selector, _signer, _signature, bytes("0"), _result); assertEq(_result, ccip2eth.__callback(_response, _extradata)); - _subdomains; } /// @dev CCIP end-to-end test with off-chain signer (with fake parameters) @@ -335,7 +331,6 @@ contract CCIP2ETHTest is Test { bytes memory _response = abi.encodeWithSelector(iCallbackType.signedRecord.selector, _signer, _recordSig, _approvedSig, _result); assertEq(_result, ccip2eth.__callback(_response, _extradata)); - _subdomains; } /// @dev CCIP end-to-end with off-chain signer and real parameters @@ -422,7 +417,6 @@ contract CCIP2ETHTest is Test { bytes memory _response = abi.encodeWithSelector(iCallbackType.signedRecord.selector, _signer, _recordSig, _approvedSig, _result); assertEq(_result, ccip2eth.__callback(_response, _extradata)); - _subdomains; } /// @dev Test setting regular and short recordhash @@ -460,9 +454,9 @@ contract CCIP2ETHTest is Test { /// @dev Test setting deep recordhash function test10_setDeepSubRecordhash() public { - string[] memory _subdomain = new string[](2); - _subdomain[0] = "hello"; - _subdomain[1] = "world"; + string[] memory _subdomains = new string[](2); + _subdomains[0] = "hello"; + _subdomains[1] = "world"; bytes[] memory _name = new bytes[](2); _name[0] = "domain"; _name[1] = "eth"; @@ -471,10 +465,10 @@ contract CCIP2ETHTest is Test { ENS.setOwner(_node, EOA); bytes memory _recordhash = hex"e501017200240801122008dd085b86d16226791544f4628c4efc0936c69221fef17dfac843d9713233bb"; - ccip2eth.setDeepSubRecordhash(_node, _subdomain, _recordhash); + ccip2eth.setDeepSubRecordhash(_node, _subdomains, _recordhash); vm.expectRevert(abi.encodeWithSelector(CCIP2ETH.NotAuthorised.selector, "NOT_APPROVED")); vm.prank(address(0xc0ffee)); - ccip2eth.setDeepSubRecordhash(_node, _subdomain, _recordhash); + ccip2eth.setDeepSubRecordhash(_node, _subdomains, _recordhash); _encoded; } }