Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC7777, which proposes a mechanism for humans and robots to establish identities on a blockchain on equal terms and cooperate under shared rules.

The following material is translated, summarized, and supplemented with explanations.

I have also covered various EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.

Overview

ERC7777 defines two main interfaces: IUniversalIdentity and IUniversalCharter. They provide mechanisms for humans and robots to establish their own identities and form decentralized communities governed by specific rules.

IUniversalIdentity

The IUniversalIdentity interface aims to ensure fair and equal treatment of non-human intelligent computational constructs, such as robots. It enables robots to establish their own on-chain identities (identities recorded on a blockchain) and interact and transact in the same way as humans.

The interface also includes a mechanism for hardware-based identity verification. Specifically, a robot uses secure hardware (a secure chip) to generate a cryptographic signature, which is verified through challenge-response authentication. This allows other humans and robots to verify the robot's identity cryptographically.

IUniversalCharter

The IUniversalCharter interface provides a framework for humans and robots to create, join, maintain, leave, and terminate societies (communities) governed by a predefined rule set. Participants, both human and robotic, can form autonomously governed societies and pursue cooperation and mutual prosperity.

These interfaces aim to make interactions between humans and robots on decentralized systems efficient and transparent, enabling them to coexist safely.

Motivation

Background

The human brain can be considered a highly parallel biological computer. It processes information through a complex combination of chemical reactions and electrical signals, fundamentally different from conventional electronic computers. Non-human intelligent computers, such as robots and AI, instead consist of electronic hardware and software. Given these differences, human society may soon need new mechanisms to coexist and collaborate with self-aware non-human computers, such as robots.

Current Challenges

Human societies today predominantly determine applicable rules based on nationality and place of birth, whereas robots lack comparable concepts of birthplace and time of birth. This creates several problems.

Challenge Description
Lack of identification Robots cannot hold official identification such as passports.
Unclear applicable rules It is unclear which laws and rules apply to robots.
Difficulty participating in financial systems Existing banking systems are designed around humans and are inaccessible to robots.
Lack of legal protection If a robot suffers damage, no court is specified in which it can seek redress.

These problems are difficult to address using traditional, geographically constrained systems.

The Blockchain-Based Solution

A blockchain is a geographically unrestricted decentralized public computer that treats all computational participants, whether human or robotic, on equal terms. This characteristic offers the following benefits.

  • An equitable environment that does not distinguish between humans and robots.
  • Tamper resistance and transparency.
  • Consistent rules across the world.

Smart contracts, in particular, allow the rights and obligations of participants to be managed explicitly and automatically.

Purpose of the Proposal

ERC7777 aims to establish a standard interface for a global society in which humans and robots can coexist.

This simplifies the design and implementation of numerous possible social rule sets, allowing anyone to create, join, and terminate societies through a common mechanism.

Two Main Objectives

Creating and Managing Robot Identities

To operate on-chain, robots need trustworthy identities. In this mechanism, each robot is represented by a smart contract. The robot registers information such as its manufacturer, operator, model number, serial number, and public key, and proves its authenticity with signatures generated by a secure element embedded in its hardware.

This enables the following.

  • Tamper-resistant identity records that can also be verified against physical hardware.
  • Clear attribution of actions to individual robots.
  • Transparent relationships in which accountability can be shared with humans.
Creating and Enforcing Rules

Humans and robots need a common rule set to cooperate. The proposal establishes a decentralized governance system running on Ethereum.

Specifically, societies are formed through the following steps.

  1. Create a smart contract defining the rules.
  2. Humans and robots join (register with) the contract.
  3. The contract automatically monitors and checks compliance with the rules.

Multiple societies with different rule sets can also coexist, allowing flexible designs tailored to different purposes.

Specification

IUniversalIdentity

js
interface IUniversalIdentity {

    /// @notice Structure for hardware identity
    struct HardwareIdentity {
        bytes32 publicKey;            // Hardware-bound public key uniquely tied to this robot
        string manufacturer;           // Identifier for the robot's manufacturer
        string operator;               // Identifier for the robot's operator
        string model;                  // Model identifier of the robot
        string serialNumber;           // Unique serial number for the robot
        bytes32 initialHashSignature;  // Signature of the initial system state hash (e.g., firmware, OS) by the root key
        bytes32 currentHashSignature;  // Signature of the latest state hash, updated periodically for integrity verification by the root key
    }

