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

In light-client, use ethereum_ssz instead of ssz-rs #1417

Open
carver opened this issue Sep 4, 2024 · 11 comments · May be fixed by #1588
Open

In light-client, use ethereum_ssz instead of ssz-rs #1417

carver opened this issue Sep 4, 2024 · 11 comments · May be fixed by #1588
Assignees
Labels
flamingo Maintenance or downtime for the person on Flamingo rotation to tackle good-first-issue Good for newcomers

Comments

@carver
Copy link
Collaborator

carver commented Sep 4, 2024

ethereum_ssz is used for SSZ handling in most places, but light-client uses ssz-rs. Investigate replacing ssz-rs, so we can remove a dependency.

@carver carver added the good-first-issue Good for newcomers label Sep 4, 2024
@morph-dev morph-dev added the flamingo Maintenance or downtime for the person on Flamingo rotation to tackle label Sep 5, 2024
@virajbhartiya
Copy link

Can I work on this?

@KolbyML
Copy link
Member

KolbyML commented Nov 19, 2024

@virajbhartiya yes you can work on it 🚀

@virajbhartiya
Copy link

@KolbyML @carver While looking at the implementation of ethereum_ssz, I couldn't find Vector, Node, etc in it. I also went through its usage in trin-beacon and trin-history. If I am missing something can you please help me out with this?

@KolbyML
Copy link
Member

KolbyML commented Nov 20, 2024

@KolbyML @carver While looking at the implementation of ethereum_ssz, I couldn't find Vector, Node, etc in it. I also went through its usage in trin-beacon and trin-history. If I am missing something can you please help me out with this?

Could you give me an example of code you are trying to update but having problems with? Or link to the lines of code which use Vector`, `Node you are referring to?

@virajbhartiya
Copy link

Eg:

) -> Result<Node> {
let genesis_root = genesis_root.to_vec().try_into()?;
let domain_type = &hex::decode("07000000")?[..];
let fork_version = Vector::from_iter(fork_version.to_vec());

also
use ssz_rs::Vector;
pub type Bytes32 = Vector<u8, 32>;

If I try removing ssz-rs, I was unable to find a replacement for these in ethereum_ssz, if it is okay to replace it with [u8] I can try to update the usages

@KolbyML
Copy link
Member

KolbyML commented Nov 20, 2024

Eg:

) -> Result<Node> {
let genesis_root = genesis_root.to_vec().try_into()?;
let domain_type = &hex::decode("07000000")?[..];
let fork_version = Vector::from_iter(fork_version.to_vec());

also

use ssz_rs::Vector;
pub type Bytes32 = Vector<u8, 32>;

If I try removing ssz-rs, I was unable to find a replacement for these in ethereum_ssz, if it is okay to replace it with [u8] I can try to update the usages

So for vector you should be able to use FixedVector from this library https://docs.rs/ssz_types/latest/ssz_types/ to read more on SSZ types you can find info here https://github.com/ethereum/consensus-specs/blob/dev/ssz/simple-serialize.md

Example usage can be found in our ethportal-api crate which uses ethereum_ssz and ssz_types

You didn't give an example for Node, but the process should be fairly similar feel free to ask more questions if you are still confused.

@virajbhartiya
Copy link

Thanks for helping out with Vector, I'll make the change,

Example for the usage of Node

pub fn compute_signing_root(object_root: Bytes32, domain: Bytes32) -> Result<Node> {

@virajbhartiya
Copy link

Another issue is with

let is_valid = is_valid_merkle_branch(&leaf_hash, branch.iter(), depth, index, &state_root);

@KolbyML
Copy link
Member

KolbyML commented Nov 21, 2024

Thanks for helping out with Vector, I'll make the change,

Example for the usage of Node

pub fn compute_signing_root(object_root: Bytes32, domain: Bytes32) -> Result<Node> {

In ethereum_ssz the type Node would be B256

@virajbhartiya
Copy link

@KolbyML I have raised a PR for this, I was unable to find a fix for is_valid_merkle_branch and hash_tree_root. If you could help me out with that it'll be great, thanks!

@KolbyML
Copy link
Member

KolbyML commented Nov 23, 2024

@KolbyML I have raised a PR for this, I was unable to find a fix for is_valid_merkle_branch and hash_tree_root. If you could help me out with that it'll be great, thanks!

You should be able to use this crate as a replacement https://docs.rs/tree_hash/latest/tree_hash/ we use it in ethportal-api so you can probably find an example. The rust derive's name is Hash I believe, it is used for the consensus types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flamingo Maintenance or downtime for the person on Flamingo rotation to tackle good-first-issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants