Skip to content

Conversation

ensi321
Copy link
Contributor

@ensi321 ensi321 commented Sep 9, 2025

How to run

zig build run:download_spec_tests && zig run:write_spec_tests && zig test:spec_tests

Sample result

image

Part of #21

}

if (comptime isFixedType(ST)) {
try ST.deserializeFromBytes(serialized, value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
try ST.deserializeFromBytes(serialized, value);
try ST.deserializeFromBytes(serialized, &@field(out, fld.name));

hence no need to declare value here
we can simplify "*Out" not to contain pointers, for example

pub const Phase0OperationsOut = struct {
    pre: ?ssz.phase0.BeaconState.Type = null,
    post: ?ssz.phase0.BeaconState.Type = null,
    attestation: ?ssz.phase0.Attestation.Type = null,
    attester_slashing: ?ssz.phase0.AttesterSlashing.Type = null,
    block: ?ssz.phase0.BeaconBlock.Type = null,
    deposit: ?ssz.phase0.Deposit.Type = null,
    proposer_slashing: ?ssz.phase0.ProposerSlashing.Type = null,
    voluntary_exit: ?ssz.phase0.SignedVoluntaryExit.Type = null,
};

and we don't need an inline for to deinit fields at consumer side https://github.com/ChainSafe/state-transition-z/pull/46/files#diff-1d6f5b6eb82151a80442a6c728e68021970e2170f6ab4bb3574ac4f44b10886fR27

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@twoeths The thing is each field has default value of null. So &@field(out, fld.name) is a pointer to a nullable, which ST.deserializeFromBytes doesn't accept.

We need to pass a ST.Type pointer to ST.deserializeFromBytes by creating one, and then assign the field to it.

Copy link
Collaborator

@twoeths twoeths left a comment

Choose a reason for hiding this comment

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

general approach looks good to me, left some suggestions to deduplicate schemas and simplify things a bit, let me know if it does not work

@ensi321 ensi321 changed the base branch from te/naive_state_transition to main October 7, 2025 09:10
@ensi321 ensi321 changed the title [wip] feat: add minimal framework for spec test feat: add minimal framework for spec test Oct 8, 2025
@ensi321 ensi321 marked this pull request as ready for review October 8, 2025 10:34
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

Successfully merging this pull request may close these issues.

4 participants