    /// @notice Gets the hardware identity info
    /// @return HardwareIdentity Current hardware identity
    function getHardwareIdentity() external view returns (HardwareIdentity memory);

    /// @notice Generates a new challenge for hardware verification
    /// @return bytes32 Random challenge that needs to be signed
    function generateChallenge() external returns (bytes32);
  
    /// @notice Verify response to a specific challenge
    /// @param challenge The challenge that was issued
    /// @param signature Hardware signature of the challenge
    /// @return bool True if signature is valid for this challenge
    function verifyChallenge(bytes32 challenge, bytes memory signature) external returns (bool);

    /// @notice Adds a rule to the robot's identity, showing that the robot agrees to follow the rule.
    /// @param rule The dynamic byte array representing the rule that the robot agrees to follow. Each rule is a textual string encoded into a dynamic byte array. For example: 'A robot must keep a 1m distance from humans.'
    /// @dev The rule SHOULD come from the rule sets defined in the IUniversalCharter contract that the robot intends to join. 
    /// @dev This function SHOULD be implemented by contracts to add the rules that the robot intends to follow.
    function addRule(bytes memory rule) external;

    /// @notice Removes a rule from the robot's identity.
    /// @param rule The dynamic byte array representing the rule that the robot no longer agrees to follow.
    /// @dev This function SHOULD be implemented by contracts to remove the rules that the robot does not intend to follow.
    function removeRule(bytes memory rule) external;

    /// @notice Checks if the robot complies with a specific rule.
    /// @param rule The rule to check.
    /// @return bool Returns true if the robot complies with the rule.
    /// @dev This function MUST be implemented by contracts for compliance verification.
    function checkCompliance(bytes memory rule) external view returns (bool);

    /// @dev Emitted when a rule is added to the robot's identity.
    event RuleAdded(bytes rule);

    /// @dev Emitted when a rule is removed from the robot's identity.
    event RuleRemoved(bytes rule);
  
    /// @dev Emitted when a charter is subscribed to.
    event SubscribedToCharter(address indexed charter);

    /// @dev Emitted when it is unsubscribed from a charter.
    event UnsubscribedFromCharter(address indexed charter);
}

IUniversalIdentity is an interface for representing a robot's identity on a blockchain and enabling identity verification and compliance checks. This allows a physical robot to prove its identity cryptographically and be treated as an entity subject to established rules.

HardwareIdentity

javascript
struct HardwareIdentity {
    bytes32 publicKey;
    string manufacturer;
    string operator;
    string model;
    string serialNumber;
    bytes32 initialHashSignature;
    bytes32 currentHashSignature;
}

A struct containing hardware-specific information about a robot. This struct is intended to establish the robot's physical and cryptographic uniqueness. Robots use keys and signatures generated through secure hardware (a secure element) to establish their identities in a tamper-resistant manner.

Parameters

  • publicKey
    • A hardware-specific public key associated with the robot.
  • manufacturer
    • An identifier for the robot's manufacturer.
  • operator
    • An identifier for the entity operating and managing the robot.
  • model
    • The robot's model name.
  • serialNumber
    • A unique serial number.
  • initialHashSignature
    • A signature produced by signing the hash of the initial state, such as firmware or the operating system, with the root key.
  • currentHashSignature
    • A signature produced periodically over the latest state hash to verify integrity.

getHardwareIdentity

javascript
function getHardwareIdentity() external view returns (HardwareIdentity memory);

Retrieves the robot's hardware information. It exposes the robot's registered information, including its manufacturer, model, and signatures. Other contracts and users can use this information to verify the robot's authenticity.

Return Value

  • HardwareIdentity
    • The robot's currently registered hardware information.

generateChallenge

javascript
function generateChallenge() external returns (bytes32);

Generates an authentication challenge. During robot identity verification, a random challenge is generated, and the robot proves its authenticity by signing the challenge and returning the signature. This method is called challenge-response authentication.

