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

some tricks in ssz #3

Open
fearlessfe opened this issue Dec 11, 2024 · 3 comments
Open

some tricks in ssz #3

fearlessfe opened this issue Dec 11, 2024 · 3 comments

Comments

@fearlessfe
Copy link

The current way of ssz has some flaws

  1. the array length is different in different preset(mainnet_preset and minimal_preset), this mainly affects encode and decode
    like HistoricalBatch, in fact the block_roots and state_roots are both array type, not Slice, but in different preset, the length is different
// 8192 in mainnet_preset and 64 in minimal_preset
pub const HistoricalBatch = struct {
    block_roots: []primitives.Root,
    state_roots: []primitives.Root,
};

maybe we can use union to solve the problem, like types in different forks

pub const BeaconBlockBody = union(primitives.ForkType) {
    phase0: phase0.BeaconBlockBody,
    altair: altair.BeaconBlockBody,
    bellatrix: bellatrix.BeaconBlockBody,
    capella: capella.BeaconBlockBody,
    deneb: deneb.BeaconBlockBody,
    electra: deneb.BeaconBlockBody,
};
  1. when caculate the hashRootTree of a Slice type, we must know the limit of the slice, like attesting_indices field in
    IndexedAttestation type
pub const IndexedAttestation = struct {
    // # [Modified in Electra:EIP7549] size: MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT
    attesting_indices: []primitives.ValidatorIndex,
    data: AttestationData,
    signature: primitives.BLSSignature,
};

we can add a attrs to present the limit for Slice, the field in attrs represent the limit of corresponding properties

pub const IndexedAttestation = struct {
    // # [Modified in Electra:EIP7549] size: MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT
    attesting_indices: []primitives.ValidatorIndex,
    ...
    pub const attrs = struct{
         .attesting_indices = limit
   }
};

or we can consider using codegen, so some other information can be present in comments, just like tag in golang

pub const IndexedAttestation = struct {
    attesting_indices: []primitives.ValidatorIndex, // add additional information here
    data: AttestationData,
    signature: primitives.BLSSignature,
};
@GrapeBaBa
Copy link
Member

Our goal is that building a high performance ssz lib such as https://www.youtube.com/watch?v=WIu4PGDZOqI

@GrapeBaBa
Copy link
Member

https://github.com/ghiliweld/sszb the lib

@GrapeBaBa
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants