Skip to content

Use plain strings as chain IDs#432

Closed
SuperFluffy wants to merge 8 commits into
mainfrom
superfluffy/chain-id-string
Closed

Use plain strings as chain IDs#432
SuperFluffy wants to merge 8 commits into
mainfrom
superfluffy/chain-id-string

Conversation

@SuperFluffy

@SuperFluffy SuperFluffy commented Sep 26, 2023

Copy link
Copy Markdown
Contributor

Summary

Removed ChainId type in favor of a plain old String. Strings are hashed before constructing commitments.

Background

#395 introduces plain strings as chain IDs in its protobuf definitions. This patch is a step to make the refactor easier.

Open question

  1. The SequenceAction protobuf message still takes bytes as the chain ID. It should also be changed to take a String
  2. Sending data to the sequencer costs tokens, but the chain ID is currently not priced in. Should it be added?
  3. Pricing in the chain ID encourages shorter names, but potentially also namesquatting. Should we instead commit the sha256 hash of the chain ID?

Changes

  • Replace the ChainId type by a plain String
  • Hash the String using sha256 before constructing merkle trees and roots as commitments

Testing

All present tests should still pass after this change.

Breaking Changelist

  • This is a breaking change because chain IDs are no longer plain bytes but utf8 strings
  • The action tree and chain ID commitments change because chain IDs are hashed before constructing trees.

Related Issues

This is a follow-up to #346

Closes #433

@github-actions github-actions Bot added conductor pertaining to the astria-conductor crate sequencer-relayer pertaining to the astria-sequencer-relayer crate labels Sep 26, 2023
@SuperFluffy SuperFluffy changed the title Superfluffy/chain id string Use plain strings as chain IDs Sep 26, 2023
@github-actions github-actions Bot added the sequencer pertaining to the astria-sequencer crate label Sep 26, 2023
let rollup_data_tree = MerkleTree::from_leaves(self.rollup_txs.clone());
let rollup_data_root = rollup_data_tree.root();
let mut leaf = self.chain_id.as_ref().to_vec();
let mut leaf = utils::sha256_hash(self.chain_id.as_bytes()).to_vec();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this PR change the format of the sequence::Action merkle tree? can you update the doc in specs/sequencer-inclusion-proofs.md accordingly?

data.push(action.data.clone());
})
.or_insert_with(|| vec![action.data.clone()]);
// FIXME(https://): change sequence actions to carry string chain IDs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add issue number?

})
.or_insert_with(|| vec![action.data.clone()]);
// FIXME(https://): change sequence actions to carry string chain IDs
let chain_id = String::from_utf8_lossy(&action.chain_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it better to us from_utf8_lossy over from_utf8?

@SuperFluffy SuperFluffy Sep 27, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we don't know what's inside action.chain_id. Right now we define it as bytes (in the protobuf definition), so it could be bytes that are not utf8. I guess we could return an error instead.

@noot noot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine, please update specs/sequencer-inclusion-proofs.md before merging!

@SuperFluffy

Copy link
Copy Markdown
Contributor Author

@noot I have pushed a small modification where the sha256(chain_id) is submitted to the DA rather than the chain_id string itself. The commit is reversible.

@SuperFluffy SuperFluffy force-pushed the superfluffy/chain-id-string branch from 4b980b4 to 3dd1c45 Compare September 27, 2023 14:06
@github-actions github-actions Bot added proto pertaining to the Astria Protobuf spec composer pertaining to composer labels Sep 27, 2023

@sambukowski sambukowski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just need to fix build tests

@SuperFluffy

Copy link
Copy Markdown
Contributor Author

Closing this in favor of #436

@SuperFluffy SuperFluffy deleted the superfluffy/chain-id-string branch November 23, 2023 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

composer pertaining to composer conductor pertaining to the astria-conductor crate proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate sequencer-relayer pertaining to the astria-sequencer-relayer crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change Chain IDs to be String

3 participants