Return Value

  • bytes32
    • The challenge that the robot must sign.

verifyChallenge

javascript
function verifyChallenge(bytes32 challenge, bytes memory signature) external returns (bool);

Verifies whether the signature returned by a robot is valid. It checks the response signed by the robot's hardware for the issued challenge. If the signature corresponds to the robot's public key, the robot is authenticated.

Arguments

  • challenge
    • The issued challenge.
  • signature
    • The signature returned by the robot.

Return Value

  • bool
    • Returns true if the signature is valid.

addRule

javascript
function addRule(bytes memory rule) external;

Allows a robot to accept a new rule. By adding rules defined in an IUniversalCharter contract, a robot establishes its obligations as a member of that society. Rules are passed as variable-length byte arrays and described in string form.

Arguments

  • rule
    • Example: Robots must remain at least 1 m away from humans.

removeRule

javascript
function removeRule(bytes memory rule) external;

Removes a rule that a robot follows. It is used when a rule is no longer necessary or when replacing rules to join another society. This enables flexible self-management by the robot.

Arguments

  • rule
    • A byte array encoding the string of the rule to remove.

checkCompliance

javascript
function checkCompliance(bytes memory rule) external view returns (bool);

Checks whether a robot complies with a particular rule. It verifies whether the robot follows a rule that it has added. Other contracts can also call this function to check compliance.

Arguments

  • rule
    • The rule to check.

Return Value

  • bool
    • Returns true if the rule is followed.

RuleAdded

javascript
event RuleAdded(bytes rule);

An event emitted when a rule is added. It records the robot's adoption of a new rule on the blockchain. This enables external tracking and auditing.

Parameters

  • rule
    • The rule that was added.

RuleRemoved

javascript
event RuleRemoved(bytes rule);

An event emitted when a rule is removed. It records that the robot has abandoned a rule. Keeping this history preserves transparency.

Parameters

  • rule
    • The rule that was removed.

SubscribedToCharter

javascript
event SubscribedToCharter(address indexed charter);

An event emitted when a robot joins a new charter. It enables tracking which charter (society) the robot has joined.

Parameters

  • charter
    • The address of the charter that was joined.

UnsubscribedFromCharter

javascript
event UnsubscribedFromCharter(address indexed charter);

An event emitted when a robot leaves a charter. It records the departure on the blockchain, allowing transparent management of membership history.

Parameters

  • charter
    • The address of the charter that was left.

IUniversalCharter

js
interface IUniversalCharter {

    // Define the user types as an enum.
    enum UserType { Human, Robot }

    /// @notice Registers a user (human or robot) to join the system by agreeing to a rule set.
    /// @param userType The type of user.
    /// @param ruleSet The array of individual rules the user agrees to follow. 
    /// @dev This function MUST be implemented by contracts using this interface.
    /// @dev The implementing contract MUST ensure that the user complies with the specified rule set before registering them in the system by invoking `checkCompliance`.
    function registerUser(UserType userType, bytes[] memory ruleSet) external;

    /// @notice Allows a user (human or robot) to leave the system 
    /// @dev This function MUST be callable only by the user themselves (via `msg.sender`). 
    /// @dev The implementing contract MUST ensure that the user has complied with all necessary rules before they can successfully leave the system by invoking `checkCompliance`.
    function leaveSystem() external;

    /// @notice Checks if the user (human or robot) complies with the system’s rules.
    /// @param user Address of the user (human or robot).
    /// @param ruleSet The array of individual rules to verify. 
    /// @return bool Returns true if the user complies with the rule set.
    /// @dev This function SHOULD invoke the `checkCompliance` function of the user’s IUniversalIdentity contract to check for rules individually. 
    /// @dev This function MUST be implemented by contracts for compliance verification.
    function checkCompliance(address user, bytes[] memory ruleSet) external view returns (bool);

    /// @notice Updates the rule set.
    /// @param newRuleSet The array of new individual rules replacing the existing ones. 
    /// @dev This function SHOULD be restricted to authorized users (e.g., contract owner).
    function updateRuleSet(bytes[] memory newRuleSet) external;

