Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Created June 4, 2019 03:58
Show Gist options
  • Save Arachnid/ed939227331d7e117fd057327010989f to your computer and use it in GitHub Desktop.
Save Arachnid/ed939227331d7e117fd057327010989f to your computer and use it in GitHub Desktop.
pragma solidity ^0.5.0;
import './ENS.sol';
library BytesUtils {
/*
* @dev Returns the 32 byte value at the specified index of self.
* @param self The byte string.
* @param idx The index into the bytes
* @return The specified 32 bytes of the string.
*/
function readBytes32(bytes memory self, uint idx) internal pure returns (bytes32 ret) {
require(idx + 32 <= self.length);
assembly {
ret := mload(add(add(self, 32), idx))
}
}
}
contract ResolverProxy {
ENS public ens;
using BytesUtils for bytes;
constructor(ENS _ens) public {
ens = _ens;
}
function() external {
bytes memory data = msg.data;
// First call argument is the namehash
bytes32 node = data.readBytes32(4);
address resolver = ens.resolver(node);
// Proxy the call to the resolver
(bool success, bytes memory ret) = resolver.staticcall(data);
require(success);
// Return exactly what the resolver returned.
assembly {
return(add(ret, 32), mload(ret))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment