Проверенный контрактТочноеMIT
IdentityRegistry
Адрес0xffe52fb27d66dcccdf03376b400d6e399dec3eec
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.25
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.25+commit.b61c2a91
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Через IR
- да
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 172 474
- Транзакция создания
- 0x367419d406…96e30f4cab
14 файлов
- contracts/v2/IdentityRegistry.solглавный45,77 КБ
- @openzeppelin/contracts/access/Ownable.sol3,1 КБ
- @openzeppelin/contracts/access/Ownable2Step.sol2,48 КБ
- @openzeppelin/contracts/utils/Context.sol963 Б
- @openzeppelin/contracts/utils/Pausable.sol2,71 КБ
- @openzeppelin/contracts/utils/cryptography/Hashes.sol1,03 КБ
- @openzeppelin/contracts/utils/cryptography/MerkleProof.sol24,34 КБ
- contracts/v2/AttestationRegistry.sol3,77 КБ
- contracts/v2/ENSIdentityVerifier.sol4,94 КБ
- contracts/v2/interfaces/IAddrResolver.sol151 Б
- contracts/v2/interfaces/IENS.sol636 Б
- contracts/v2/interfaces/INameWrapper.sol397 Б
- contracts/v2/interfaces/IReputationEngine.sol6,28 КБ
- contracts/v2/utils/Ownable2Step.sol522 Б
contracts/v2/IdentityRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {Ownable2Step} from "./utils/Ownable2Step.sol";
import {IENS} from "./interfaces/IENS.sol";
import {INameWrapper} from "./interfaces/INameWrapper.sol";
import {IReputationEngine} from "./interfaces/IReputationEngine.sol";
import {ENSIdentityVerifier} from "./ENSIdentityVerifier.sol";
import {AttestationRegistry} from "./AttestationRegistry.sol";
error ZeroAddress();
error ZeroNode();
error UnauthorizedAgent();
error EtherNotAccepted();
error IncompatibleReputationEngine();
error EmptySubdomain();
/// @title IdentityRegistry
/// @notice Verifies ENS subdomain ownership and tracks manual allowlists
/// for agents and validators. Provides helper views that also check
/// reputation blacklists.
contract IdentityRegistry is Ownable2Step {
/// @notice Module version for compatibility checks.
uint256 public constant version = 2;
enum AgentType {
Human,
AI
}
IENS public ens;
INameWrapper public nameWrapper;
IReputationEngine public reputationEngine;
AttestationRegistry public attestationRegistry;
bytes32 public agentRootNode;
bytes32 public clubRootNode;
bytes32 public nodeRootNode;
bytes32 public agentMerkleRoot;
bytes32 public validatorMerkleRoot;
mapping(address => bool) public additionalAgents;
mapping(address => bool) public additionalValidators;
mapping(address => bool) public additionalNodeOperators;
mapping(address => AgentType) public agentTypes;
/// @notice Optional metadata URI describing agent capabilities.
mapping(address => string) public agentProfileURI;
bytes32[] private agentRootNodeAliases;
bytes32[] private clubRootNodeAliases;
bytes32[] private nodeRootNodeAliases;
mapping(bytes32 => bool) private agentRootNodeAliasSet;
mapping(bytes32 => bool) private clubRootNodeAliasSet;
mapping(bytes32 => bool) private nodeRootNodeAliasSet;
event ENSUpdated(address indexed ens);
event NameWrapperUpdated(address indexed nameWrapper);
event ReputationEngineUpdated(address indexed reputationEngine);
event AttestationRegistryUpdated(address indexed attestationRegistry);
event AgentRootNodeUpdated(bytes32 indexed agentRootNode);
event ClubRootNodeUpdated(bytes32 indexed clubRootNode);
event NodeRootNodeUpdated(bytes32 indexed nodeRootNode);
event AgentMerkleRootUpdated(bytes32 indexed agentMerkleRoot);
event ValidatorMerkleRootUpdated(bytes32 indexed validatorMerkleRoot);
event AdditionalAgentUpdated(address indexed agent, bool allowed);
event AdditionalValidatorUpdated(address indexed validator, bool allowed);
event AdditionalNodeOperatorUpdated(address indexed nodeOperator, bool allowed);
event AdditionalAgentUsed(address indexed agent, string subdomain);
event AdditionalValidatorUsed(address indexed validator, string subdomain);
event AdditionalNodeOperatorUsed(address indexed nodeOperator, string subdomain);
event AgentRootNodeAliasUpdated(bytes32 indexed node, bool allowed);
event ClubRootNodeAliasUpdated(bytes32 indexed node, bool allowed);
event NodeRootNodeAliasUpdated(bytes32 indexed node, bool allowed);
event IdentityVerified(
address indexed user,
AttestationRegistry.Role indexed role,
bytes32 indexed node,
string subdomain
);
event ENSVerified(
address indexed user,
bytes32 indexed node,
string label,
bool viaWrapper,
bool viaMerkle
);
/// @notice Emitted when a verification attempt fails.
event IdentityVerificationFailed(
address indexed user,
AttestationRegistry.Role indexed role,
string subdomain
);
event AgentTypeUpdated(address indexed agent, AgentType agentType);
/// @notice Emitted when an agent updates their profile metadata.
event AgentProfileUpdated(address indexed agent, string uri);
event MainnetConfigured(
address indexed ens,
address indexed nameWrapper,
bytes32 indexed agentRoot,
bytes32 clubRoot,
bytes32 nodeRoot
);
event ConfigurationApplied(
address indexed caller,
bool ensUpdated,
bool nameWrapperUpdated,
bool reputationEngineUpdated,
bool attestationRegistryUpdated,
bool agentRootUpdated,
bool clubRootUpdated,
bool nodeRootUpdated,
bool agentMerkleRootUpdated,
bool validatorMerkleRootUpdated,
uint256 additionalAgentUpdates,
uint256 additionalValidatorUpdates,
uint256 additionalNodeUpdates,
uint256 agentTypeUpdates
);
struct ConfigUpdate {
bool setENS;
address ens;
bool setNameWrapper;
address nameWrapper;
bool setReputationEngine;
address reputationEngine;
bool setAttestationRegistry;
address attestationRegistry;
bool setAgentRootNode;
bytes32 agentRootNode;
bool setClubRootNode;
bytes32 clubRootNode;
bool setNodeRootNode;
bytes32 nodeRootNode;
bool setAgentMerkleRoot;
bytes32 agentMerkleRoot;
bool setValidatorMerkleRoot;
bytes32 validatorMerkleRoot;
}
function _assertSubdomain(string memory subdomain) private pure {
if (bytes(subdomain).length == 0) revert EmptySubdomain();
}
struct AdditionalAgentConfig {
address agent;
bool allowed;
}
struct AdditionalValidatorConfig {
address validator;
bool allowed;
}
struct AdditionalNodeOperatorConfig {
address nodeOperator;
bool allowed;
}
struct AgentTypeConfig {
address agent;
AgentType agentType;
}
struct RootNodeAliasConfig {
bytes32 node;
bool allowed;
}
address public constant MAINNET_ENS =
0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e;
address public constant MAINNET_NAME_WRAPPER =
0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401;
bytes32 public constant MAINNET_AGENT_ROOT_NODE =
0x2c9c6189b2e92da4d0407e9deb38ff6870729ad063af7e8576cb7b7898c88e2d;
bytes32 public constant MAINNET_CLUB_ROOT_NODE =
0x39eb848f88bdfb0a6371096249dd451f56859dfe2cd3ddeab1e26d5bb68ede16;
bytes32 public constant MAINNET_ALPHA_AGENT_ROOT_NODE =
0xc74b6c5e8a0d97ed1fe28755da7d06a84593b4de92f6582327bc40f41d6c2d5e;
bytes32 public constant MAINNET_ALPHA_CLUB_ROOT_NODE =
0x6487f659ec6f3fbd424b18b685728450d2559e4d68768393f9c689b2b6e5405e;
bytes32 public constant MAINNET_NODE_ROOT_NODE =
0xa26287e1184492446ad67d7dcdb51be050d4144ddda21bb3ba5926a8bf5c5731;
bytes32 public constant MAINNET_ALPHA_NODE_ROOT_NODE =
0x2d936bd2c82bc0aaa072a9d3c6d87aad1c1ec6a245f991129efb6ecc9fed57c4;
constructor(
IENS _ens,
INameWrapper _nameWrapper,
IReputationEngine _reputationEngine,
bytes32 _agentRootNode,
bytes32 _clubRootNode
) Ownable2Step(msg.sender) {
ens = _ens;
if (address(_ens) != address(0)) {
emit ENSUpdated(address(_ens));
}
nameWrapper = _nameWrapper;
if (address(_nameWrapper) != address(0)) {
emit NameWrapperUpdated(address(_nameWrapper));
}
if (address(_reputationEngine) != address(0)) {
if (_reputationEngine.version() != 2) {
revert IncompatibleReputationEngine();
}
reputationEngine = _reputationEngine;
emit ReputationEngineUpdated(address(_reputationEngine));
}
agentRootNode = _agentRootNode;
if (_agentRootNode != bytes32(0)) {
emit AgentRootNodeUpdated(_agentRootNode);
}
clubRootNode = _clubRootNode;
if (_clubRootNode != bytes32(0)) {
emit ClubRootNodeUpdated(_clubRootNode);
}
}
// ---------------------------------------------------------------------
// Owner configuration
// ---------------------------------------------------------------------
function setENS(address ensAddr) public onlyOwner {
_setENS(ensAddr);
}
function setNameWrapper(address wrapper) public onlyOwner {
_setNameWrapper(wrapper);
}
function setReputationEngine(address engine) external onlyOwner {
_setReputationEngine(engine);
}
function setAttestationRegistry(address registry) external onlyOwner {
_setAttestationRegistry(registry);
}
function setAgentRootNode(bytes32 root) public onlyOwner {
_setAgentRootNode(root);
}
function setClubRootNode(bytes32 root) public onlyOwner {
_setClubRootNode(root);
}
function setNodeRootNode(bytes32 root) public onlyOwner {
_setNodeRootNode(root);
}
function getAgentRootNodeAliases() external view returns (bytes32[] memory) {
return agentRootNodeAliases;
}
function getClubRootNodeAliases() external view returns (bytes32[] memory) {
return clubRootNodeAliases;
}
function getNodeRootNodeAliases() external view returns (bytes32[] memory) {
return nodeRootNodeAliases;
}
function isAgentRootNodeAlias(bytes32 node) external view returns (bool) {
return agentRootNodeAliasSet[node];
}
function isClubRootNodeAlias(bytes32 node) external view returns (bool) {
return clubRootNodeAliasSet[node];
}
function isNodeRootNodeAlias(bytes32 node) external view returns (bool) {
return nodeRootNodeAliasSet[node];
}
function addAgentRootNodeAlias(bytes32 node) external onlyOwner {
_addAgentRootNodeAlias(node);
}
function removeAgentRootNodeAlias(bytes32 node) external onlyOwner {
_removeAgentRootNodeAlias(node);
}
function addClubRootNodeAlias(bytes32 node) external onlyOwner {
_addClubRootNodeAlias(node);
}
function removeClubRootNodeAlias(bytes32 node) external onlyOwner {
_removeClubRootNodeAlias(node);
}
function addNodeRootNodeAlias(bytes32 node) external onlyOwner {
_addNodeRootNodeAlias(node);
}
function removeNodeRootNodeAlias(bytes32 node) external onlyOwner {
_removeNodeRootNodeAlias(node);
}
/// @notice Configure the registry with canonical mainnet ENS settings.
function configureMainnet() external onlyOwner {
_setENS(MAINNET_ENS);
_setNameWrapper(MAINNET_NAME_WRAPPER);
_setAgentRootNode(MAINNET_AGENT_ROOT_NODE);
_setClubRootNode(MAINNET_CLUB_ROOT_NODE);
_setNodeRootNode(MAINNET_NODE_ROOT_NODE);
_addAgentRootNodeAlias(MAINNET_ALPHA_AGENT_ROOT_NODE);
_addClubRootNodeAlias(MAINNET_ALPHA_CLUB_ROOT_NODE);
_addNodeRootNodeAlias(MAINNET_ALPHA_NODE_ROOT_NODE);
emit MainnetConfigured(
MAINNET_ENS,
MAINNET_NAME_WRAPPER,
MAINNET_AGENT_ROOT_NODE,
MAINNET_CLUB_ROOT_NODE,
MAINNET_NODE_ROOT_NODE
);
}
function setAgentMerkleRoot(bytes32 root) external onlyOwner {
_setAgentMerkleRoot(root);
}
function setValidatorMerkleRoot(bytes32 root) external onlyOwner {
_setValidatorMerkleRoot(root);
}
function addAdditionalAgent(address agent) external onlyOwner {
_setAdditionalAgent(agent, true);
}
function removeAdditionalAgent(address agent) external onlyOwner {
_setAdditionalAgent(agent, false);
}
function addAdditionalValidator(address validator) external onlyOwner {
_setAdditionalValidator(validator, true);
}
function removeAdditionalValidator(address validator) external onlyOwner {
_setAdditionalValidator(validator, false);
}
function addAdditionalNodeOperator(address nodeOperator) external onlyOwner {
_setAdditionalNodeOperator(nodeOperator, true);
}
function removeAdditionalNodeOperator(address nodeOperator) external onlyOwner {
_setAdditionalNodeOperator(nodeOperator, false);
}
function setAgentType(address agent, AgentType agentType) external onlyOwner {
_setAgentType(agent, agentType);
}
function applyConfiguration(
ConfigUpdate calldata config,
AdditionalAgentConfig[] calldata agentUpdates,
AdditionalValidatorConfig[] calldata validatorUpdates,
AdditionalNodeOperatorConfig[] calldata nodeUpdates,
RootNodeAliasConfig[] calldata agentRootAliasUpdates,
RootNodeAliasConfig[] calldata clubRootAliasUpdates,
RootNodeAliasConfig[] calldata nodeRootAliasUpdates,
AgentTypeConfig[] calldata agentTypeUpdates
) external onlyOwner {
bool ensUpdated;
bool nameWrapperUpdated;
bool reputationUpdated;
bool attestationUpdated;
bool agentRootUpdated;
bool clubRootUpdated;
bool nodeRootUpdated;
bool agentMerkleUpdated;
bool validatorMerkleUpdated;
if (config.setENS) {
_setENS(config.ens);
ensUpdated = true;
}
if (config.setNameWrapper) {
_setNameWrapper(config.nameWrapper);
nameWrapperUpdated = true;
}
if (config.setReputationEngine) {
_setReputationEngine(config.reputationEngine);
reputationUpdated = true;
}
if (config.setAttestationRegistry) {
_setAttestationRegistry(config.attestationRegistry);
attestationUpdated = true;
}
if (config.setAgentRootNode) {
_setAgentRootNode(config.agentRootNode);
agentRootUpdated = true;
}
if (config.setClubRootNode) {
_setClubRootNode(config.clubRootNode);
clubRootUpdated = true;
}
if (config.setNodeRootNode) {
_setNodeRootNode(config.nodeRootNode);
nodeRootUpdated = true;
}
if (config.setAgentMerkleRoot) {
_setAgentMerkleRoot(config.agentMerkleRoot);
agentMerkleUpdated = true;
}
if (config.setValidatorMerkleRoot) {
_setValidatorMerkleRoot(config.validatorMerkleRoot);
validatorMerkleUpdated = true;
}
uint256 agentLen = agentUpdates.length;
for (uint256 i; i < agentLen; i++) {
AdditionalAgentConfig calldata update = agentUpdates[i];
_setAdditionalAgent(update.agent, update.allowed);
}
uint256 validatorLen = validatorUpdates.length;
for (uint256 i; i < validatorLen; i++) {
AdditionalValidatorConfig calldata update = validatorUpdates[i];
_setAdditionalValidator(update.validator, update.allowed);
}
uint256 nodeLen = nodeUpdates.length;
for (uint256 i; i < nodeLen; i++) {
AdditionalNodeOperatorConfig calldata nodeUpdate = nodeUpdates[i];
_setAdditionalNodeOperator(nodeUpdate.nodeOperator, nodeUpdate.allowed);
}
uint256 agentAliasLen = agentRootAliasUpdates.length;
for (uint256 i; i < agentAliasLen; i++) {
RootNodeAliasConfig calldata update = agentRootAliasUpdates[i];
if (update.allowed) {
_addAgentRootNodeAlias(update.node);
} else {
_removeAgentRootNodeAlias(update.node);
}
}
uint256 clubAliasLen = clubRootAliasUpdates.length;
for (uint256 i; i < clubAliasLen; i++) {
RootNodeAliasConfig calldata update = clubRootAliasUpdates[i];
if (update.allowed) {
_addClubRootNodeAlias(update.node);
} else {
_removeClubRootNodeAlias(update.node);
}
}
uint256 nodeAliasLen = nodeRootAliasUpdates.length;
for (uint256 i; i < nodeAliasLen; i++) {
RootNodeAliasConfig calldata update = nodeRootAliasUpdates[i];
if (update.allowed) {
_addNodeRootNodeAlias(update.node);
} else {
_removeNodeRootNodeAlias(update.node);
}
}
uint256 agentTypeLen = agentTypeUpdates.length;
for (uint256 i; i < agentTypeLen; i++) {
AgentTypeConfig calldata update = agentTypeUpdates[i];
_setAgentType(update.agent, update.agentType);
}
emit ConfigurationApplied(
msg.sender,
ensUpdated,
nameWrapperUpdated,
reputationUpdated,
attestationUpdated,
agentRootUpdated,
clubRootUpdated,
nodeRootUpdated,
agentMerkleUpdated,
validatorMerkleUpdated,
agentLen,
validatorLen,
nodeLen,
agentTypeLen
);
}
function _setENS(address ensAddr) internal {
if (ensAddr == address(0)) {
revert ZeroAddress();
}
ens = IENS(ensAddr);
emit ENSUpdated(ensAddr);
}
function _setNameWrapper(address wrapper) internal {
if (wrapper == address(0)) {
revert ZeroAddress();
}
nameWrapper = INameWrapper(wrapper);
emit NameWrapperUpdated(wrapper);
}
function _setReputationEngine(address engine) internal {
if (engine == address(0)) {
revert ZeroAddress();
}
if (IReputationEngine(engine).version() != 2) {
revert IncompatibleReputationEngine();
}
reputationEngine = IReputationEngine(engine);
emit ReputationEngineUpdated(engine);
}
function _setAttestationRegistry(address registry) internal {
if (registry == address(0)) {
revert ZeroAddress();
}
attestationRegistry = AttestationRegistry(registry);
emit AttestationRegistryUpdated(registry);
}
function _setAgentRootNode(bytes32 root) internal {
agentRootNode = root;
emit AgentRootNodeUpdated(root);
}
function _setClubRootNode(bytes32 root) internal {
clubRootNode = root;
emit ClubRootNodeUpdated(root);
}
function _setNodeRootNode(bytes32 root) internal {
nodeRootNode = root;
emit NodeRootNodeUpdated(root);
}
function _setAgentMerkleRoot(bytes32 root) internal {
agentMerkleRoot = root;
emit AgentMerkleRootUpdated(root);
}
function _setValidatorMerkleRoot(bytes32 root) internal {
validatorMerkleRoot = root;
emit ValidatorMerkleRootUpdated(root);
}
function _setAdditionalAgent(address agent, bool allowed) internal {
if (allowed && agent == address(0)) {
revert ZeroAddress();
}
additionalAgents[agent] = allowed;
emit AdditionalAgentUpdated(agent, allowed);
}
function _setAdditionalValidator(address validator, bool allowed) internal {
if (allowed && validator == address(0)) {
revert ZeroAddress();
}
additionalValidators[validator] = allowed;
emit AdditionalValidatorUpdated(validator, allowed);
}
function _setAdditionalNodeOperator(address nodeOperator, bool allowed) internal {
if (allowed && nodeOperator == address(0)) {
revert ZeroAddress();
}
additionalNodeOperators[nodeOperator] = allowed;
emit AdditionalNodeOperatorUpdated(nodeOperator, allowed);
}
function _addAgentRootNodeAlias(bytes32 node) internal {
if (node == bytes32(0)) {
revert ZeroNode();
}
if (agentRootNodeAliasSet[node] || node == agentRootNode) {
return;
}
agentRootNodeAliasSet[node] = true;
agentRootNodeAliases.push(node);
emit AgentRootNodeAliasUpdated(node, true);
}
function _removeAgentRootNodeAlias(bytes32 node) internal {
if (node == bytes32(0)) {
revert ZeroNode();
}
if (!agentRootNodeAliasSet[node]) {
return;
}
agentRootNodeAliasSet[node] = false;
uint256 len = agentRootNodeAliases.length;
for (uint256 i; i < len; i++) {
if (agentRootNodeAliases[i] == node) {
if (i != len - 1) {
agentRootNodeAliases[i] = agentRootNodeAliases[len - 1];
}
agentRootNodeAliases.pop();
break;
}
}
emit AgentRootNodeAliasUpdated(node, false);
}
function _addClubRootNodeAlias(bytes32 node) internal {
if (node == bytes32(0)) {
revert ZeroNode();
}
if (clubRootNodeAliasSet[node] || node == clubRootNode) {
return;
}
clubRootNodeAliasSet[node] = true;
clubRootNodeAliases.push(node);
emit ClubRootNodeAliasUpdated(node, true);
}
function _removeClubRootNodeAlias(bytes32 node) internal {
if (node == bytes32(0)) {
revert ZeroNode();
}
if (!clubRootNodeAliasSet[node]) {
return;
}
clubRootNodeAliasSet[node] = false;
uint256 len = clubRootNodeAliases.length;
for (uint256 i; i < len; i++) {
if (clubRootNodeAliases[i] == node) {
if (i != len - 1) {
clubRootNodeAliases[i] = clubRootNodeAliases[len - 1];
}
clubRootNodeAliases.pop();
break;
}
}
emit ClubRootNodeAliasUpdated(node, false);
}
function _addNodeRootNodeAlias(bytes32 node) internal {
if (node == bytes32(0)) {
revert ZeroNode();
}
if (nodeRootNodeAliasSet[node] || node == nodeRootNode) {
return;
}
nodeRootNodeAliasSet[node] = true;
nodeRootNodeAliases.push(node);
emit NodeRootNodeAliasUpdated(node, true);
}
function _removeNodeRootNodeAlias(bytes32 node) internal {
if (node == bytes32(0)) {
revert ZeroNode();
}
if (!nodeRootNodeAliasSet[node]) {
return;
}
nodeRootNodeAliasSet[node] = false;
uint256 len = nodeRootNodeAliases.length;
for (uint256 i; i < len; i++) {
if (nodeRootNodeAliases[i] == node) {
if (i != len - 1) {
nodeRootNodeAliases[i] = nodeRootNodeAliases[len - 1];
}
nodeRootNodeAliases.pop();
break;
}
}
emit NodeRootNodeAliasUpdated(node, false);
}
function _setAgentType(address agent, AgentType agentType) internal {
if (agent == address(0)) {
revert ZeroAddress();
}
agentTypes[agent] = agentType;
emit AgentTypeUpdated(agent, agentType);
}
function getAgentType(address agent) external view returns (AgentType) {
return agentTypes[agent];
}
// ---------------------------------------------------------------------
// Agent profile metadata
// ---------------------------------------------------------------------
/// @notice Set or overwrite an agent's capability metadata URI.
/// @dev Restricted to governance/owner.
function setAgentProfileURI(address agent, string calldata uri) external onlyOwner {
if (agent == address(0)) {
revert ZeroAddress();
}
agentProfileURI[agent] = uri;
emit AgentProfileUpdated(agent, uri);
}
/// @notice Allows an agent to update their own profile after proving identity.
/// @param subdomain ENS subdomain owned by the agent.
/// @param proof Merkle/ENS proof demonstrating control of the subdomain.
/// @param uri Metadata URI describing the agent's capabilities.
function updateAgentProfile(
string calldata subdomain,
bytes32[] calldata proof,
string calldata uri
) external {
(bool ok, , , ) = _verifyAgent(msg.sender, subdomain, proof);
if (!ok) {
revert UnauthorizedAgent();
}
agentProfileURI[msg.sender] = uri;
emit AgentProfileUpdated(msg.sender, uri);
}
// ---------------------------------------------------------------------
// Authorization helpers
// ---------------------------------------------------------------------
function _checkAgentENSOwnership(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) internal view returns (bool ok) {
_assertSubdomain(subdomain);
if (agentRootNode != bytes32(0)) {
(ok, , , ) = ENSIdentityVerifier.checkOwnership(
ens,
nameWrapper,
agentRootNode,
agentMerkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return true;
}
}
uint256 aliasLen = agentRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
(ok, , , ) = ENSIdentityVerifier.checkOwnership(
ens,
nameWrapper,
agentRootNodeAliases[i],
agentMerkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return true;
}
}
return false;
}
function _checkValidatorENSOwnership(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) internal view returns (bool ok) {
_assertSubdomain(subdomain);
if (clubRootNode != bytes32(0)) {
(ok, , , ) = ENSIdentityVerifier.checkOwnership(
ens,
nameWrapper,
clubRootNode,
validatorMerkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return true;
}
}
uint256 aliasLen = clubRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
(ok, , , ) = ENSIdentityVerifier.checkOwnership(
ens,
nameWrapper,
clubRootNodeAliases[i],
validatorMerkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return true;
}
}
return false;
}
function _checkNodeENSOwnership(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) internal view returns (bool ok) {
_assertSubdomain(subdomain);
if (nodeRootNode != bytes32(0)) {
(ok, , , ) = ENSIdentityVerifier.checkOwnership(
ens,
nameWrapper,
nodeRootNode,
validatorMerkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return true;
}
}
uint256 aliasLen = nodeRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
(ok, , , ) = ENSIdentityVerifier.checkOwnership(
ens,
nameWrapper,
nodeRootNodeAliases[i],
validatorMerkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return true;
}
}
return false;
}
function _deriveNodeFromLabel(bytes32 root, bytes32[] storage aliases, bytes32 label)
internal
view
returns (bytes32)
{
if (root != bytes32(0)) {
return keccak256(abi.encodePacked(root, label));
}
if (aliases.length != 0) {
return keccak256(abi.encodePacked(aliases[0], label));
}
return bytes32(0);
}
function _verifyOwnership(
bytes32 root,
bytes32[] storage aliases,
bytes32 merkleRoot,
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) private returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle) {
_assertSubdomain(subdomain);
if (root != bytes32(0)) {
(ok, node, viaWrapper, viaMerkle) = ENSIdentityVerifier.verifyOwnership(
ens,
nameWrapper,
root,
merkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return (true, node, viaWrapper, viaMerkle);
}
}
uint256 aliasLen = aliases.length;
for (uint256 i; i < aliasLen; i++) {
(ok, node, viaWrapper, viaMerkle) = ENSIdentityVerifier.verifyOwnership(
ens,
nameWrapper,
aliases[i],
merkleRoot,
claimant,
subdomain,
proof
);
if (ok) {
return (true, node, viaWrapper, viaMerkle);
}
}
bytes32 labelHash = keccak256(bytes(subdomain));
node = _deriveNodeFromLabel(root, aliases, labelHash);
return (false, node, false, false);
}
function _verifyAgentENSOwnership(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) internal returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle) {
return _verifyOwnership(
agentRootNode,
agentRootNodeAliases,
agentMerkleRoot,
claimant,
subdomain,
proof
);
}
function _verifyValidatorENSOwnership(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) internal returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle) {
return _verifyOwnership(
clubRootNode,
clubRootNodeAliases,
validatorMerkleRoot,
claimant,
subdomain,
proof
);
}
function _verifyNodeENSOwnership(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) internal returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle) {
return _verifyOwnership(
nodeRootNode,
nodeRootNodeAliases,
validatorMerkleRoot,
claimant,
subdomain,
proof
);
}
function isAuthorizedAgent(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) public view returns (bool) {
_assertSubdomain(subdomain);
if (
address(reputationEngine) != address(0) &&
reputationEngine.isBlacklisted(claimant)
) {
return false;
}
if (additionalAgents[claimant]) {
return true;
}
if (address(attestationRegistry) != address(0)) {
bytes32 labelHash = keccak256(bytes(subdomain));
if (agentRootNode != bytes32(0)) {
bytes32 node = keccak256(
abi.encodePacked(agentRootNode, labelHash)
);
if (
attestationRegistry.isAttested(
node,
AttestationRegistry.Role.Agent,
claimant
)
) {
return true;
}
}
uint256 aliasLen = agentRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
bytes32 aliasNode = keccak256(
abi.encodePacked(agentRootNodeAliases[i], labelHash)
);
if (
attestationRegistry.isAttested(
aliasNode,
AttestationRegistry.Role.Agent,
claimant
)
) {
return true;
}
}
}
return _checkAgentENSOwnership(claimant, subdomain, proof);
}
function isAuthorizedValidator(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) public view returns (bool) {
_assertSubdomain(subdomain);
if (
address(reputationEngine) != address(0) &&
reputationEngine.isBlacklisted(claimant)
) {
return false;
}
if (additionalValidators[claimant]) {
return true;
}
if (additionalNodeOperators[claimant]) {
return true;
}
if (address(attestationRegistry) != address(0)) {
bytes32 labelHash = keccak256(bytes(subdomain));
if (clubRootNode != bytes32(0)) {
bytes32 node = keccak256(
abi.encodePacked(clubRootNode, labelHash)
);
if (
attestationRegistry.isAttested(
node,
AttestationRegistry.Role.Validator,
claimant
)
) {
return true;
}
}
uint256 aliasLen = clubRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
bytes32 aliasNode = keccak256(
abi.encodePacked(clubRootNodeAliases[i], labelHash)
);
if (
attestationRegistry.isAttested(
aliasNode,
AttestationRegistry.Role.Validator,
claimant
)
) {
return true;
}
}
if (nodeRootNode != bytes32(0)) {
bytes32 node = keccak256(
abi.encodePacked(nodeRootNode, labelHash)
);
if (
attestationRegistry.isAttested(
node,
AttestationRegistry.Role.Node,
claimant
)
) {
return true;
}
}
uint256 nodeAliasLen = nodeRootNodeAliases.length;
for (uint256 i; i < nodeAliasLen; i++) {
bytes32 aliasNode = keccak256(
abi.encodePacked(nodeRootNodeAliases[i], labelHash)
);
if (
attestationRegistry.isAttested(
aliasNode,
AttestationRegistry.Role.Node,
claimant
)
) {
return true;
}
}
}
if (_checkValidatorENSOwnership(claimant, subdomain, proof)) {
return true;
}
return _checkNodeENSOwnership(claimant, subdomain, proof);
}
function _verifyAgent(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
)
internal
returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle)
{
_assertSubdomain(subdomain);
if (
address(reputationEngine) != address(0) &&
reputationEngine.isBlacklisted(claimant)
) {
return (false, bytes32(0), false, false);
}
bytes32 labelHash = keccak256(bytes(subdomain));
if (agentRootNode != bytes32(0)) {
node = keccak256(abi.encodePacked(agentRootNode, labelHash));
}
if (additionalAgents[claimant]) {
ok = true;
} else if (address(attestationRegistry) != address(0)) {
if (
node != bytes32(0) &&
attestationRegistry.isAttested(
node,
AttestationRegistry.Role.Agent,
claimant
)
) {
ok = true;
} else {
uint256 aliasLen = agentRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
bytes32 aliasRoot = agentRootNodeAliases[i];
bytes32 aliasNode = keccak256(
abi.encodePacked(aliasRoot, labelHash)
);
if (
attestationRegistry.isAttested(
aliasNode,
AttestationRegistry.Role.Agent,
claimant
)
) {
node = aliasNode;
ok = true;
break;
}
}
}
}
if (!ok) {
(ok, node, viaWrapper, viaMerkle) =
_verifyAgentENSOwnership(claimant, subdomain, proof);
}
}
function verifyAgent(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
)
external
returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle)
{
(ok, node, viaWrapper, viaMerkle) =
_verifyAgent(claimant, subdomain, proof);
if (ok) {
if (additionalAgents[claimant]) {
emit AdditionalAgentUsed(claimant, subdomain);
emit ENSIdentityVerifier.OwnershipVerified(claimant, subdomain);
} else if (
address(attestationRegistry) != address(0) &&
attestationRegistry.isAttested(
node,
AttestationRegistry.Role.Agent,
claimant
)
) {
emit ENSIdentityVerifier.OwnershipVerified(claimant, subdomain);
}
emit IdentityVerified(
claimant,
AttestationRegistry.Role.Agent,
node,
subdomain
);
emit ENSVerified(claimant, node, subdomain, viaWrapper, viaMerkle);
} else {
emit IdentityVerificationFailed(
claimant,
AttestationRegistry.Role.Agent,
subdomain
);
}
}
function _verifyNode(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
) internal returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle) {
_assertSubdomain(subdomain);
if (
address(reputationEngine) != address(0) &&
reputationEngine.isBlacklisted(claimant)
) {
return (false, bytes32(0), false, false);
}
bytes32 labelHash = keccak256(bytes(subdomain));
bytes32 derivedNode = _deriveNodeFromLabel(
nodeRootNode,
nodeRootNodeAliases,
labelHash
);
if (additionalNodeOperators[claimant]) {
emit AdditionalNodeOperatorUsed(claimant, subdomain);
emit ENSIdentityVerifier.OwnershipVerified(claimant, subdomain);
return (true, derivedNode, false, false);
}
if (address(attestationRegistry) != address(0)) {
if (
derivedNode != bytes32(0) &&
attestationRegistry.isAttested(
derivedNode,
AttestationRegistry.Role.Node,
claimant
)
) {
emit ENSIdentityVerifier.OwnershipVerified(claimant, subdomain);
return (true, derivedNode, false, false);
}
uint256 aliasLen = nodeRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
bytes32 aliasRoot = nodeRootNodeAliases[i];
bytes32 aliasNode = keccak256(
abi.encodePacked(aliasRoot, labelHash)
);
if (
attestationRegistry.isAttested(
aliasNode,
AttestationRegistry.Role.Node,
claimant
)
) {
emit ENSIdentityVerifier.OwnershipVerified(
claimant,
subdomain
);
return (true, aliasNode, false, false);
}
}
}
(ok, node, viaWrapper, viaMerkle) = _verifyNodeENSOwnership(
claimant,
subdomain,
proof
);
if (ok) {
emit ENSIdentityVerifier.OwnershipVerified(claimant, subdomain);
}
return (ok, node, viaWrapper, viaMerkle);
}
function verifyValidator(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
)
external
returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle)
{
_assertSubdomain(subdomain);
if (
address(reputationEngine) != address(0) &&
reputationEngine.isBlacklisted(claimant)
) {
return (false, bytes32(0), false, false);
}
bytes32 labelHash = keccak256(bytes(subdomain));
bytes32 validatorNode = _deriveNodeFromLabel(
clubRootNode,
clubRootNodeAliases,
labelHash
);
node = validatorNode;
if (additionalValidators[claimant]) {
emit AdditionalValidatorUsed(claimant, subdomain);
emit ENSIdentityVerifier.OwnershipVerified(claimant, subdomain);
ok = true;
} else if (address(attestationRegistry) != address(0)) {
if (
validatorNode != bytes32(0) &&
attestationRegistry.isAttested(
validatorNode,
AttestationRegistry.Role.Validator,
claimant
)
) {
emit ENSIdentityVerifier.OwnershipVerified(claimant, subdomain);
node = validatorNode;
ok = true;
} else {
uint256 aliasLen = clubRootNodeAliases.length;
for (uint256 i; i < aliasLen; i++) {
bytes32 aliasRoot = clubRootNodeAliases[i];
bytes32 aliasNode = keccak256(
abi.encodePacked(aliasRoot, labelHash)
);
if (
attestationRegistry.isAttested(
aliasNode,
AttestationRegistry.Role.Validator,
claimant
)
) {
emit ENSIdentityVerifier.OwnershipVerified(
claimant,
subdomain
);
node = aliasNode;
ok = true;
break;
}
}
}
}
if (!ok) {
(ok, node, viaWrapper, viaMerkle) = _verifyValidatorENSOwnership(
claimant,
subdomain,
proof
);
if (!ok) {
(ok, node, viaWrapper, viaMerkle) = _verifyNode(
claimant,
subdomain,
proof
);
}
}
if (ok) {
emit IdentityVerified(
claimant,
AttestationRegistry.Role.Validator,
node,
subdomain
);
emit ENSVerified(claimant, node, subdomain, viaWrapper, viaMerkle);
} else {
emit IdentityVerificationFailed(
claimant,
AttestationRegistry.Role.Validator,
subdomain
);
}
}
function verifyNode(
address claimant,
string calldata subdomain,
bytes32[] calldata proof
)
external
returns (bool ok, bytes32 node, bool viaWrapper, bool viaMerkle)
{
(ok, node, viaWrapper, viaMerkle) = _verifyNode(claimant, subdomain, proof);
if (ok) {
emit IdentityVerified(
claimant,
AttestationRegistry.Role.Node,
node,
subdomain
);
emit ENSVerified(claimant, node, subdomain, viaWrapper, viaMerkle);
} else {
emit IdentityVerificationFailed(
claimant,
AttestationRegistry.Role.Node,
subdomain
);
}
}
/// @notice Confirms the contract and its owner can never incur tax liability.
/// @return Always true, signalling perpetual tax exemption.
function isTaxExempt() external pure returns (bool) {
return true;
}
// ---------------------------------------------------------------
// Ether rejection
// ---------------------------------------------------------------
/// @dev Reject direct ETH transfers to keep the contract tax neutral.
receive() external payable {
revert EtherNotAccepted();
}
/// @dev Reject calls with unexpected calldata or funds.
fallback() external payable {
revert EtherNotAccepted();
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
@openzeppelin/contracts/utils/Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
@openzeppelin/contracts/utils/cryptography/Hashes.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/Hashes.sol)
pragma solidity ^0.8.20;
/**
* @dev Library of standard hash functions.
*
* _Available since v5.1._
*/
library Hashes {
/**
* @dev Commutative Keccak256 hash of a sorted pair of bytes32. Frequently used when working with merkle proofs.
*
* NOTE: Equivalent to the `standardNodeHash` in our https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
*/
function commutativeKeccak256(bytes32 a, bytes32 b) internal pure returns (bytes32) {
return a < b ? efficientKeccak256(a, b) : efficientKeccak256(b, a);
}
/**
* @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
*/
function efficientKeccak256(bytes32 a, bytes32 b) internal pure returns (bytes32 value) {
assembly ("memory-safe") {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
@openzeppelin/contracts/utils/cryptography/MerkleProof.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/MerkleProof.sol)
// This file was procedurally generated from scripts/generate/templates/MerkleProof.js.
pragma solidity ^0.8.20;
import {Hashes} from "./Hashes.sol";
/**
* @dev These functions deal with verification of Merkle Tree proofs.
*
* The tree and the proofs can be generated using our
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
* You will find a quickstart guide in the readme.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the Merkle tree could be reinterpreted as a leaf value.
* OpenZeppelin's JavaScript library generates Merkle trees that are safe
* against this attack out of the box.
*
* IMPORTANT: Consider memory side-effects when using custom hashing functions
* that access memory in an unsafe way.
*
* NOTE: This library supports proof verification for merkle trees built using
* custom _commutative_ hashing functions (i.e. `H(a, b) == H(b, a)`). Proving
* leaf inclusion in trees built using non-commutative hashing functions requires
* additional logic that is not supported by this library.
*/
library MerkleProof {
/**
*@dev The multiproof provided is not valid.
*/
error MerkleProofInvalidMultiproof();
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*
* This version handles proofs in memory with the default hashing function.
*/
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leaves & pre-images are assumed to be sorted.
*
* This version handles proofs in memory with the default hashing function.
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*
* This version handles proofs in memory with a custom hashing function.
*/
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bool) {
return processProof(proof, leaf, hasher) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leaves & pre-images are assumed to be sorted.
*
* This version handles proofs in memory with a custom hashing function.
*/
function processProof(
bytes32[] memory proof,
bytes32 leaf,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = hasher(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*
* This version handles proofs in calldata with the default hashing function.
*/
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leaves & pre-images are assumed to be sorted.
*
* This version handles proofs in calldata with the default hashing function.
*/
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*
* This version handles proofs in calldata with a custom hashing function.
*/
function verifyCalldata(
bytes32[] calldata proof,
bytes32 root,
bytes32 leaf,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bool) {
return processProofCalldata(proof, leaf, hasher) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leaves & pre-images are assumed to be sorted.
*
* This version handles proofs in calldata with a custom hashing function.
*/
function processProofCalldata(
bytes32[] calldata proof,
bytes32 leaf,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = hasher(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* This version handles multiproofs in memory with the default hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProof}.
*/
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* This version handles multiproofs in memory with the default hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the Merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofFlagsLen = proofFlags.length;
// Check proof validity.
if (leavesLen + proof.length != proofFlagsLen + 1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](proofFlagsLen);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < proofFlagsLen; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = Hashes.commutativeKeccak256(a, b);
}
if (proofFlagsLen > 0) {
if (proofPos != proof.length) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[proofFlagsLen - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* This version handles multiproofs in memory with a custom hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProof}.
*/
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bool) {
return processMultiProof(proof, proofFlags, leaves, hasher) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* This version handles multiproofs in memory with a custom hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the Merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofFlagsLen = proofFlags.length;
// Check proof validity.
if (leavesLen + proof.length != proofFlagsLen + 1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](proofFlagsLen);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < proofFlagsLen; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = hasher(a, b);
}
if (proofFlagsLen > 0) {
if (proofPos != proof.length) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[proofFlagsLen - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* This version handles multiproofs in calldata with the default hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProofCalldata}.
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* This version handles multiproofs in calldata with the default hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the Merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofFlagsLen = proofFlags.length;
// Check proof validity.
if (leavesLen + proof.length != proofFlagsLen + 1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](proofFlagsLen);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < proofFlagsLen; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = Hashes.commutativeKeccak256(a, b);
}
if (proofFlagsLen > 0) {
if (proofPos != proof.length) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[proofFlagsLen - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* This version handles multiproofs in calldata with a custom hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProofCalldata}.
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves, hasher) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* This version handles multiproofs in calldata with a custom hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves,
function(bytes32, bytes32) view returns (bytes32) hasher
) internal view returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the Merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofFlagsLen = proofFlags.length;
// Check proof validity.
if (leavesLen + proof.length != proofFlagsLen + 1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](proofFlagsLen);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < proofFlagsLen; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = hasher(a, b);
}
if (proofFlagsLen > 0) {
if (proofPos != proof.length) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[proofFlagsLen - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
}
contracts/v2/AttestationRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {IENS} from "./interfaces/IENS.sol";
import {INameWrapper} from "./interfaces/INameWrapper.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
error UnauthorizedAttestor();
error ZeroAddress();
/// @title AttestationRegistry
/// @notice Allows ENS name owners to grant and revoke attestations
/// for specific roles to other addresses.
contract AttestationRegistry is Ownable, Pausable {
/// @dev Roles that can be attested for a name.
enum Role {
Agent,
Validator,
Node
}
IENS public ens;
INameWrapper public nameWrapper;
/// @notice Mapping of node => role => address => attested
mapping(bytes32 => mapping(Role => mapping(address => bool))) public attestations;
event ENSUpdated(address indexed ens);
event NameWrapperUpdated(address indexed nameWrapper);
event Attested(bytes32 indexed node, Role indexed role, address indexed who, address attestor);
event Revoked(bytes32 indexed node, Role indexed role, address indexed who, address attestor);
constructor(IENS _ens, INameWrapper _nameWrapper) Ownable(msg.sender) {
ens = _ens;
if (address(_ens) != address(0)) {
emit ENSUpdated(address(_ens));
}
nameWrapper = _nameWrapper;
if (address(_nameWrapper) != address(0)) {
emit NameWrapperUpdated(address(_nameWrapper));
}
}
function setENS(address ensAddr) external onlyOwner {
if (ensAddr == address(0)) {
revert ZeroAddress();
}
ens = IENS(ensAddr);
emit ENSUpdated(ensAddr);
}
function setNameWrapper(address wrapper) external onlyOwner {
if (wrapper == address(0)) {
revert ZeroAddress();
}
nameWrapper = INameWrapper(wrapper);
emit NameWrapperUpdated(wrapper);
}
function _ownerOf(bytes32 node) internal view returns (address) {
if (address(nameWrapper) != address(0)) {
try nameWrapper.ownerOf(uint256(node)) returns (address owner) {
if (owner != address(0)) {
return owner;
}
} catch {}
}
if (address(ens) != address(0)) {
try ens.owner(node) returns (address ensOwner) {
return ensOwner;
} catch {}
}
return address(0);
}
/// @notice Attest that `who` holds `role` for `node`.
function attest(bytes32 node, Role role, address who) external whenNotPaused {
if (who == address(0)) {
revert ZeroAddress();
}
if (_ownerOf(node) != msg.sender) {
revert UnauthorizedAttestor();
}
attestations[node][role][who] = true;
emit Attested(node, role, who, msg.sender);
}
/// @notice Revoke a previously granted attestation.
function revoke(bytes32 node, Role role, address who) external whenNotPaused {
if (_ownerOf(node) != msg.sender) {
revert UnauthorizedAttestor();
}
attestations[node][role][who] = false;
emit Revoked(node, role, who, msg.sender);
}
/// @notice Pause attestation mutations in case of compromise.
function pause() external onlyOwner {
_pause();
}
/// @notice Resume attestation mutations after recovery.
function unpause() external onlyOwner {
_unpause();
}
/// @notice Check whether `who` has been attested for `role` on `node`.
function isAttested(bytes32 node, Role role, address who) external view returns (bool) {
return attestations[node][role][who];
}
}
contracts/v2/ENSIdentityVerifier.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import {IENS} from "./interfaces/IENS.sol";
import {INameWrapper} from "./interfaces/INameWrapper.sol";
import {IAddrResolver} from "./interfaces/IAddrResolver.sol";
/// @title ENSIdentityVerifier
/// @notice Library providing ENS ownership verification via Merkle proofs,
/// NameWrapper, and resolver lookups. Emits events on success or recovery
/// conditions.
library ENSIdentityVerifier {
event OwnershipVerified(address indexed claimant, string subdomain);
event RecoveryInitiated(string reason);
function checkOwnership(
IENS ens,
INameWrapper nameWrapper,
bytes32 rootNode,
bytes32 merkleRoot,
address claimant,
string memory subdomain,
bytes32[] calldata proof
)
internal
view
returns (bool ok, bytes32 subnode, bool viaWrapper, bool viaMerkle)
{
bytes32 labelHash = keccak256(bytes(subdomain));
subnode = keccak256(abi.encodePacked(rootNode, labelHash));
bytes32 leaf = keccak256(abi.encode(claimant, labelHash));
if (MerkleProof.verifyCalldata(proof, merkleRoot, leaf)) {
return (true, subnode, false, true);
}
try nameWrapper.ownerOf(uint256(subnode)) returns (address actualOwner) {
if (actualOwner == claimant) {
return (true, subnode, true, false);
}
} catch {}
if (address(ens) != address(0)) {
address resolverAddr = ens.resolver(subnode);
if (resolverAddr != address(0)) {
try IAddrResolver(resolverAddr).addr(subnode) returns (
address resolvedAddress
) {
if (resolvedAddress == claimant) {
return (true, subnode, false, false);
}
} catch {}
}
}
return (false, subnode, false, false);
}
function verifyOwnership(
IENS ens,
INameWrapper nameWrapper,
bytes32 rootNode,
bytes32 merkleRoot,
address claimant,
string memory subdomain,
bytes32[] calldata proof
)
internal
returns (bool ok, bytes32 subnode, bool viaWrapper, bool viaMerkle)
{
bytes32 labelHash = keccak256(bytes(subdomain));
subnode = keccak256(abi.encodePacked(rootNode, labelHash));
bytes32 leaf = keccak256(abi.encode(claimant, labelHash));
if (MerkleProof.verifyCalldata(proof, merkleRoot, leaf)) {
emit OwnershipVerified(claimant, subdomain);
return (true, subnode, false, true);
}
bool eventEmitted;
try nameWrapper.ownerOf(uint256(subnode)) returns (address actualOwner) {
if (actualOwner == claimant) {
emit OwnershipVerified(claimant, subdomain);
return (true, subnode, true, false);
}
} catch Error(string memory reason) {
emit RecoveryInitiated(reason);
eventEmitted = true;
} catch {
emit RecoveryInitiated(
"NameWrapper call failed without a specified reason."
);
eventEmitted = true;
}
if (address(ens) != address(0)) {
address resolverAddr = ens.resolver(subnode);
if (resolverAddr != address(0)) {
IAddrResolver resolver = IAddrResolver(resolverAddr);
try resolver.addr(subnode) returns (
address resolvedAddress
) {
if (resolvedAddress == claimant) {
emit OwnershipVerified(claimant, subdomain);
return (true, subnode, false, false);
}
if (!eventEmitted) {
emit RecoveryInitiated("Resolver address mismatch.");
eventEmitted = true;
}
} catch {
if (!eventEmitted) {
emit RecoveryInitiated(
"Resolver call failed without a specified reason."
);
eventEmitted = true;
}
}
} else {
if (!eventEmitted) {
emit RecoveryInitiated("Resolver address not found for node.");
eventEmitted = true;
}
}
} else {
if (!eventEmitted) {
emit RecoveryInitiated("ENS not configured.");
eventEmitted = true;
}
}
if (!eventEmitted) {
emit RecoveryInitiated("Ownership verification failed.");
}
return (false, subnode, false, false);
}
}
contracts/v2/interfaces/IAddrResolver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
interface IAddrResolver {
function addr(bytes32 node) external view returns (address);
}
contracts/v2/interfaces/IENS.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
/// @title IENS
/// @notice Minimal interface for retrieving resolver addresses from the ENS registry.
interface IENS {
/// @notice Get resolver address for a node.
/// @param node The ENS node hash.
/// @return resolverAddr Address of the resolver for `node`.
function resolver(bytes32 node) external view returns (address resolverAddr);
/// @notice Get the owner of an ENS node.
/// @param node The ENS node hash.
/// @return ownerAddr Address of the owner for `node`.
function owner(bytes32 node) external view returns (address ownerAddr);
}
contracts/v2/interfaces/INameWrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
/// @title INameWrapper
/// @notice Minimal interface to check ownership of wrapped ENS names.
interface INameWrapper {
/// @notice Get the owner of a wrapped ENS name.
/// @param id The namehash of the ENS name.
/// @return owner Address of the owner.
function ownerOf(uint256 id) external view returns (address owner);
}
contracts/v2/interfaces/IReputationEngine.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
/// @title IReputationEngine
/// @notice Interface for tracking and updating participant reputation scores
interface IReputationEngine {
/// @notice Module version for compatibility checks.
function version() external view returns (uint256);
/// @dev Reverts when a caller is not authorised to update reputation
error UnauthorizedCaller(address caller);
/// @dev Reverts when attempting to act on a blacklisted user
error BlacklistedUser(address user);
/// @dev Reverts when array lengths for validator context mismatch
error ArrayLengthMismatch();
event ReputationUpdated(address indexed user, int256 delta, uint256 newScore);
event BlacklistUpdated(address indexed user, bool status);
event StakeManagerUpdated(address stakeManager);
event ScoringWeightsUpdated(uint256 stakeWeight, uint256 reputationWeight);
/// @notice Increase a user's reputation score
/// @param user Address whose reputation is increased
/// @param amount Amount to add to the user's score
/// @dev Reverts with {UnauthorizedCaller} if caller is not permitted
/// or {BlacklistedUser} if the user is blacklisted
function add(address user, uint256 amount) external;
/// @notice Decrease a user's reputation score
/// @param user Address whose reputation is decreased
/// @param amount Amount to subtract from the user's score
/// @dev Reverts with {UnauthorizedCaller} if caller is not permitted
/// or {BlacklistedUser} if the user is blacklisted
function subtract(address user, uint256 amount) external;
/// @notice Retrieve a user's reputation score
/// @param user Address to query
/// @return The current reputation score of the user
function reputation(address user) external view returns (uint256);
/// @notice Alias for {reputation} for backwards compatibility
function getReputation(address user) external view returns (uint256);
/// @notice Alternate view to mirror v1 naming
function reputationOf(address user) external view returns (uint256);
/// @notice Retrieve accumulated entropy penalties for a user
/// @param user Address to query
/// @return The current entropy score of the user
function entropy(address user) external view returns (uint256);
/// @notice Alias for {entropy}
function getEntropy(address user) external view returns (uint256);
/// @notice Alternate view for legacy naming
function entropyOf(address user) external view returns (uint256);
/// @notice Check if a user is blacklisted
/// @param user Address to query
/// @return True if the user is blacklisted
function isBlacklisted(address user) external view returns (bool);
/// @notice Determine whether a user meets the premium access threshold
/// @param user Address to query
/// @return True if the user's reputation meets or exceeds the threshold
function meetsThreshold(address user) external view returns (bool);
/// @notice Owner functions
/// @notice Allow or disallow a caller to update reputation
/// @param caller Address of the caller to configure
/// @param allowed True to authorise the caller, false to revoke
function setCaller(address caller, bool allowed) external;
/// @notice Backwards compatible alias for {setCaller}
function setAuthorizedCaller(address caller, bool allowed) external;
/// @notice Set the minimum score threshold for certain actions
function setThreshold(uint256 newThreshold) external;
/// @notice Set premium reputation threshold
function setPremiumThreshold(uint256 newThreshold) external;
/// @notice Add or remove a user from the blacklist
/// @param user Address to update
/// @param status True to blacklist the user, false to remove
function setBlacklist(address user, bool status) external;
/// @notice Job lifecycle hooks
function onApply(address user) external view;
function onFinalize(address user, bool success, uint256 payout, uint256 duration) external;
function rewardValidator(address validator, uint256 agentGain) external;
/// @notice Update agent and validator reputation for a completed job.
/// @param jobId Identifier of the job being settled.
/// @param agent Address of the agent that executed the job.
/// @param validators Validator committee that assessed the job.
/// @param success True if the job was approved by validators.
/// @param validatorRevealed Flags indicating whether each validator revealed their vote.
/// @param validatorVotes Recorded vote for each validator (true = approval).
/// @param payout Agent payout expressed with 18 decimals.
/// @param duration Time elapsed between assignment and completion in seconds.
function updateScores(
uint256 jobId,
address agent,
address[] calldata validators,
bool success,
bool[] calldata validatorRevealed,
bool[] calldata validatorVotes,
uint256 payout,
uint256 duration
) external;
/// @notice Compute reputation gain for an agent based on payout and duration.
/// @param payout Amount paid to the agent (18-decimal).
/// @param duration Job duration in seconds.
/// @return Reputation points awarded to the agent.
function calculateReputationPoints(uint256 payout, uint256 duration)
external
view
returns (uint256);
/// @notice Retrieve combined operator score using stake and reputation
/// @param operator Address to query
/// @return Weighted score used for ranking
function getOperatorScore(address operator) external view returns (uint256);
/// @notice Set the StakeManager used for stake lookups
/// @param manager Address of the StakeManager contract
function setStakeManager(address manager) external;
/// @notice Update weighting factors for stake and reputation contributions
/// @param stakeWeight Weight applied to stake (scaled by TOKEN_SCALE)
/// @param reputationWeight Weight applied to reputation (scaled by TOKEN_SCALE)
function setScoringWeights(uint256 stakeWeight, uint256 reputationWeight) external;
}
contracts/v2/utils/Ownable2Step.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step as OpenZeppelinOwnable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
/// @title Ownable2Step
/// @dev Extends OpenZeppelin's Ownable2Step by exposing a constructor
/// that forwards the initial owner to the underlying Ownable base.
abstract contract Ownable2Step is OpenZeppelinOwnable2Step {
constructor(address initialOwner) Ownable(initialOwner) {}
}
Настройки компилятораПоказать
{
"viaIR": true,
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.