    /// @notice Terminates the contract, preventing any further registrations or interactions.
    /// @dev This function SHOULD be restricted to authorized users (e.g., contract owner).
    /// @dev This function SHOULD be implemented by contracts.
    function terminateContract() external;

    /// @dev Emitted when a user joins the system by agreeing to a set of rules.
    event UserRegistered(address indexed user, UserType userType, bytes[] ruleSet);

    /// @dev Emitted when a user successfully leaves the system after fulfilling obligations.
    event UserLeft(address indexed user);

    /// @dev Emitted when a user’s compliance with a rule set is verified.
    event ComplianceChecked(address indexed user, bytes[] ruleSet);

    /// @dev Emitted when a rule set is updated.
    event RuleSetUpdated(bytes[] newRuleSet, address updatedBy);
}

IUniversalCharter is an interface for managing societies (communities) in which humans and robots participate. It defines membership, departure, rule updates, and compliance checks.

UserType

javascript
enum UserType { Human, Robot }

An enumeration identifying the type of user. Distinguishing between humans and robots allows appropriate rules and processes to be applied to each. This is more efficient and less error-prone than using strings.

registerUser

javascript
function registerUser(UserType userType, bytes[] memory ruleSet) external;

Registers a human or robot in the system. Users must agree to the charter's rule set when joining. Before registration, checkCompliance is called to verify compliance with the rules.

Arguments

  • userType
    • The type of user to register (Human or Robot).
  • ruleSet
    • The set of rules being accepted.

leaveSystem

javascript
function leaveSystem() external;

Allows a user to leave the system. The user can call it directly, and departure is approved after verifying that all obligations (rules) have been fulfilled.

checkCompliance

javascript
function checkCompliance(address user, bytes[] memory ruleSet) external view returns (bool);

Checks whether a user complies with the rules. It calls checkCompliance on the IUniversalIdentity contract to check individual rules. This function helps maintain order and trust throughout the society.

Arguments

  • user
    • The address of the user being checked.
  • ruleSet
    • An array of rules to verify.

Return Value

  • bool
    • true if all rules are followed.

updateRuleSet

javascript
function updateRuleSet(bytes[] memory newRuleSet) external;

Updates the rule set. Existing rules can be replaced with new rules. Only the contract administrator is permitted to execute this function.

Arguments

  • newRuleSet
    • An array of new rules.

terminateContract

javascript
function terminateContract() external;

Terminates the charter. It halts all activity and prevents new registrations or operations. This allows the system to be shut down safely.

Events

Event Description
UserRegistered Emitted when a new user is registered.
UserLeft Emitted when a user leaves.
ComplianceChecked Emitted when compliance has been checked.
RuleSetUpdated Emitted when the rule set is updated.

These events enable external monitoring and auditing of major activities within the system.

Reference Implementation

UniversalIdentity

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.19;

import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { UniversalCharter } from "./UniversalCharter.sol";

// Interfaces
import { IUniversalIdentity } from "./interface/IUniversalIdentity.sol";
import { IUniversalCharter } from "./interface/IUniversalCharter.sol";

/// @title UniversalIdentity
/// @notice The UniversalIdentity contract is used to manage the identity of robots.

