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

CHIP-0029: Signer Protocol Serialization #104

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions CHIPs/chip-0029.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
CHIP Number | 0029
:-------------|:----
Title | Signer Protocol Serialization
Description | A JSON-CLVM-binary serialization technique for the wallet signer protocol
Author | [Matt Hauff](https://github.com/Quexington)
Editor | [Dan Perry](https://github.com/danieljperry)
Comments-URI | [CHIPs repo, PR #104](https://github.com/Chia-Network/chips/pull/104)
Status | Review
Category | Process
Sub-Category | Tooling
Created | 2024-03-14
Requires | [0027](https://github.com/Chia-Network/chips/pull/102)
Replaces | None
Superseded-By | None


## Abstract

This CHIP provides a standard method for serializing the APIs presented in `CHIP-0027` from JSON to binary.

## Motivation

The APIs from `CHIP-0027` are listed in JSON, but the wallet signer protocol only recognizes binary large objects (BLOBs). Therefore, this CHIP is needed as a standard method for serializing the APIS from JSON into bytes.

## Backwards Compatibility

This CHIP does not introduce any backwards incompatibilities.

## Rationale

This CHIP creates a standard method of converting JSON to CLVM, and later to binary. The reason to implement serialization in this way is to minimize the number of required dependencies. By definition, every type of signer (with the exception of blind signers) must examine the spends it is signing. Therefore, CLVM is required. With the design of this CHIP, JSON libraries become extra dependencies. Effectively, this design keeps the potential attack surface as small as possible.

## Specification

Prior to serialization, the JSON will be converted to CLVM according to the following rules:
1. Each dictionary (which the top layer of JSON must be) will be converted to a nil-terminated CLVM list of key/value pairs, where:
* The keys must be strings
* The values will be serialized recursively
2. Each list will be converted to a nil-terminated CLVM list. The elements of the list will be serialized recursively.
3. Anything that is neither a dictionary, nor a list, must be a string. The string will be interpreted using conventional CLVM syntax (`0x` for bytes, an additional pair of quote marks for strings, etc).

At this point, the JSON will have been converted into a CLVM tree. That tree will then be serialized in the consensus format specified in the [Chialisp documentation](https://chialisp.com/clvm#serialization).

## Reference Implementation

This CHIP is implemented in the following locations:
* [clvm_streamable.py](https://github.com/Chia-Network/chia-blockchain/blob/385916a6a29c5124155b43cb7cfe48c6ec7b3590/chia/wallet/util/clvm_streamable.py).
* [hsms](https://github.com/Chia-Network/hsms/blob/8cd5a44ad83c1d7f525a13c8ceb734f2ead89e6e/hsms/clvm_serde/__init__.py)

## Security

Chia Network, Inc. has conducted an internal review of the code involved with this CHIP.

## Additional Assets

None

## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).