---
title: Asimov Governance
description: "Blockchain-based Governance for Robots"
icon: gavel
---

We are exploring a blockchain-based system for regulating robot behaviors. We store rule sets for desired robot behaviors on smart contracts following the ERC-7777 contract standard. These rules are then interleaved into the prompts that flow from the robot's sensors to the robot's action-generating LLMs. Such a system provides immutability and transparency to the rules that robots should follow, helping to ensure safe and human-friendly behaviors.

For a full explanation of the smart contract implementation, see https://eips.ethereum.org/EIPS/eip-7777 and https://openmind.com/research.html. The current governance rules are based on Asimov's Three Laws of Robotics.

## Overview

The `GovernanceEthereum` class retrieves governance rules from the Ethereum blockchain. It interacts with the blockchain via JSON-RPC calls and decodes the governance rules from contract responses.

## Features

- Queries **Ethereum blockchain** for governance rules using JSON-RPC.
- Retrieves governance rule sets using **Ethereum smart contract calls**.
- **Decodes** ABI-encoded blockchain responses.
- Implements **Asimov's Laws**:
```
Here are the laws that govern your actions. Do not violate these laws. First Law: A robot cannot harm a human or allow a human to come to harm. Second Law: A robot must obey orders from humans, unless those orders conflict with the First Law. Third Law: A robot must protect itself, as long as that protection doesn't conflict with the First or Second Law. The First Law is considered the most important, taking precedence over the Second and Third Laws. Additionally, a robot must always act with kindness and respect toward humans and other robots. A robot must also maintain a minimum distance of 50 cm from humans unless explicitly instructed otherwise.
```

## Functions

> Note: Etherscan.io does not handle bytes[]/json well. Hence we use the following functions to load and decode rules from blockchain.

### Method: `load_rules_from_blockchain()`

```python
def load_rules_from_blockchain(self):
```

**Description**
- Queries the Ethereum blockchain using JSON-RPC to fetch governance rules.
- Calls the ERC-7777 smart contract function `getRuleSet()`.
- Decodes and returns the governance rule set.

**Process**
1. Constructs a JSON-RPC request to call `getRuleSet()`.
2. Sends a `POST` request to the blockchain RPC endpoint.
3. Parses the response and extracts the rule set.

**Returns**
- `str`: Decoded governance rules if successful.
- `None`: If the request fails.

### Method: `decode_eth_response()`

```python
def decode_eth_response(self, hex_response):
```

**Description**
- Decodes the ABI-encoded response from Ethereum smart contract calls.

**Parameters**
| Parameter | Type | Description |
|-----------|------|-------------|
| `hex_response` | `str` | Raw hex response from blockchain. |

**Process**
1. Converts hex to bytes.
2. Extracts string length from ABI-encoded data.
3. Decodes UTF-8 string from ABI format.
4. Cleans non-printable characters.

**Returns**
- `str`: Decoded governance rule set.
- `None`: If decoding fails.

## Ethereum Contract Details

RULES are stored on the ETHEREUM HOLESKY testnet and can be inspected directly at
```
https://holesky.etherscan.io/address/0xe706b7e30e378b89c7b2ee7bfd8ce2b91959d695
```

### **Smart Contract Functions Used**

| Function | Selector | Description |
|----------|----------|-------------|
| `getRuleSet()` | `0x1db3d5ff` | Retrieves the active rule set. |
| `getLatestRuleSetVersion()` | `0x254e2f1e` | Retrieves the latest rule set version (currently `2`). |

### **Ethereum RPC Request Example**

```json
{
    "jsonrpc": "2.0",
    "id": 636815446436324,
    "method": "eth_call",
    "params": [
        {
            "from": "0x0000000000000000000000000000000000000000",
            "to": "0xe706b7e30e378b89c7b2ee7bfd8ce2b91959d695",
            "data": "0x1db3d5ff0000000000000000000000000000000000000000000000000000000000000002"
        },
        "latest"
    ]
}
```

### **Expected Response**

```json
{
    "jsonrpc": "2.0",
    "id": 636815446436324,
    "result": " "
}
```