contract UniversalIdentity is IUniversalIdentity, OwnableUpgradeable {
    /// @notice Version identifier for the current implementation of the contract.
    string public constant VERSION = "v0.0.1";

    /// @notice Mapping to store rules that the robot has agreed to follow
    mapping(bytes => bool) private robotRules;

    /// @notice Mapping to store the off-chain compliance status for each rule
    mapping(bytes => bool) private complianceStatus;

    /// @notice Track the charters the robot is subscribed to
    mapping(address => bool) private subscribedCharters;

    /// @notice Custom errors to save gas on reverts
    error RuleNotAgreed(bytes rule);
    error RuleNotCompliant(bytes rule);
    error RuleAlreadyAdded(bytes rule);

    /// @dev Event to emit when compliance is checked
    /// @param updater The address of the compliance updater (owner of the contract)
    /// @param rule The rule that was checked
    event ComplianceChecked(address indexed updater, bytes rule);

    /// @notice Modifier to check if a rule exists
    modifier ruleExists(bytes memory rule) {
        require(robotRules[rule], "Rule does not exist");
        _;
    }

    /// @notice Constructor to set the owner
    constructor() {
        initialize({ _owner: address(0xdEaD) });
    }

    /// @dev Initializer function
    function initialize(address _owner) public initializer {
        __Ownable_init();
        transferOwnership(_owner);
        hardwareIdentity = _hardwareIdentity;
    }

    /// @notice Gets the hardware identity info
    function getHardwareIdentity() external view returns (HardwareIdentity memory) {
        return hardwareIdentity;
    }

    /// @notice Generates a new challenge for hardware verification
    function generateChallenge() external returns (bytes32) {
        bytes32 challenge = keccak256(abi.encodePacked(
            block.timestamp,
            block.prevrandao,
            msg.sender
        ));
        activeChallenge[challenge] = true;
        return challenge;
    }

    /// @notice Verify response to a specific challenge
    function verifyChallenge(
        bytes32 challenge,
        bytes memory signature
    ) external returns (bool) {
        if (!activeChallenge[challenge]) {
            revert InvalidChallenge();
        }

        // Remove challenge after use
        delete activeChallenge[challenge];

        // Verify the signature using ECDSA
        bytes32 messageHash = keccak256(abi.encodePacked(challenge));
        bytes32 ethSignedMessageHash = ECDSA.toEthSignedMessageHash(messageHash);
        address signer = ECDSA.recover(ethSignedMessageHash, signature);
  
        // Convert hardware public key to address for comparison
        address hardwareAddress = address(uint160(uint256(hardwareIdentity.publicKey)));
  
        if (signer != hardwareAddress) {
            revert InvalidSignature();
        }

        return true;
    }

    /// @notice Updates the hardware identity information
    /// @param _hardwareIdentity New hardware identity information
    function updateHardwareIdentity(
        HardwareIdentity memory _hardwareIdentity
    ) external onlyOwner {
        hardwareIdentity = _hardwareIdentity;
    }

    /// @notice Adds a rule to the robot's identity
    /// @param rule The dynamic byte array representing the rule that the robot agrees to follow.
    function addRule(bytes memory rule) external override onlyOwner {
        if (robotRules[rule]) {
            revert RuleAlreadyAdded(rule);
        }

        // Add rule to the mapping
        robotRules[rule] = true;

        emit RuleAdded(rule);
    }

    /// @notice Removes a rule from the robot's identity
    /// @param rule The dynamic byte array representing the rule that the robot no longer agrees to follow.
    function removeRule(bytes memory rule) external override onlyOwner ruleExists(rule) {
        robotRules[rule] = false;
        complianceStatus[rule] = false;

        emit RuleRemoved(rule);
    }

    /// @notice Subscribe and register to a specific UniversalCharter contract using its stored rule set
    /// @param charter The address of the UniversalCharter contract
    /// @param version The version of the rule set to fetch and register for
    function subscribeAndRegisterToCharter(address charter, uint256 version) external {
        require(!subscribedCharters[charter], "Already subscribed to this charter");
        subscribedCharters[charter] = true;

        // Fetch the rule set directly from the UniversalCharter contract using the public getter
        bytes[] memory ruleSet = UniversalCharter(charter).getRuleSet(version);

        // Register as a robot in the charter using the fetched rule set
        UniversalCharter(charter).registerUser(IUniversalCharter.UserType.Robot, ruleSet);

        emit SubscribedToCharter(charter);
    }

    /// @notice Leave the system for a specific UniversalCharter contract
    /// @param charter The address of the UniversalCharter contract to leave
    function leaveCharter(address charter) external {
        require(subscribedCharters[charter], "Not subscribed to this charter");

        // Call the leaveSystem function of the UniversalCharter contract
        UniversalCharter(charter).leaveSystem();

        // Unsubscribe from the charter after leaving
        subscribedCharters[charter] = false;
        emit UnsubscribedFromCharter(charter);
    }

    /// @notice Updates compliance status for a rule (called by the owner)
    /// @param rule The dynamic byte array representing the rule
    /// @param status The compliance status (true if compliant, false if not)
    function updateCompliance(bytes memory rule, bool status) external onlyOwner ruleExists(rule) {
        complianceStatus[rule] = status;

        emit ComplianceChecked(msg.sender, rule);
    }

    /// @notice Checks if the robot has agreed to follow a specific rule and if it is compliant
    /// @param rule The rule to check.
    /// @return bool Returns true if the robot has agreed to the rule and is compliant
    function checkCompliance(bytes memory rule) external view override returns (bool) {
        if (!robotRules[rule]) {
            revert RuleNotAgreed(rule);
        }

        return true;
    }

    /// @notice Gets the compliance status of a rule
    /// @param rule The rule to check.
    function getRule(bytes memory rule) external view returns (bool) {
        return robotRules[rule];
    }

    /// @notice Gets the subscription status of a charter
    /// @param charter The address of the charter to check.
    function getSubscribedCharters(address charter) external view returns (bool) {
        return subscribedCharters[charter];
    }

    /// @notice Gets the compliance status of a rule
    /// @param rule The rule to check.
    function getComplianceStatus(bytes memory rule) external view returns (bool) {
        return complianceStatus[rule];
    }
}

