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

Implement ChainID #45

Merged
merged 32 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
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
4 changes: 1 addition & 3 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
58 changes: 14 additions & 44 deletions src/CCIP2ETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 8 additions & 14 deletions test/CCIP2ETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -101,7 +101,6 @@ contract CCIP2ETHTest is Test {
)
);
ccip2eth.resolve(_encoded, _request);
_subdomains;
}

/// @dev Test subdomain-level CCIP-Read call
Expand All @@ -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);
Expand All @@ -136,7 +135,6 @@ contract CCIP2ETHTest is Test {
)
);
ccip2eth.resolve(_encoded, _request);
_subdomains;
}

/// @dev Test deep CCIP-Read call
Expand Down Expand Up @@ -182,7 +180,6 @@ contract CCIP2ETHTest is Test {
)
);
ccip2eth.resolve(_encoded, _request);
_subdomains;
}

/// @dev CCIP end-to-end test with on-chain signer
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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";
Expand All @@ -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;
}
}
Expand Down