Skip to content

Commit

Permalink
clean & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xc0de4c0ffee committed Jul 20, 2023
1 parent bc2a2f5 commit 0fdc412
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 428 deletions.
2 changes: 0 additions & 2 deletions justfile

This file was deleted.

13 changes: 0 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,9 @@
"license": "MIT",
"type": "module",
"scripts": {
"abi": "node ./test/abigen.js",
"gen": "node ./test/recgen.js",
"local": "anvil --fork-url https://rpc.ankr.com/eth_goerli",
"localDeploy": "forge fmt && source .env && forge script ./script/Deploy.s.sol --rpc-url http://127.0.0.1:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast -vvvv",
"test": "forge fmt && source .env && forge test --fork-url $GOERLI_RPC_URL -vvvv --fork-block-number 8897000 --gas-report",
"dev": "forge fmt && source .env && forge test --fork-url $GOERLI_RPC_URL -vvv --fork-block-number 8897000 --gas-report --watch"
},
"devDependencies": {
"concurrently": "^8.1.0",
"jest": "^29.5.0",
"nodemon": "^2.0.22"
},
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"@noble/secp256k1": "^1.7.1",
"viem": "^1.0.2"
}
}
243 changes: 98 additions & 145 deletions src/CCIP2ETH.sol

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ interface iCCIP2ETH is iENSIP10 {
external
view
returns (address _signer);
function setRecordhash(string[] memory _subdomains, bytes32 _node, bytes calldata _contenthash) external;
function setRecordhash(bytes32 _node, bytes calldata _recordhash) external;
function setOwnerhash(bytes calldata _recordhash) external payable;
function redirectService(bytes calldata _encoded, bytes calldata _requested)
external
view
returns (bytes4 _selector, bytes32 _namehash, bytes memory _redirectRequest, string memory domain);
}