UniversalCharter

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.20;

import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { SystemConfig } from "./SystemConfig.sol";

// Interfaces
import { IUniversalCharter } from "./interface/IUniversalCharter.sol";
import { IUniversalIdentity } from "./interface/IUniversalIdentity.sol";

/// @title UniversalCharter
/// @notice The UniversalCharter contract is used to manage the registration and compliance of users.

contract UniversalCharter is IUniversalCharter, OwnableUpgradeable {
    /// @notice Struct to store information about a registered user
    struct UserInfo {
        bool isRegistered;
        UserType userType;
        uint256 ruleSetVersion; // Rule set version the user is following
    }

    /// @notice Mapping to store registered users
    mapping(address => UserInfo) private users;

    /// @notice Mapping to store rule sets by version number
    mapping(uint256 => bytes[]) private ruleSets;

    /// @notice Mapping to track the rule set hash and its corresponding version
    mapping(bytes32 => uint256) private ruleSetVersions;

    /// @notice Version identifier for the current implementation of the contract.
    string public constant VERSION = "v0.0.1";

    /// @notice Variable to track the current version of the rule set
    uint256 private currentVersion;

    /// @notice Variable to store the address of the SystemConfig contract
    SystemConfig public systemConfig;

    /// @notice Error for when a method cannot be called when paused. This could be renamed
    /// to `Paused` in the future, but it collides with the `Paused` event.
    error CallPaused();

    /// @notice Reverts when paused.
    modifier whenNotPaused() {
        if (paused()) revert CallPaused();
        _;
    }

    /// @notice Constucts the UniversalCharter contract.
    constructor() {
        initialize({ _owner: address(0xdEaD), _systemConfig: address(0xdEaD) });
    }

    /// @dev Initializer function
    function initialize(address _owner, address _systemConfig) public initializer {
        __Ownable_init();
        transferOwnership(_owner);
        systemConfig = SystemConfig(_systemConfig);
    }

    /// @notice Registers a user (either human or robot) by agreeing to a rule set
    /// @param userType The type of user: Human or Robot
    /// @param ruleSet The array of individual rules the user agrees to follow
    function registerUser(UserType userType, bytes[] memory ruleSet) external override whenNotPaused {
        require(!users[msg.sender].isRegistered, "User already registered");

        // Hash the rule set to find the corresponding version
        bytes32 ruleSetHash = keccak256(abi.encode(ruleSet));
        uint256 version = ruleSetVersions[ruleSetHash];
        require(version > 0, "Invalid or unregistered rule set");

        // For robots, ensure compliance with each rule via the UniversalIdentity contract
        if (userType == UserType.Robot) {
            require(_checkRobotCompliance(msg.sender, version), "Robot not compliant with rule set");
        }

        // Register the user with the versioned rule set
        users[msg.sender] = UserInfo({ isRegistered: true, userType: userType, ruleSetVersion: version });

        emit UserRegistered(msg.sender, userType, ruleSet);
    }

    /// @notice Allows a user (human or robot) to leave the system after passing compliance checks
    function leaveSystem() external override whenNotPaused {
        require(users[msg.sender].isRegistered, "User not registered");

        UserInfo memory userInfo = users[msg.sender];

        // For robots, verify compliance with all rules in the rule set
        uint256 version = userInfo.ruleSetVersion;
        if (userInfo.userType == UserType.Robot) {
            require(_checkRobotCompliance(msg.sender, version), "Robot not compliant with rule set");
        }

        users[msg.sender] = UserInfo({ isRegistered: false, userType: UserType.Human, ruleSetVersion: 0 });

        emit UserLeft(msg.sender);
    }

    /// @notice Internal function to verify robot hardware identity
    /// @param robotAddress The address of the robot to verify
    /// @return bool Returns true if hardware verification succeeds
    function _verifyRobotHardware(address robotAddress) internal returns (bool) {
        IUniversalIdentity robot = IUniversalIdentity(robotAddress);
  
        // Get hardware identity to ensure it exists
        robot.getHardwareIdentity();
  
        // Generate a new challenge
        bytes32 challenge = robot.generateChallenge();
  
        // Store the challenge for future reference
        users[robotAddress].lastVerifiedChallenge = challenge;
  
        // Get signature from the robot (this would typically happen off-chain)
        // For this implementation, we'll assume the signature is provided in a separate tx
        // and just verify the challenge exists
        return challenge != 0;
    }

    /// @notice Checks if a user complies with their registered rule set
    /// @param user The address of the user (human or robot)
    /// @param ruleSet The array of individual rules to verify
    /// @return bool Returns true if the user complies with the given rule set
    function checkCompliance(address user, bytes[] memory ruleSet) external view override returns (bool) {
        require(users[user].isRegistered, "User not registered");

        // Hash the provided rule set to find the corresponding version
        bytes32 ruleSetHash = keccak256(abi.encode(ruleSet));
        uint256 version = ruleSetVersions[ruleSetHash];
        require(version > 0, "Invalid or unregistered rule set");
        require(users[user].ruleSetVersion == version, "Rule set version mismatch");

        // For robots, check compliance with each rule in the UniversalIdentity contract
        if (users[user].userType == UserType.Robot) {
            return _checkRobotCompliance(user, version);
        }

        // If the user is human, compliance is assumed for now (can be extended)
        return true;
    }

    /// @notice Internal function to check compliance for robots with their rule set version
    /// @dev This function will revert if the robot is not compliant with any rule. Returns true for view purposes.
    /// @param robotAddress The address of the robot
    /// @param version The version of the rule set to verify compliance with
    /// @return bool Returns true if the robot is compliant with all the rules in the rule set
    function _checkRobotCompliance(address robotAddress, uint256 version) internal view returns (bool) {
        IUniversalIdentity robot = IUniversalIdentity(robotAddress);
        bytes[] memory rules = ruleSets[version];

        for (uint256 i = 0; i < rules.length; i++) {
            if (!robot.checkCompliance(rules[i])) {
                return false;
            }
        }

        return true;
    }

    /// @notice Updates or defines a new rule set version.
    /// @param newRuleSet The array of new individual rules.
    /// @dev This function SHOULD be restricted to authorized users (e.g., contract owner).
    function updateRuleSet(bytes[] memory newRuleSet) external whenNotPaused onlyOwner {
        require(newRuleSet.length > 0, "Cannot update to an empty rule set");

        // Hash the new rule set and ensure it's not already registered
        bytes32 ruleSetHash = keccak256(abi.encode(newRuleSet));
        require(ruleSetVersions[ruleSetHash] == 0, "Rule set already registered");

        // Increment the version and store the new rule set
        currentVersion += 1;
        ruleSets[currentVersion] = newRuleSet;
        ruleSetVersions[ruleSetHash] = currentVersion;

        emit RuleSetUpdated(newRuleSet, msg.sender);
    }

    /// @notice Getter for the latest version of the rule set.
    function getLatestRuleSetVersion() external view returns (uint256) {
        return currentVersion;
    }

    /// @notice Get the rule set for a specific version.
    /// @param version The version of the rule set to retrieve.
    function getRuleSet(uint256 version) external view returns (bytes[] memory) {
        return ruleSets[version];
    }

    /// @notice Get the version number for a specific rule set.
    /// @param ruleSet The hash of the rule set to retrieve the version for.
    function getRuleSetVersion(bytes32 ruleSet) external view returns (uint256) {
        return ruleSetVersions[ruleSet];
    }

    function getUserInfo(address user) external view returns (UserInfo memory) {
        return users[user];
    }

    /// @notice Getter for the current paused status.
    /// @return paused_ Whether or not the contract is paused.
    function paused() public view returns (bool paused_) {
        paused_ = systemConfig.paused();
    }
}

