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

refactor wrapped callback #328

Open
wants to merge 6 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified bun.lockb
Binary file not shown.
47 changes: 24 additions & 23 deletions contracts/dnsregistrar/OffchainDNSResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,11 @@ contract OffchainDNSResolver is IExtendedResolver, IERC165 {
bytes calldata response,
bytes calldata extraData
) external view returns (bytes memory) {
(bytes memory name, bytes memory query, bytes4 selector) = abi.decode(
(bytes memory name, bytes memory query) = abi.decode(
extraData,
(bytes, bytes, bytes4)
(bytes, bytes)
);

if (selector != bytes4(0)) {
(bytes memory targetData, address targetResolver) = abi.decode(
query,
(bytes, address)
);
return
callWithOffchainLookupPropagation(
targetResolver,
name,
query,
abi.encodeWithSelector(
selector,
response,
abi.encode(targetData, address(this))
)
);
}

DNSSEC.RRSetWithSignature[] memory rrsets = abi.decode(
response,
(DNSSEC.RRSetWithSignature[])
Expand Down Expand Up @@ -167,6 +149,25 @@ contract OffchainDNSResolver is IExtendedResolver, IERC165 {
revert CouldNotResolve(name);
}

function resolveWrappedCallback(
bytes calldata response,
bytes calldata extraData
) external view returns (bytes memory) {
(
bytes memory name,
bytes memory innerExtraData,
address targetResolver,
bytes4 selector
) = abi.decode(extraData, (bytes, bytes, address, bytes4));
return
callWithOffchainLookupPropagation(
targetResolver,
name,
innerExtraData,
abi.encodeWithSelector(selector, response, innerExtraData)
);
}

function parseRR(
bytes memory data,
uint256 idx,
Expand Down Expand Up @@ -304,7 +305,7 @@ contract OffchainDNSResolver is IExtendedResolver, IERC165 {
urls,
abi.encodeCall(IDNSGateway.resolve, (name, TYPE_TXT)),
OffchainDNSResolver.resolveCallback.selector,
abi.encode(name, data, bytes4(0))
abi.encode(name, data)
);
}

Expand All @@ -329,8 +330,8 @@ contract OffchainDNSResolver is IExtendedResolver, IERC165 {
address(this),
urls,
callData,
OffchainDNSResolver.resolveCallback.selector,
abi.encode(name, extraData, innerCallbackFunction)
OffchainDNSResolver.resolveWrappedCallback.selector,
abi.encode(name, extraData, sender, innerCallbackFunction)
);
}
}
4 changes: 2 additions & 2 deletions contracts/test/mocks/MockOffchainResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ contract MockOffchainResolver is IExtendedResolver, ERC165 {
bytes calldata response,
bytes calldata extraData
) external view returns (bytes memory) {
(, bytes memory callData, ) = abi.decode(
(, bytes memory callData, , ) = abi.decode(
extraData,
(bytes, bytes, bytes4)
(bytes, bytes, address, bytes4)
);
if (bytes4(callData) == bytes4(keccak256("addr(bytes32)"))) {
(bytes memory result, , ) = abi.decode(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"dependencies": {
"@ensdomains/buffer": "^0.1.1",
"@ensdomains/solsha1": "0.0.3",
"@nomicfoundation/solidity-analyzer-darwin-x64": "^0.1.2",
"@openzeppelin/contracts": "^4.1.0",
"dns-packet": "^5.3.0"
},
Expand All @@ -69,6 +70,6 @@
},
"homepage": "https://github.com/ensdomains/ens-contracts#readme",
"volta": {
"node": "16.20.2"
"node": "20.15.1"
}
}
13 changes: 7 additions & 6 deletions test/dnsregistrar/TestOffchainDNSResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ async function fixture() {
)
const dnsName = dnsEncodeName(name)
const extraData = encodeAbiParameters(
[{ type: 'bytes' }, { type: 'bytes' }, { type: 'bytes4' }],
[dnsName, calldata, '0x00000000'],
[{ type: 'bytes' }, { type: 'bytes' }],
[dnsName, calldata],
)

return offchainDnsResolver.read.resolveCallback([response, extraData])
Expand Down Expand Up @@ -150,8 +150,8 @@ describe('OffchainDNSResolver', () => {
args: [namehash(name)],
})
const extraData = encodeAbiParameters(
[{ type: 'bytes' }, { type: 'bytes' }, { type: 'bytes4' }],
[dnsName, callData, '0x00000000'],
[{ type: 'bytes' }, { type: 'bytes' }],
[dnsName, callData],
)

const gatewayCall = encodeFunctionData({
Expand Down Expand Up @@ -523,10 +523,11 @@ describe('OffchainDNSResolver', () => {
})

const extraData = encodeAbiParameters(
parseAbiParameters('bytes,bytes,bytes4'),
parseAbiParameters('bytes,bytes,address,bytes4'),
[
dnsName,
calldata,
offchainResolver.address,
toFunctionSelector('function resolveCallback(bytes,bytes)'),
],
)
Expand All @@ -544,7 +545,7 @@ describe('OffchainDNSResolver', () => {
getAddress(offchainDnsResolver.address),
['https://example.com/'],
calldata,
toFunctionSelector('function resolveCallback(bytes,bytes)'),
toFunctionSelector('function resolveWrappedCallback(bytes,bytes)'),
extraData,
)

Expand Down
8 changes: 4 additions & 4 deletions test/utils/TestUniversalResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,12 @@ describe('UniversalResolver', () => {
],
})
const innerExtraData = encodeAbiParameters(
parseAbiParameters('bytes, bytes, bytes4'),
[dnsEncodeName(name), addrCall, '0x00000000'],
parseAbiParameters('bytes, bytes'),
[dnsEncodeName(name), addrCall],
)
const extraData = encodeExtraData({
isWildcard: true,
resolver: offchainDnsResolver.address,
resolver: offchainDnsResolver.address as Address,
gateways: ['http://universal-offchain-resolver.local'],
metadata: '0x',
extraDatas: [
Expand Down Expand Up @@ -759,7 +759,7 @@ describe('UniversalResolver', () => {

const extraData = encodeExtraData({
isWildcard: false,
resolver: offchainResolver.address,
resolver: offchainResolver.address as Address,
gateways: ['http://universal-offchain-resolver.local'],
metadata: '0x',
extraDatas: [
Expand Down