interface iGatewayManager is iERC173 {
Expand Down Expand Up @@ -101,6 +106,6 @@ interface iCallbackType {
address recordSigner, // Owner OR On-chain Manager OR Off-chain Manager
bytes memory recordSignature, // Signature from signer for redirect value
bytes memory approvedSignature, // bytes1(..) IF signer is owner or on-chain manager
bytes memory redirect // ABI-encoded recordhash OR DNS-encoded domain.eth to redirect
bytes memory redirect // DNS-encoded domain.eth to redirect
) external view returns (bytes memory);
}
57 changes: 25 additions & 32 deletions test/CCIP2ETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ contract CCIP2ETHTest is Test {

/// @dev Test CCIP-Read call for a domain
function test2_ResolveLevel2() public {
string[] memory _subdomains = new string[](0);
bytes[] memory _name = new bytes[](2);
_name[0] = "ccip2";
_name[1] = "eth";
Expand All @@ -63,7 +62,7 @@ contract CCIP2ETHTest is Test {
vm.prank(_addr);
//ENS.setOwner(_namehash, address(this));
//ENS.setResolver(_namehash, address(ccip2eth));
ccip2eth.setRecordhash(_subdomains, _namehash, _recordhash);
ccip2eth.setRecordhash(_namehash, _recordhash);
(string memory _path, string memory _domain) = utils.Format(_encoded);
bytes memory _request = abi.encodePacked(iResolver.addr.selector, _namehash);
string memory _recType = gateway.funcToJson(_request);
Expand All @@ -87,7 +86,6 @@ contract CCIP2ETHTest is Test {

/// @dev Test subdomain-level CCIP-Read call
function test3_ResolveLevel3() public {
string[] memory _subdomains = new string[](0);
bytes[] memory _name = new bytes[](3);
_name[0] = "blog";
_name[1] = "vitalik";
Expand All @@ -98,7 +96,7 @@ contract CCIP2ETHTest is Test {
ENS.setOwner(_namehash, address(this));
bytes memory _recordhash =
hex"e50101720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c";
ccip2eth.setRecordhash(_subdomains, _namehash, _recordhash);
ccip2eth.setRecordhash(_namehash, _recordhash);
(string memory _path, string memory _domain) = utils.Format(_encoded);
bytes memory _request = abi.encodePacked(iResolver.text.selector, _namehash, abi.encode(string("avatar")));
string memory _recType = gateway.funcToJson(_request);
Expand All @@ -124,7 +122,6 @@ contract CCIP2ETHTest is Test {

/// @dev Test deep CCIP-Read call
function test4_ResolveLevel7() public {
string[] memory _subdomains = new string[](0);
bytes[] memory _base = new bytes[](2);
_base[0] = "vitalik";
_base[1] = "eth";
Expand All @@ -134,7 +131,7 @@ contract CCIP2ETHTest is Test {
ENS.setOwner(_baseNode, address(this)); // Owner records set at level 2 only
bytes memory _recordhash =
hex"e50101720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c";
ccip2eth.setRecordhash(_subdomains, _baseNode, _recordhash);
ccip2eth.setRecordhash(_baseNode, _recordhash);

bytes[] memory _name = new bytes[](7);
_name[0] = "never";
Expand Down Expand Up @@ -171,7 +168,6 @@ contract CCIP2ETHTest is Test {

/// @dev CCIP end-to-end test with on-chain signer
function test5_CCIPCallbackApprovedOnChain() public {
string[] memory _subdomains = new string[](0);
bytes[] memory _name = new bytes[](2);
_name[0] = "domain";
_name[1] = "eth";
Expand All @@ -185,7 +181,7 @@ contract CCIP2ETHTest is Test {
ccip2eth.approve(_node, _signer, true);
bytes memory _recordhash =
hex"e50101720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c";
ccip2eth.setRecordhash(_subdomains, _node, _recordhash);
ccip2eth.setRecordhash(_node, _recordhash);

(string memory _path, string memory _domain) = utils.Format(_encoded);
bytes memory _request = abi.encodePacked(iResolver.addr.selector, _node);
Expand All @@ -211,13 +207,13 @@ contract CCIP2ETHTest is Test {
ccip2eth.resolve(_encoded, _request);
bytes memory _result = abi.encode(address(this));
string memory signRequest = string.concat(
"Requesting Signature To Update Record\n",
"\nDomain: ",
"Requesting Signature To Update ENS Record\n",
"\nOrigin: ",
_domain,
"\nType: address/60",
"\nExtradata: 0x",
gateway.bytesToHexString(abi.encodePacked(keccak256(_result)), 0),
"\nSigner: eip155:1:",
"\nSigned By: eip155:1:",
gateway.toChecksumAddress(address(_signer))
);
bytes32 _digest = keccak256(
Expand All @@ -236,7 +232,6 @@ contract CCIP2ETHTest is Test {

/// @dev CCIP end-to-end test with off-chain signer (with fake parameters)
function test6_CCIPCallbackApprovedOffChain() public {
string[] memory _subdomains = new string[](0);
bytes[] memory _name = new bytes[](2);
_name[0] = "domain";
_name[1] = "eth";
Expand All @@ -251,7 +246,7 @@ contract CCIP2ETHTest is Test {
bytes memory _recordhash =
hex"e50101720024080112203c5aba6c9b5055a5fa12281c486188ed8ae2b6ef394b3d981b00d17a4b51735c";
vm.prank(_owner);
ccip2eth.setRecordhash(_subdomains, _node, _recordhash);
ccip2eth.setRecordhash(_node, _recordhash);

(string memory _path, string memory _domain) = utils.Format(_encoded);
bytes memory _request = abi.encodePacked(iResolver.addr.selector, _node);
Expand All @@ -275,13 +270,13 @@ contract CCIP2ETHTest is Test {
ccip2eth.resolve(_encoded, _request);
bytes memory _result = abi.encode(address(this));
string memory signRequest = string.concat(
"Requesting Signature To Update Record\n",
"\nDomain: ",
"Requesting Signature To Update ENS Record\n",
"\nOrigin: ",
_domain,
"\nType: address/60",
"\nExtradata: 0x",
gateway.bytesToHexString(abi.encodePacked(keccak256(_result)), 0),
"\nSigner: eip155:1:",
"\nSigned By: eip155:1:",
gateway.toChecksumAddress(address(_signer))
);
bytes32 _digest = keccak256(
Expand All @@ -294,11 +289,11 @@ contract CCIP2ETHTest is Test {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(SignerKey, _digest);
bytes memory _recordSig = abi.encodePacked(r, s, v);
signRequest = string.concat(
"Requesting Signature To Approve Records Signer\n",
"\nDomain: domain.eth",
"Requesting Signature To Approve Offchain ENS Records Signer\n",
"\nOrigin: domain.eth",
"\nApproved Signer: eip155:1:",
gateway.toChecksumAddress(_signer),
"\nOwner: eip155:1:",
"\nApproved By: eip155:1:",
gateway.toChecksumAddress(_owner)
);
_digest = keccak256(
Expand All @@ -315,7 +310,6 @@ contract CCIP2ETHTest is Test {

/// @dev CCIP end-to-end with off-chain signer and real parameters
function test7_CCIPCallbackApprovedOffChain_WithRealParameters() public {
string[] memory _subdomains = new string[](0);
bytes[] memory _name = new bytes[](2);
_name[0] = "00081";
_name[1] = "eth";
Expand All @@ -330,7 +324,7 @@ contract CCIP2ETHTest is Test {
bytes memory _recordhash =
hex"e501017200240801122008dd085b86d16226791544f4628c4efc0936c69221fef17dfac843d9713233bb";
vm.prank(_owner);
ccip2eth.setRecordhash(_subdomains, _node, _recordhash); // Set recordhash
ccip2eth.setRecordhash(_node, _recordhash); // Set recordhash

(string memory _path, string memory _domain) = utils.Format(_encoded);
bytes memory _request = abi.encodePacked(iResolver.addr.selector, _node);
Expand All @@ -354,13 +348,13 @@ contract CCIP2ETHTest is Test {
ccip2eth.resolve(_encoded, _request);
bytes memory _result = abi.encode(address(0x1111000000000000000000000000000000000001));
string memory signRequest = string.concat(
"Requesting Signature To Update Record\n",
"\nDomain: ",
"Requesting Signature To Update ENS Record\n",
"\nOrigin: ",
_domain,
"\nType: address/60",
"\nExtradata: 0x",
gateway.bytesToHexString(abi.encodePacked(keccak256(_result)), 0),
"\nSigner: eip155:1:",
"\nSigned By: eip155:1:",
gateway.toChecksumAddress(address(_signer))
);
bytes32 _digest = keccak256(
Expand All @@ -373,12 +367,12 @@ contract CCIP2ETHTest is Test {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(SignerKey, _digest);
bytes memory _recordSig = abi.encodePacked(r, s, v);
signRequest = string.concat(
"Requesting Signature To Approve Records Signer\n",
"\nDomain: ",
"Requesting Signature To Approve Offchain ENS Records Signer\n",
"\nOrigin: ",
_domain,
"\nApproved Signer: eip155:1:",
gateway.toChecksumAddress(_signer),
"\nOwner: eip155:1:",
"\nApproved By: eip155:1:",
gateway.toChecksumAddress(_owner)
);
_digest = keccak256(
Expand All @@ -394,8 +388,7 @@ contract CCIP2ETHTest is Test {
}

/// @dev Test setting deep recordhash
function test8_setDeepRecordhash() public {
string[] memory _subdomains = new string[](2);
/*function test8_setDeepRecordhash() public {
_subdomains[0] = "hello";
_subdomains[1] = "world";
bytes[] memory _name = new bytes[](2);
Expand All @@ -410,16 +403,16 @@ contract CCIP2ETHTest is Test {
bytes memory _recordhash =
hex"e501017200240801122008dd085b86d16226791544f4628c4efc0936c69221fef17dfac843d9713233bb";
vm.prank(_owner);
ccip2eth.setRecordhash(_subdomains, _node, _recordhash); // Set recordhash for 'hello.world.domain.eth'
ccip2eth.setRecordhash(_node, _recordhash); // Set recordhash for 'hello.world.domain.eth'
_encoded;
}
}*/
}

/// @dev Utility functions
contract Utils {
function Format(bytes calldata _encoded) external pure returns (string memory _path, string memory _domain) {
uint256 n = 1;
uint256 len = uint8(bytes1(_encoded[:1]));
uint256 len = uint8(bytes1(_encoded[0]));
bytes memory _label;
_label = _encoded[1:n += len];
_path = string(_label);
Expand Down
6 changes: 0 additions & 6 deletions test/genABI.js

This file was deleted.

8 changes: 0 additions & 8 deletions test/t2.js

This file was deleted.

Loading

0 comments on commit 0fdc412

Please sign in to comment.