Skip to content

hashTreeRoot for slice field #23

@fearlessfe

Description

@fearlessfe

In ssz spec, the list type must have a limit to calculate the merkle tree root. So we define a method to get the limit of the slice.

eg IndexedAttestation, the field attesting_indices is a slice, so it must have a method ${fieldName}_limit

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,

    // limit for slice type from spec, the method name must be field name + "_limit"
    pub fn attesting_indices_limit() u64 {
        return preset.ActivePreset.get().MAX_VALIDATORS_PER_COMMITTEE;
    }
};

There is a side efffect, Because call the method through reflection is comptime, so we have to add method for all Slice type field, even it's not a ssz type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions