Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

FM-111: Hashed chain ID and --chain-name #115

Merged
merged 10 commits into from
May 24, 2023
Merged

FM-111: Hashed chain ID and --chain-name #115

merged 10 commits into from
May 24, 2023

Conversation

aakoshh
Copy link
Contributor

@aakoshh aakoshh commented May 24, 2023

Closes consensus-shipyard/ipc#339

The PR is an opinionated (quick and dirty if you like) implementation of a domain separation of chains by hashing the chain ID together with the message CID, so the signature cannot be validated on a different chain, preventing replay attacks.

It doesn't implement delegated signatures. My goal was just to thread the necessary settings through the CLI, RPC, interpreters, genesis, etc.

The way it works is:

  1. The chain_name is configured in the genesis file.
  2. It's turned into a chain_id during init_chain and becomes part of the state (it might change during the life of the chain if there is a fork or state migration).
  3. The signed message interpreter gets the chain_id from the state and uses it to validate signatures.
  4. The CLI commands get a --chain-name argument which is turned into a chain_id and used to produce signatures.

How the chain_name is turned into a chain_id is full of ad-hoc decisions:

  • First we look up if the name is one of the well known Filecoin networks.
  • If not, we hash the name with Blake2b256 (same hashing algorithm as used by the CID) and treat the bytes as a positive BigInt, then we take the modulo of the highest chain ID Javascript tools can handle (the chain ID must work with EVM tools).
  • If the ID happens to clash with a known network ID, an error is returned.
  • For signing, we use the Big-endian byte encoding of the u64 that is the chain ID, append it to the CID, then use this as the input for signing.

@aakoshh aakoshh requested a review from adlrocha May 24, 2023 09:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a chain ID to the signature of FVM messages
1 participant