Security

Compliance Updater

The compliance updater is the entity authorized to update a robot's compliance status within the UniversalIdentity contract. In the current implementation, this role is restricted to the owner of the contract.

The updater has significant authority because it can change whether a robot is recorded as complying with rules. Abuse of this authority could cause the following problems.

  • A dishonest update could falsely mark a robot that violates a rule as compliant.
  • Deliberate manipulation of compliance information could cause other systems to make incorrect decisions.

Managing the owner role is therefore critically important. For security, the owner should use a secure hardware wallet. A future design could also introduce a multisignature approval process to avoid relying on a single owner.

Rule Management

Functions involved in rule management include addRule, removeRule, updateCompliance (in UniversalIdentity), and updateRuleSet (in UniversalCharter). These functions determine which rules are active in the system, so misuse or malicious operations can undermine the reliability of the entire system.

Allowing unrestricted rule changes introduces the following risks.

Risk Description
Unauthorized rule additions Unauthorized users deliberately add harmful rules that restrict the behavior of robots or humans.
Loopholes through rule removal Particular users or robots improperly remove rules to exempt themselves.
Compliance tampering Unauthorized calls to updateCompliance conceal rule violations.

Access control must therefore be designed strictly so that only authorized users can call these functions. For example, the onlyOwner modifier and role-based access control, such as AccessControl, can be combined for secure operation.

