Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create MEP-3355.md #24

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ If your MEP requires images, the image files should be included in a subdirector
| [MEP-1759](proposals/mep-1759.md) | MXC DApp Store Metadata Standard | Standards | Living|
| [MEP-600](proposals/mep-600.md) | NFT NFC Contract | Standards | Draft |
| [MEP-2542](proposals/mep-2542.md) | Multi-Token Mining for MEP-1004 Radio Miners | Standards | Living |
| [MEP-3355](proposals/mep-3355.md) | LLM Friendly Transaction Memo Format | Standards | Draft |
126 changes: 126 additions & 0 deletions proposals/MEP-3355.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

<pre>
MEP: 3355
Title: MEP-3355 LLM Friendly Transaction Memo Format
Status: Draft
Type: Standards
Created: 2023-06-20
</pre>

# MEP-3355: LLM Friendly Transaction Memo Format

## Abstract

MEP-3355 proposes a standard format for transaction memos on Moonchain that is optimized for processing by large language models (LLMs). The standard leverages the Brotli compression algorithm to efficiently compress memo data before sending it to Moonchain. This allows for more expressive and detailed memos while minimizing transaction costs. The standard memo format enables powerful LLM-based applications built on Moonchain transaction data.

## Motivation

As LLMs become increasingly powerful tools for processing and analyzing on-chain data, there is an opportunity to structure transaction memo data in a way that facilitates LLM understanding. By defining a standard LLM-friendly memo format and leveraging compression, Moonchain aims to unlock a new generation of LLM-powered blockchain analytics, data extraction, and smart contract capabilities.

The key benefits of an LLM-friendly memo format include:

- Enabling efficient and streamlined ingestion of Moonchain transaction data by LLMs
- Facilitating better LLM understanding of transaction context and intent
- Allowing for more expressive memos with minimized transaction cost through compression
- Providing a foundation for building advanced LLM-based Moonchain applications

## Specification

MEP-3355 proposes the following standard format for LLM friendly transaction memos on Moonchain:

```json
{
"format": "MEP-3355",
"version": "1.0.0",
"metadata": {
"data_source": "Compressed data source information",
"data_collection_method": "Compressed data collection method",
"preprocessing": "Compressed preprocessing details"
},
"data": [
{
"type": "sensor",
"content": "Compressed sensor data in jsonl goes here",
"compression": "brotli"
},
{
"type": "lpwan",
"content": ["compressed", "tag", "list"]
}
]
}
```

The memo data is represented as a JSON object with the following fields:

- `format` (required): Specifies the MEP-3355 format to allow for future extension
- `version` (required): The version of the MEP-3355 spec used
- `metadata` (optional): An object containing additional information about the data
- `data_source` (optional): Compressed information about the source of the data
- `data_collection_method` (optional): Compressed details on how the data was collected
- `preprocessing` (optional): Compressed information about any preprocessing performed on the data
- `data` (required): An array of data objects included in the memo
- `type` (required): The type of data (initially `"sensor"` or `"lpwan"`)
- `content` (required): The compressed data content
- `compression` (optional): The compression algorithm used (defaults to `"brotli"`)

Before being added to the memo, text content should be compressed using the Brotli algorithm. This allows for longer and more expressive memos while keeping transaction size and cost manageable.

Tag data can be used to concisely annotate key concepts, entities and topics to aid LLM understanding. The tag list should also be compressed.

Here's an example of how the memo data could be structured in JSONL format:

```jsonl
{"timestamp": "2024-06-19T22:00:00Z", "heartbeat": 72, "sleep_status": "awake"}
{"timestamp": "2024-06-19T22:15:00Z", "heartbeat": 70, "sleep_status": "asleep"}
{"timestamp": "2024-06-19T22:30:00Z", "heartbeat": 68, "sleep_status": "asleep"}
{"timestamp": "2024-06-19T22:45:00Z", "heartbeat": 67, "sleep_status": "asleep"}
{"timestamp": "2024-06-20T07:00:00Z", "heartbeat": 75, "sleep_status": "awake"}
```

Each line in the JSONL data represents a separate data point, with the relevant information structured as key-value pairs. This format allows for easy parsing and processing by LLMs.

## Rationale

The proposed memo format is designed to optimize for LLM ingestion and understanding while working within the constraints of blockchain transactions. Key design choices include:

- Using JSON for its widespread support and extensibility
- Including metadata to provide additional context about the data source, collection methods, and preprocessing
- Separately typing text and tag data to allow focused LLM processing
- Compressing data to pack more information into memos at lower transaction cost
- Specifying the compression algorithm for consistent decoding

Brotli compression was selected because it achieves high compression ratios on text data while remaining relatively fast. This makes it well-suited for compressing memos in the context of blockchain transactions.

## Backwards Compatibility

Adopting the MEP-3355 format for Moonchain transaction memos would require a coordinated upgrade of Moonchain nodes, wallets and other key infrastructure to support the new format. Transactions using the legacy memo format could continue to be supported for a transition period as determined by the community.

## Test Cases

Test cases should be developed to verify the correctness of MEP-3355 memo encoding and decoding across different Moonchain implementations. Key aspects to test include:

- JSON validity and schema conformance of generated memos
- Correct Brotli compression and decompression of memo data
- Graceful handling of invalid or malformed MEP-3355 memos
- Performance impact of memo compression and decompression

## Implementation

Implementing MEP-3355 would involve:

1. Adding support for MEP-3355 memo formatting and compression in Moonchain nodes
2. Updating Moonchain wallets to provide user-friendly MEP-3355 memo creation
3. Building Moonchain blockchain explorers and analytics tools that parse MEP-3355 memos
4. Developing and releasing LLM-based applications that leverage MEP-3355 formatted data

A phased rollout is recommended, starting with infrastructure upgrades and ending with LLM application development.

## References

- Brotli Compressed Data Format (RFC 7932)
https://www.rfc-editor.org/rfc/rfc7932
- MIME Type Registrations for CBOR (RFC 9177)
https://www.rfc-editor.org/rfc/rfc9177
- Moonchain
https://www.moonchain.com/
Loading