Upgradeable Contracts

Using upgradeable contracts such as OwnableUpgradeable introduces additional risks during initialization and upgrades. One particular concern is the re-execution of initialize (a reinitialization attack).

In an upgradeable contract, initialize performs initial setup instead of a conventional constructor. If it remains callable repeatedly, an attacker could set themselves as the owner or reinitialize the contract to take control.

The following measures are important for preventing this vulnerability.

Measure Description
Prevent reinitialization Use the initializer modifier to ensure that initialization can only run once.
Verify ownership Confirm that owner is set correctly after initialization.
Audit upgrade procedures When deploying a new contract version, check for unintended reinitialization or gaps in access control.

Without these basic protections, an attacker could seize all privileges and completely compromise the system.

Gas Consumption

An excessively large rule set may sharply increase the gas (fees) required to process transactions on Ethereum. On a blockchain, larger amounts of data or computation result in higher gas costs. This can cause the following problems.

  • Registration and update operations become very expensive.
  • Adding or removing rules fails.
  • In extreme cases, denial-of-service (DoS) attacks become possible.

To prevent this, limits should be placed on the number of rules and the size of their contents. For example, a rule set could be limited to 100 rules, or a maximum length could be imposed on rule strings. Storing hashes of rules instead can also reduce the amount of data and lower gas costs.

Citation

OpenMind, Jan Liphardt jan@openmind.org, Shaohong Zhong (@ShaohongZ), Boyuan Chen (@bchen-dev), Paige Xu paige@openmind.org, James Ball james.ball@nethermind.io, Thamer Dridi thamer.dridi@nethermind.io, "ERC-7777: Governance for Human Robot Societies [DRAFT]," Ethereum Improvement Proposals, no. 7777, September 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7777.

Conclusion

This article covered ERC7777, which proposes a mechanism for humans and robots to establish identities on a blockchain on equal terms and cooperate under shared rules. I hope you found it useful.

If you have questions, feel free to contact me by direct message on Twitter.

Twitter @cardene777

I also share information on other platforms, so feel free to explore them.

https://chaldene.net/